1. Question:How to convert large binary number to hexadecimal 

    Answer
    #include<stdio.h>
    #define MAX 1000
    
    int main(){
    
       char binaryNumber[MAX],hexaDecimal[MAX];
       int temp;
       long int i=0,j=0;
      
       printf("Enter any number any binary number: ");
       scanf("%s",binaryNumber);
    
       while(binaryNumber[i]){
          binaryNumber[i] = binaryNumber[i] -48;
          ++i;
       }
    
       --i;
       while(i-2>=0){
           temp =  binaryNumber[i-3] *8 + binaryNumber[i-2] *4 +  binaryNumber[i-1] *2 + binaryNumber[i] ;
           if(temp > 9)
                hexaDecimal[j++] = temp + 55;
           else
                hexaDecimal[j++] = temp + 48;
           i=i-4;
       }
    
       if(i ==1)
          hexaDecimal[j] = binaryNumber[i-1] *2 + binaryNumber[i] + 48 ;
       else if(i==0)
          hexaDecimal[j] =  binaryNumber[i] + 48 ;
        else
          --j;
    
       printf("Equivalent hexadecimal value: ");
       while(j>=0){
          printf("%c",hexaDecimal[j--]);
       }
    
       return 0;
    }
    Sample output: Enter any number any binary number: 1010011011100011110 001001111011110001000100011101110111011110 Equivalent hexadecimal value: 14DC789EF111DDDE

    1. Report
  2. Question:C code for sum of two binary numbers 

    Answer
    #include<stdio.h>
    
    int main(){
    
        long int binary1,binary2;
        int i=0,remainder = 0,sum[20];
    
        printf("Enter any first binary number: ");
        scanf("%ld",&binary1);
        printf("Enter any second binary number: ");
        scanf("%ld",&binary2);
    
        while(binary1!=0||binary2!=0){
             sum[i++] =  (binary1 %10 + binary2 %10 + remainder ) % 2;
             remainder = (binary1 %10 + binary2 %10 + remainder ) / 2;
             binary1 = binary1/10;
             binary2 = binary2/10;
        }
    
        if(remainder!=0)
             sum[i++] = remainder;
    
        --i;
        printf("Sum of two binary numbers: ");
        while(i>=0)
             printf("%d",sum[i--]);
    
       return 0;
    }
    Sample output: Enter any first binary number: 1100011 Enter any second binary number: 1101 Sum of two binary numbers: 1110000

    1. Report
  3. Question:C program for multiplication of two binary numbers 

    Answer
    #include<stdio.h>
    
    int binaryAddition(int,int);
    
    int main(){
    
        long int binary1,binary2,multiply=0;
        int digit,factor=1;
    
        printf("Enter any first binary number: ");
        scanf("%ld",&binary1);
        printf("Enter any second binary number: ");
        scanf("%ld",&binary2);
    
        while(binary2!=0){
             digit =  binary2 %10;
    
             if(digit ==1){
                     binary1=binary1*factor;
                     multiply = binaryAddition(binary1,multiply);
             }
             else
                 binary1=binary1*factor;
       
             binary2 = binary2/10;
             factor = 10;
        }
    
        printf("Product of two binary numbers: %ld",multiply);
       
       return 0;
    }
    
    int binaryAddition(int binary1,int binary2){
    
        int i=0,remainder = 0,sum[20];
        int binarySum=0;
    
        while(binary1!=0||binary2!=0){
             sum[i++] =  (binary1 %10 + binary2 %10 + remainder ) % 2;
             remainder = (binary1 %10 + binary2 %10 + remainder ) / 2;
             binary1 = binary1/10;
             binary2 = binary2/10;
        }
    
        if(remainder!=0)
             sum[i++] = remainder;
        --i;
        while(i>=0)
             binarySum = binarySum*10 + sum[i--];
    
        return binarySum;
    }
    Sample output: Enter any first binary number: 1101 Enter any second binary number: 11 Product of two binary numbers: 100111

    1. Report
  4. Question:C code for fractional binary to decimal converter 

    Answer
    #include<stdio.h>
    #define MAX 1000
    
    int main(){
    
        long double fraDecimal=0.0,dFractional=0.0 ,fraFactor=0.5;
        long int dIntegral = 0,bIntegral=0,bFractional[MAX];
        long int intFactor=1,remainder,i=0,k=0,flag=0;
        char fraBinary[MAX];
    
        printf("Enter any fractional binary number: ");
        scanf("%s",&fraBinary);
       
        while(fraBinary[i]){
            
             if(fraBinary[i] == '.')
                 flag = 1;
             else if(flag==0)
                 bIntegral = bIntegral * 10 + (fraBinary[i] -48);
             else
                  bFractional[k++] = fraBinary[i] -48;
             i++;
        }
       
        while(bIntegral!=0){
            remainder=bIntegral%10;
            dIntegral= dIntegral+remainder*intFactor;
            intFactor=intFactor*2;
            bIntegral=bIntegral/10;
        }
       
        for(i=0;i<k;i++){
             dFractional  = dFractional  + bFractional[i] * fraFactor;
             fraFactor = fraFactor / 2;
        }
    
        fraDecimal = dIntegral + dFractional ;
    
        printf("Equivalent decimal value: %Lf",fraDecimal);
       
        return 0;
    }
    Sample output: Enter any fractional binary number: 11.11 Equivalent decimal value: 3.750000

    1. Report
  5. Question:C code for fractional decimal to binary converter 

    Answer
    #include<stdio.h>
    
    int main(){
       
        long double fraDecimal,fraBinary,bFractional = 0.0,dFractional,fraFactor=0.1;
        long int dIntegral,bIntegral=0;
        long int intFactor=1,remainder,temp,i;
    
        printf("Enter any fractional decimal number: ");
        scanf("%Lf",&fraDecimal);
       
        dIntegral = fraDecimal;
        dFractional =  fraDecimal - dIntegral;
    
        while(dIntegral!=0){
             remainder=dIntegral%2;
             bIntegral=bIntegral+remainder*intFactor;
             dIntegral=dIntegral/2;
             intFactor=intFactor*10;
        }
    
       for(i=1;i<=6;i++){
          
           dFractional = dFractional * 2;
           temp =  dFractional;
            
           bFractional = bFractional + fraFactor* temp;
           if(temp ==1)
                 dFractional = dFractional - temp;
    
           fraFactor=fraFactor/10;
       }
      
       fraBinary =  bIntegral +  bFractional;
       printf("Equivalent binary value: %lf",fraBinary);
       
       return 0;
    }
    Sample output: Enter any fractional decimal number: 5.7 Equivalent binary value: 101.101100

    1. Report
  6. Question:Convert numbers to roman numerals in c 

    Answer
    #include<stdio.h>
    
    void predigits(char c1,char c2);
    void postdigits(char c,int n);
    
    char roman_Number[1000];
    int i=0;
    
    int main(){
    
        int j;
        long int number;
       
        printf("Enter any natural number: ");
        scanf("%d",&number);
       
        if(number <= 0){
             printf("Invalid number");
             return 0;
        }
    
        while(number != 0){
    
             if(number >= 1000){
                 postdigits('M',number/1000);
                 number = number - (number/1000) * 1000;
             }
             else if(number >=500){
                 if(number < (500 + 4 * 100)){
                     postdigits('D',number/500);
                     number = number - (number/500) * 500;
                 }
                 else{
                     predigits('C','M');
                     number = number - (1000-100);
                 }
             }
             else if(number >=100){
                 if(number < (100 + 3 * 100)){
                     postdigits('C',number/100);
                     number = number - (number/100) * 100;
                 }
                 else{
                     predigits('L','D');
                     number = number - (500-100);
                 }
             }
             else if(number >=50){
                 if(number < (50 + 4 * 10)){
                     postdigits('L',number/50);
                     number = number - (number/50) * 50;
                 }
                 else{
                     predigits('X','C');
                     number = number - (100-10);
                 }
             }
             else if(number >=10){
                 if(number < (10 + 3 * 10)){
                     postdigits('X',number/10);
                     number = number - (number/10) * 10;
                 }
                 else{
                     predigits('X','L');
                     number = number - (50-10);
                 }
             }
             else if(number >=5){
                 if(number < (5 + 4 * 1)){
                     postdigits('V',number/5);
                     number = number - (number/5) * 5;
                 }
                 else{
                     predigits('I','X');
                     number = number - (10-1);
                 }
             }
             else if(number >=1){
                 if(number < 4){
                     postdigits('I',number/1);
                     number = number - (number/1) * 1;
                 }
                 else{
                     predigits('I','V');
                     number = number - (5-1);
                 }
             }
        }
    
        printf("Roman number will be: ");
        for(j=0;j<i;j++)
             printf("%c",roman_Number[j]);
    
        return 0;
    
    }
    
    void predigits(char c1,char c2){
        roman_Number[i++] = c1;
        roman_Number[i++] = c2;
    }
    
    void postdigits(char c,int n){
        int j;
        for(j=0;j<n;j++)
             roman_Number[i++] = c;
       
    }
    Sample output: Enter any natural number: 87 Roman number will be: LXXXVII

    1. Report
  7. Question:C code for roman numbers to English numbers 

    Answer
    #include<stdio.h>
    #include<string.h>
    
    int digitValue(char);
    
    int main(){
    
        char roman_Number[1000];
        int i=0;
        long int number =0;
       
        printf("Enter any roman number (Valid digits are I, V, X, L, C, D, M):  \n");
        scanf("%s",roman_Number);
       
        while(roman_Number[i]){
            
             if(digitValue(roman_Number[i]) < 0){
                 printf("Invalid roman digit : %c",roman_Number[i]);
                 return 0;
             }
                
             if((strlen(roman_Number) -i) > 2){
                 if(digitValue(roman_Number[i]) < digitValue(roman_Number[i+2])){
                     printf("Invalid roman number");
                     return 0;
                 }
             }
    
             if(digitValue(roman_Number[i]) >= digitValue(roman_Number[i+1]))
                 number = number + digitValue(roman_Number[i]);
             else{
                 number = number + (digitValue(roman_Number[i+1]) - digitValue(roman_Number[i]));
                 i++;
             }
             i++;
        }
            
        printf("Its decimal value is : %ld",number);
       
        return 0;
    
    }
    
    int digitValue(char c){
    
        int value=0;
    
        switch(c){
             case 'I': value = 1; break;
             case 'V': value = 5; break;
             case 'X': value = 10; break;
             case 'L': value = 50; break;
             case 'C': value = 100; break;
             case 'D': value = 500; break;
             case 'M': value = 1000; break;
             case '\0': value = 0; break;
             default: value = -1; 
        }
    
        return value;
    }
    Sample output: Enter any roman number (Valid digits are I, V, X, L, C, D, M): XVII Its decimal value is: 17

    1. Report
  8. Question:C code to covert each digits of a number in English word 

    Answer
    #include<stdio.h>
    
    int main(){
    
        int number,i=0,j,digit;
        char * word[1000];
    
        printf("Enter any integer: ");
        scanf("%d",&number);
    
        while(number){
    
        digit = number %10;
        number = number /10;
    
             switch(digit){
                 case 0: word[i++] = "zero"; break;
                 case 1: word[i++] = "one"; break;
                 case 2: word[i++] = "two"; break;
                 case 3: word[i++] = "three"; break;
                 case 4: word[i++] = "four"; break;
                 case 5: word[i++] = "five"; break;
                 case 6: word[i++] = "six"; break;
                 case 7: word[i++] = "seven"; break;
                 case 8: word[i++] = "eight"; break;
                 case 9: word[i++] = "nine"; break;
    
             }
        }
       
        for(j=i-1;j>=0;j--){
             printf("%s ",word[j]);
        }
    
        return 0;
    
    }
    Sample output: Enter any integer: 23451208 two three four five one two zero eight

    1. Report
  9. Question:C code to convert any number to English word 

    Answer
    #include<stdio.h>
    #include<string.h>
    
    void toWord(int,int);
    char * getPositionValue(int);
    char * digitToWord(int);
    
    char  word[100][30];
    int i =0;
    
    int main(){
    
        int j,k,subnumer;
        unsigned long int number;
    
        printf("Enter any postive number: ");
        scanf("%lu",&number);
       
        if(number ==0){
             printf("Zero");
             return 0;
        }
    
        while(number){
    
             if(i==1){
                 toWord(number %10,i);
                 number = number/10;
             }else{
                 toWord(number %100,i);
                 number = number/100;
             }
    
             i++;
            
        }
    
        printf("Number in word: ");
        *word[i-1] = *word[i-1] - 32;
        for(j=i-1;j>=0;j--){
             printf("%s",word[j]);
        }
    
        return 0;
    
    }
    
    void toWord(int number,int position){
    
        char  numberToword[100]={" "};
    
        if(number ==0){
        }else if (number < 20 ||number %10==0){
             strcpy(numberToword,digitToWord(number));
        }else{
             strcpy(numberToword,digitToWord((number/10)*10));
             strcat(numberToword,digitToWord(number%10));
        }
       
        strcat(numberToword,getPositionValue(position));
        strcpy(word[i],numberToword);
    }
    
    char * getPositionValue(int postion){
    
        static char positionValue[10]=" ";
       
        switch(postion){
    
             case 1: strcpy(positionValue,"hundreds "); break;
             case 2: strcpy(positionValue,"thousand "); break;
             case 3: strcpy(positionValue,"lakh "); break;
             case 4: strcpy(positionValue,"crore "); break;
             case 5: strcpy(positionValue,"arab "); break;
             case 6: strcpy(positionValue,"kharab "); break;
             case 7: strcpy(positionValue,"neel "); break;
             case 8: strcpy(positionValue,"padam "); break;
        }
        
        return positionValue;
    }
    
    char * digitToWord(int digit){
    
         static char digitInWord[10]=" ";
    
        switch(digit){
             case 1: strcpy(digitInWord , "one "); break;
             case 2: strcpy(digitInWord , "two "); break;
             case 3: strcpy(digitInWord , "three "); break;
             case 4: strcpy(digitInWord , "four "); break;
             case 5: strcpy(digitInWord , "five "); break;
             case 6: strcpy(digitInWord , "six "); break;
             case 7: strcpy(digitInWord , "seven "); break;
             case 8: strcpy(digitInWord , "eight "); break;
             case 9: strcpy(digitInWord , "nine ");break;
             case 10: strcpy(digitInWord , "ten "); break;
             case 11: strcpy(digitInWord , "eleven "); break;
             case 12: strcpy(digitInWord , "twelve "); break;
             case 13: strcpy(digitInWord , "thirteen "); break;
             case 14: strcpy(digitInWord , "fourteen "); break;
             case 15: strcpy(digitInWord , "fifteen "); break;
             case 16: strcpy(digitInWord , "sixteen "); break;
             case 17: strcpy(digitInWord , "seventeen "); break;
             case 18: strcpy(digitInWord , "eighteen "); break;
             case 19: strcpy(digitInWord , "nineteen "); break;
             case 20: strcpy(digitInWord , "twenty "); break;
             case 30: strcpy(digitInWord , "thirty "); break;
             case 40: strcpy(digitInWord , "fourty "); break;
             case 50: strcpy(digitInWord , "fifty "); break;
             case 60: strcpy(digitInWord , "sixty "); break;
             case 70: strcpy(digitInWord , "seventy "); break;
             case 80: strcpy(digitInWord , "eighty "); break;
             case 90: strcpy(digitInWord,"ninety "); break;
        }
       
        return digitInWord;
    }

    1. Report
  10. Question:C code to convert one unit to other unit 

    Answer
    #include<stdio.h>
    #include<math.h>
    
    int main(){
       
        char fromUnit,toUnit;
        char *fUnit,*tUnit;
        long double fromValue,meterValue,toValue;
        int power =0;
    
        printf("To convert the 12 Inch to Foot\n");
        printf("enter the the unit in the format : dc12\n");
    
        printf("Ell: a\n");
        printf("Femi: b\n");
        printf("Foot: c\n");
        printf("Inch: d\n");
        printf("Light year: e\n");
        printf("Metre: f\n");
        printf("Mile: g\n");
        printf("Nano meter: h\n");
        printf("Pace: i\n");
        printf("Point: j\n");
        printf("Yard: k\n");
        printf("Mili meter: l\n");
        printf("Centi meter: m\n");
        printf("Deci meter: n\n");
        printf("Deca meter: o\n");
        printf("Hecto meter: p\n");
        printf("Kilo meter: q\n");
    
        scanf("%c%c%Lf",&fromUnit,&toUnit,&fromValue); 
    
        switch(fromUnit){
             case 'a': meterValue = fromValue * 1.143; fUnit="ell"; break;
             case 'b': meterValue = fromValue ; power = -15; fUnit="fm"; break;
             case 'c': meterValue = fromValue * 0.3048; fUnit="ft"; break;
             case 'd': meterValue = fromValue * 0.0254; fUnit="in"; break;
             case 'e': meterValue = fromValue * 9.4607304725808; power =15; fUnit="ly"; break;
             case 'f': meterValue = fromValue; fUnit="m"; break;
             case 'g': meterValue = fromValue * 1609.344; fUnit="mi"; break;
             case 'h': meterValue = fromValue; fUnit="nm"; power = -9; break;
             case 'i': meterValue = fromValue * 0.762 ; fUnit="pace"; break;
             case 'j': meterValue = fromValue * 0.000351450; fUnit="pt"; break;
             case 'k': meterValue = fromValue * 0.9144; fUnit="yd"; break;
             case 'l': meterValue = fromValue * 0.001; fUnit="mm"; break;
             case 'm': meterValue = fromValue * 0.01; fUnit="cm"; break;
             case 'n': meterValue = fromValue * 0.1; fUnit="deci meter"; break;
             case 'o': meterValue = fromValue * 10; fUnit="deca meter"; break;
             case 'p': meterValue = fromValue * 100; fUnit="hm"; break;
             case 'q': meterValue = fromValue * 1000; fUnit="km"; break;
             default:
                 printf("Invalid input"); exit(0);
        }
    
        switch(toUnit){
             case 'a': toValue = meterValue/1.143; tUnit="ell"; break;
             case 'b': toValue = meterValue; tUnit="fm"; break;
             case 'c': toValue = meterValue/0.3048; tUnit="ft"; break;
             case 'd': toValue = meterValue/0.0254; tUnit="in"; break;
             case 'e': toValue = meterValue/9.4607304725808; tUnit="ly"; break;
             case 'f': toValue = meterValue; tUnit="m";break;
             case 'g': toValue = meterValue/1609.344; tUnit="mi"; break;
             case 'h': toValue = meterValue; tUnit="nm"; break;
             case 'i': toValue = meterValue/0.762; tUnit="pace"; break;
             case 'j': toValue = meterValue/0.000351450; tUnit="pt"; break;
             case 'k': toValue = meterValue/0.9144; tUnit="yd"; break;
             case 'l': toValue = meterValue/0.001; tUnit="mm"; break;
             case 'm': toValue = meterValue/0.01; tUnit="cm"; break;
             case 'n': toValue = meterValue/0.1; tUnit="deci meter"; break;
             case 'o': toValue = meterValue/10; tUnit="deca meter"; break;
             case 'p': toValue = meterValue/100; tUnit="hm"; break;
             case 'q': toValue = meterValue/1000; tUnit="km"; break;
             default:
                 printf("Invalid input"); exit(0);
        }
       
        if(power==0)
             printf("%.4Lf %s = %.4Lf %s",fromValue,fUnit,toValue,tUnit);
        else{
             while(tovalue > 10 
             printf("%.4Lf %s = %.4Lf*10^%d %s",fromValue,fUnit,toValue,power,tUnit);
        }
    
    
        return 0;
    }

    1. Report
Copyright © 2024. Powered by Intellect Software Ltd