• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar

Aspiration Classes

  • Join Now
  • contact@aspirationclassess.com
  • +91 9831 913 909
  • Home
  • About Us
  • Subjects Taught
  • Resources
    • ICSE
      • ICSE Computer Applications
      • ICSE Chemistry
      • ICSE Biology
      • ICSE Chemistry
      • ICSE Commerce
      • ICSE Maths
      • ICSE Physics
    • ISC
      • ISC Computer
      • ISC Physics
      • ISC Chemistry
      • ISC Maths
      • ISC Accounts
      • ISC Biology
  • Notice
  • Contact Us

Blog

Home / ISC / ISC Computer / ISC Practical Program – ISC 2004
  • ISC Computer

ISC Practical Program – ISC 2004

By Faseel Anwar - 05/02/2018

Number have different representations depending on the bases on which they are expressed. For example in base 3, the number 12 is written as 110 , but in base 8 it is written as

Consider, for example, the integers 12 and 5. Certainly these ar not equal if base 10 is used for each, but suppose 12 was a base 3 number and 5 was a base 6 number then what happens.

12 base 3 = 1 x 31 + 2 x 30, or 5 was base 10(5 in any base is equal to 5 base 10).

So 12 and 5 can be equal if you select the right bases for each of them/

Write a program to input two integers, X and Y and calculated the smallest base for X and smallest base for Y (likely different from X) so that X and Y represent the same value. The base associated with X and Y will be between 1 and 20 (both inclusive), in representing these numbers the digits 0 to 9 have their usual decimal interpretations. The uppercase alphabetic characters A through J represent digits 10 through 19 respectively.

Test your program for the following data and some random data:

INPUT :
X = 12, Y = 5
OUTPUT:
12(base 3) = 5(base 6)
INPUT :
X = 10, Y = A
OUTPUT:
10(base 10) = A(base 11)
INPUT :
X = 123, Y = 456
OUTPUT:
123 is not equal to 456 in any base between 2 to 20
INPUT :
X = 42, Y = 36
OUTPUT:
42(base 7) = 36(base 8)

Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.*;
public class Base_Equality
{
    String dg = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int base2dec(String n, int b)
    {
        int i, l = n.length(), d=0, x, c=0;
        for(i = l-1; i>=0; i--)
        {                   //Converting the number to decimal from base b
            x = dg.indexOf(n.charAt(i));
            if(b<=x)        //If any digit is greater than or equal to the base then the number cannot be from that base
                return -1;
            d = d + x*(int)Math.pow(b, c);
            c++;
        }
        return d;
    }
 
    void check(String a, String b)
    {
        int i, j, m, n;
        for(i=2;i<=20;i++)
        {
            m = base2dec(a, i);
            if(m==-1)       //Skipping the loop
            continue;
            for(j=2;j<=20;j++)
            {
                n = base2dec(b, j);
                if(n==-1)   //Skipping the loop
                continue;
                if(m == n)
                {
                    System.out.println(a+" in base "+i+" and "+b+" in base "+j+" are equal");
                    System.exit(0);
                }
            }
        }
        System.out.println(a+" is not equal to "+b+" in any base between 2 to 20");
    }
    
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        String a, b;
        Base_Equality ob = new Base_Equality();
        System.out.println("Enter 2 numbers: ");
        a = sc.nextLine();      //Taking input
        b = sc.nextLine();
        ob.check(a, b);      //Calling the function
    }
}

Output 1

Output 2

Related Posts

  • Sample ISC Practical Question SolvedWrite a program to input 2 numbers in Binary and add them.
  • ISC 2018 – Computer Practical Question 1 SolutionISC 2018 – Computer Practical Question 1 Solution
  • Sample ISC Practical Question SolvedKaprekar Number – ISC Practical 2010 – Question 2

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Google+ (Opens in new window)

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Find us on facebook

Facebook By Weblizar Powered By Weblizar

Search the website

Recent Posts

  • Study for IIT – JEE Mains and Advanced from an all IITian faculty
  • ICSE Maths Mock Test Paper – 2
  • ICSE Maths Mock Test Paper – 3
  • Write a program to implement an array based Dequeue
  • Write a program to implement an array based queue

Recent Comments

  • prostate vibrator on ISC 2018 – Computer Practical Question 1 Solution

Categories

  • Engineering (3)
  • ICSE (114)
  • ICSE Biology (2)
  • ICSE Chemistry (7)
  • ICSE Commerce (4)
  • ICSE Computer Applications (108)
  • ICSE Economics (2)
  • ICSE English (2)
  • ICSE Maths (8)
  • ICSE Physics (7)
  • ISC (84)
  • ISC Accounts (3)
  • ISC Biology (2)
  • ISC Chemistry (7)
  • ISC Commerce (1)
  • ISC Computer (71)
  • ISC Economics (1)
  • ISC English (1)
  • ISC Maths (6)
  • ISC Physics (12)
  • Notices (10)
  • Others (16)
  • Uncategorized (1)

ISC POPULAR POSTS

Write a program to implement an array based Dequeue

February 22, 2018

Write a program to implement an array based queue

February 22, 2018

Write a program to implement an array based STACK

February 22, 2018

ICSE POPULAR POSTS

ICSE Maths Mock Test Paper – 2

February 25, 2018

ICSE Maths Mock Test Paper – 3

February 25, 2018

ICSE Commercial Application Mock Question paper – 1

February 19, 2018

OTHER POPULAR POSTS

Write a program to implement an array based Dequeue

February 22, 2018

Write a program to implement an array based queue

February 22, 2018

Write a program to implement an array based STACK

February 22, 2018
ABOUT US
Aspiration Classes is a venture of like minded people from various backgrounds who seek to provide high quality assistance to school and college going students.
Contact us: contact@aspirationclasses.com
FOLLOW US
  • Disclaimer
  • Privacy Policy
  • Advertisement
  • Contact Us

© Copyright 2017 - Designed & Developed by Trian Technologies