09 June, 2013

C Program For Conversion Of Decimal No Into Octal No.

This Post Contains A C Program For Conversion Of Decimal No Into Octal No With Correct Source Code & Output. This Program Is Written, Compiled & Executed At Turbo C/C++3.0 Compiler & Will Help You To Understand The Concept Of 'For-loop', 'While-loop' & 'If...else' From C Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.


# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.


C Program For Conversion Of Decimal No Into Octal No.

/* Declaration Of Header Files */
# include <stdio.h>
# include <conio.h>

/* Start Of Main Program */
void main()
{

   /* Declaration Of Variables */
   long Num;
   int   r,   q,   o,   a[ 20 ], b[ 20 ];
   clrscr();

   /* Asking For The Input From User */
   printf(" \n Enter Any No. : ");
   scanf("%d", &Num);

   /* Source Code For Computing Conversion Of Decimal Into Octal */
   o   =   0;
   while (   Num   >   0   )
   {
     if  (  Num  <  8  )
     {
       a[ o++ ]   =   Num;
       break;
     }
     else
     {
       a[ o++ ]   =   Num   %   8 ;
       Num   =   Num  /  8 ;
     }
   }
   r  =  0;
   for  (  q  =  0 - 1;  q  >=  0;  q--  )
   {
     b[ r++ ]  =  a[ q ] ;
   }

   /* Printing The Output On Console/Screen */
   printf(" \n Octal No. :  ");
   for  (  q  =  0;  q  <  r;  q++  )
   {
     printf("%d", b[ q ]);
   }
   getch();
}
/* End Of Main Program */ 




No comments:

Post a Comment

Subscribe To:

Most Commonly Asked Programs In 'C' & 'C++' Language.

Blog Archive