C Programming Tutorial

 
 
 
 
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>

void main()
{
    int rev[20],a[20],b[20],c[20];
    int i,j,k,l,flag,cntint,cntfra;
    int rem,num1,num3;
    float rem1,dno,num2,num4;
    char s[20];
    clrscr();
    cntint=cntfra=0;
    flag=l=0;
    rem=0;
    printf(\"ENTER THE BINARY NO : \");
    scanf(\"%s\",&s);
    for(i=0,j=0,k=0;i<strlen(s);i++)
    {
        if(s[i]==\'.\')
        {
            flag=1;
        }
        else if(flag==0)
        a[k++]=s[i]-48;
        else if(flag==1)
        b[j++]=s[i]-48;
    }
    cntint=k;
    cntfra=j;
    for(j=0,i=cntint-1;j<cntint;j++,i--)
    {
        rem = rem + (a[j] * pow(2,i));
    }
    for(k=0,i=1;k<cntfra;k++,i++)
    {
        rem1 = rem1 + (b[k] / pow(2,i));
    }
    rem1 = rem + rem1;
    dno=rem1;
    num1 = (int)dno;
    num2 = dno - num1;
    i=0;
    while(num1!=0)
    {
        rem = num1 % 8;
        rev[i] = rem;
        num1 = num1 / 8;
        i++;
    }
    j=0;
    while(num2!=0.0)
    {
        num2 =num2 * 8;
        num3 = (int) num2;
        num4 = num2 - num3;
        num2 = num4;
        c[j] = num3;
        j++;
        if(j==4)
        {
            break;
        }
    }
    l=i;
    printf(\"\\nTHE OCTAL VALUE OF GIVEN BINARY NO IS : \");
    for(i=l-1;i>=0;i--)
    {
        printf(\"%d\",rev[i]);
    }
    printf(\".\");
    for( k=0;k<j;k++)
    {
        printf(\"%d\",c[k]);
    }
    getch();
}
/* OUTPUT
--------------------------------------------------------
ENTER THE BINARY NO : 1001010.110

THE OCTAL VALUE OF GIVEN BINARY NO IS : 112.6
*/

    Related Post:
  1. program to read the price of an item in decimal form and print the output in paisa

  2. PROGRAM TO CONVERT OCTAL TO DECIMAL USING FLOAT VALUES

  3. Program to create processes using fork() and check orphan state

  4. Program that takes a string from user and prints the total number of characters, words and lines present in the string.

  5. Program to convert value from one currency to another i.e. from dollar to rupees and rupees to dollar

  6. Program to display pyramid

  7. Find Death Date C Program

  8. Program to find the roots of an equation ax2 + bx + c = 0

  9. Program to calculate square of a given number

  10. Program that implements a priority queue using an array

  11. Program to count number of employee in the company using structures / file

  12. program that takes string and word from a user and displays substring including user inputted word....

  13. PROGRAM TO FIND CORRELATION BETWEEN TWO DATA SETS DEFINED NUMBER OF PROCESSES

  14. Basic GAUSS ELIMINATION METHOD, GAUSS ELIMINATION WITH PIVOTING, GAUSS JACOBI METHOD, GAUSS SEIDEL METHOD

  15. Program that reads the encoded alphabetic text from a file and produces decoded file by replacing each character with the character that occurs five

  16. Program to display numbers using for loop

  17. Program to create a singly linked list of numbers using threads

  18. Program to read two positive numbers and interchange its values using *(mul) and /(div) operators and without using any extra variable

  19. Program using structures/file to print name and age of the oldest and the youngest student in the class

  20. Program to display entered character in capital letter

 
 
Didn't find what you were looking for? Find more on PROGRAM TO CONVERT BINARY FLOTING POINT TO OCTAL FLOATING POINT