13 June, 2013

Mini Project :~ C Program To Perform Various Operations On Strings. [Such As : Find Length, Copy, Reverse, Palindrome, Concatenation, Sub-string]

This Post Contains A Mini Project :~ C Program To Perform Various Operations On Strings. [Such As : Find Length, Copy, Reverse, Palindrome, Concatenation, Sub-string] With Correct Source Code, Algorithm & Output. This Program Is Written, Compiled & Executed At Turbo C/C++3.0 Compiler & Will Help You To Understand The Concept Of 'String Operations', 'Character Arrays', 'Functions', 'Menu Driven Concept' 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.



Mini Project :~ C Program To Perform Various Operations On Strings. [Such As : Find Length, Copy, Reverse, Palindrome, Concatenation, Sub-string]
/* Declaration Of Header Files */
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

/* Function Declarations */
void Scan1(char *);
void Scan2(char * , char *);
void Leng (char *);
void Copy (char * , char *);
void Reve (char * , char *);
void Palindrome(char * , char *);
void Concat    (char * , char *);
void Subs (char Str1[] , char Str2[]);

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

{
 /* Declaration Of Local Variables Of 'main()' Function */

 int  Num = 0;
 char Str1[50] , Str2[50];

 clrscr();

 /* Printing 'Menu' On Screen/Console */
 printf(" \n :: Welcome To 'String Operation' Program :: \n ");

     do
     {
         printf(" \n Please Select One Of The Options From Following Menu : ");

         printf(" \n 1. Length Of Given String. \n 2. Copy   Of Given String.");
         printf(" \n 3. Reverse The String. \n 4. Check For Palindrome.");
         printf(" \n 5.Concatenate The Strings. \n 6. To Find The Sub-string.");
         printf(" \n 7. EXIT  From  PROGRAM.");

         printf(" \n Please Enter Your Option Here ::\t\a");

         scanf("%d" , &Num);

         switch(Num)
         {

              case 1: textcolor(RED);
                      clrscr();
                      printf(" \n :: Welcome To Length Function :: \n ");
                      Scan1( Str1 );  // Call To Function.
                      Leng ( Str1 );   // Call To Function.
                      break;

              case 2: textcolor(GREEN);
                      clrscr();
                      printf(" \n :: Welcome To Copy Function :: \n ");
                      Scan1( Str1 );
                      Copy ( Str1 , Str2 );  // Call To Function.
                      break;

              case 3: textcolor(YELLOW);
                      clrscr();
                      printf(" \n :: Welcome To Reverse Function :: \n ");
                      Scan1( Str1 );
                      Reve ( Str1 , Str2 );   // Call To Function.
                      break;

              case 4: textcolor(10);
                      clrscr();
                      printf(" \n :: Welcome To Palindrome Function :: \n ");
                      Scan1( Str1 );
                      Palindrome( Str1 , Str2 );  // Call To Function.
                      break;

              case 5: textcolor(12);
                      clrscr();
                      printf(" \n :: Welcome To Concatenation Function :: \n ");
                      Scan2( Str1 , Str2 );
                      Concat(Str1 , Str2);   // Call To Function.
                      break;

              case 6: textcolor(5);
                      clrscr();
                      printf(" \n :: Welcome To Substring Function :: \n ");
                      Scan2( Str1 , Str2 );
                      Subs ( Str1 , Str2 );   // Call To Function.
                      break;

              case 7: exit (0);  // Exit From Program.
                      break;

              default: printf(" \n Sorry!!!. Please Enter A Valid Choice. ");
        }
 }while( Num <= 7 );
 /* End Of 'Menu' */
 getch();
}
/* End Of Main Program */

void Scan1(char *Str1)   // Function Definition.

{

    printf(" \n Please Enter The String ::\t ");

    fflush( stdin );

    gets  ( Str1 );

}

void Scan2(char *Str1 , char *Str2)   // Function Definition.

{

    printf(" \n Please Enter String 1 ::\t ");

    fflush( stdin );

    gets  ( Str1 );

    printf(" \n Please Enter String 2 ::\t ");

    fflush( stdin );

    gets  ( Str2 );

}

void Leng( char *Str1 )   // Function Definition.

{

    int i = 0;

    while( Str1[i] != '\0' )

    {

        i++;

    }

    printf(" \n The Length Of String Is ::\t%d ", i);

    getch();

}

void Copy( char *Str1 , char *Str2 )  // Function Definition.

{

    int i = 0 , j = 0;

    while( Str1[i] != '\0' )

    {

        Str2[j] = Str1[i];

        j++;

        i++;

    }

    Str2[j] = '\0';

    printf("The Entered String Is ::\t");

    puts(Str1);

    printf("Copy Of Given String Is ::\t");

    puts(Str2);

    getch();

}

void Reve( char *Str1 , char *Str2 )    // Function Definition.

{

    int i = 0 , j = 0;

    while( Str1[i] != '\0' )

    {

        i++;

    }

    for(i--; i>=0; i--)

    {

        Str2[j] = Str1[i];

        j++;

    }

    Str2[j] = '\0';

    printf("The Entered String Is ::\t");

    puts(Str1);

    printf("Reversed Of Given String Is ::\t");

    puts(Str2);

    getch();

}

void Palindrome( char *Str1 , char *Str2 )   // Function Definition.

{

    int i = 0, j = 0, flag = 0;

    while( Str1[i] != '\0' )

    {

        i++;

    }

    for(i--; i>=0; i--)

    {

        Str2[j] = Str1[i];

        j++;

    }

    Str2[j] = '\0';

    i=0;

    j--;

    while( Str1[i] == Str1[j] )

    {

        flag = 1;

        i++;

        j--;

    }

    if( flag == 1 )

    {

        printf("\nThe Given String Is A Palindrome");

    }

    else

    {

        printf("\nThe Given String Is Not A Palindrome");

    }

    getch();

}

void Concat( char *Str1 , char *Str2 )   // Function Definition.

{

    int i = 0 , j = 0;

    while( Str1[i] != '\0' )

    {

        i++;

    }

    while( Str2[j] != '\0' )

    {

        Str1[i] = Str2[j];

        i++;

        j++;

    }

    Str1[i] = '\0';

    printf("\n The Concatenated String Is :");

    puts( Str1 );

    getch();

}

void Subs( char Str1[] , char Str2[] )   // Function Definition.

{

    int i , j , flag = 0;

    for(j=0; Str2[j] != '\0'; j++)

    {

        for(i=0; Str1[i] != '\0'; i++)

        {

            if( Str1[i] == Str2[j] )

            {

                flag = 1;

                break;

            }

        }

    }

    if( flag == 1 )

        {

            printf("\nThe Given String 2 Is A Substring Of String 1");

        }

        else

        {

            printf("\nThe Given String 2 Is Not A Substring Of String 1");

        }

    getch();

}




12 June, 2013

C++ Program To Find & Print Inverse Of A Matrix.

This Post Contains A C++ Program To Find & Print Inverse Of A Matrix With Correct Source Code, Algorithm & Output. This Program Is Written, Compiled & Executed At Turbo C/C++3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays', 'For-Loop' & 'Nested-Loops' 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 To Find & Print Inverse Of A Matrix.
/* Declaration Of Header Files */
#include <iostream.h>
#include <conio.h>

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

/* Declaration Of Variables */
int a[3][3], b[3][3]; c[10];
float d[3][3], det;
int i, j, l, m, t, k;

clrscr();

/* Accepting Values Of 2D Array [ Matrix ] */

       cout  <<  "  Enter  9  Values for 2D Array  :  ";

       for  (  i  =  0;  i  <  3;  i++  )

       {

                for  (  j  =  0;  j  <  3;  j++  )

                {

                         cin  >>  a [ i ][ j ];

                }

       }

/* Source Code For Computing Inverse Of A Matrix */

for(l=0; l<3; l++)

{

   for(m=0; m<3; m++)

   {

      t=0;

      for(i=0; i<3; i++)

      {

         for(j=0; j<3; j++)

         {

            if(i != l && j != m)

            {

               c[t]=a[i][j]; 

               t++;

            }

         }

      }

      b[l][m]=( c[0]*c[3] )-( c[1]*c[2] );

   }

}

   cout  <<  " \n Matrix A : ";

   for(i=0; i<3; i++)

   {

      cout  <<  "\n";

      for(j=0; j<3; j++)

      {

         cout  <<  a[i][j]<<"\t";

      }

   }

   cout  <<  " \n Adjoint Matrix : ";

   for(i=0; i<3; i++)

   {

      cout  <<  "\n";

      for(j=0; j<3; j++)

      {

         cout  <<  b[i][j]  <<  "\t";

      }

   }

   for(i=0; i<3; i++)

   {

      for(j=0; j<3; j++)

      {

         if(i+j==1 || i+j==3)

            a[i][j]=a[i]][j]*-l;

      }

   }

   cout  <<  " \n Values Of Matrix A : ";

   for(i=0; i<3; i++)

   {

      cout  <<  "\n";

      for(j=0; j<3; j++)

      {

         cout  <<  a[i][j]  <<  "\t";

      }

   }

   for(i=0; i<3; i++)

   {

      det=0;

      for(j=0; j<3; j++)

      {

         det=det+a[i][j]*b[i][j];

      }

   }

cout  <<  " \n Determinant : "  <<  det;

if(det != 0)

{

      for(i=0; i<3; i++)

      {

         for(j=0; j<3; j++)

         {

            d[i][j]=b[i][j]/det;

         }

      }

/* Printing The Output Onto The Screen/Console */

      cout  <<  " \n Inverse Of Matrix A : ";

      for(i=0; i<3; i++)

      {

         cout  <<  "\n";

         for(j=0; j<3; j++)

         {

            cout  <<  d[i][j]  <<  "\t";

         }

      }     

}

else

{

   cout  <<  " \n Inverse Of Matrix Is Not Possible";

}

getch();

}

/* End Of Main Program */




C++ Program For Sorting Of A Matrix By Rows.

This Post Contains A C++ Program For Sorting Of A Matrix By Rows With Correct Source Code, Algorithm & Output. This Program Is Written, Compiled & Executed At Turbo C/C++3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays', 'For-Loops', 'If...else' & 'Nested Loops' 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 Sorting Of A Matrix By Rows.
/* Declaration Of Header Files */
#include <iostream.h>
#include <conio.h>

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

/* Declaration Of Variables */
int a[10][10], i, j, r, c, t;

clrscr();

      /* Asking For The Input From User */

       cout  <<  "  Enter Number Of Rows & Columns Of 2D Array [ Matrix ]  :  ";

       cin  >>  r  >>  c ;

      

       //  Accepting Values Of 2D Array [ Matrix ]

       cout  <<  "  Enter  "  <<  r  *  c  <<  "  Values for 2D Array  :  ";

       for  (  i  =  0;  i  <  r;  i++  )

       {

                for  (  j  =  0;  j  <  c;  j++  )

                {

                         cin  >>  a [ i ][ j ];

                }

       }

       // Printing Values Of 2D Array [ Matrix ]

       cout  <<  "  Values Of 2D Array [ Matrix ] Are  :  ";

       for  (  i  =  0;  i  <  r;  i++  )

       {

                cout  <<  " \n ";

                for  (  j  =  0;  j  <  c;  j++  )

                {

                         cin  >>  a [ i ][ j ];

                }

       }

/* Source Code For Sorting Of A Matrix By Rows */

   for(i=0; i < r; i++)

   {

      for(j=0; j < c; j++)

      {

         for(k=j+1; k < q; k++)

         {

            if(a[i][j] > a[i][k])

            {

               t=a[i][j];

               a[i][j]=a[i][k];

               a[i][k]=t;

            }

         }

      }

   }
/* Printing The Output Onto The Screen/Console */   

   cout  <<  " \n After Sorting Elements Of Matrix A : ";

   for(i=0; i < r; i++)

   {

      cout  <<  "\n";

      for(j=0; j < c; j++)

      {

         cout  <<  a[i][j]  <<  "\t";

      }

   }

getch();

}

/* End Of Main Program */

Output:
Enter Order For Array A : 3 3

Enter 9 Values For Array :

9  8  7  6  5  4  3  2  1

After Sorting Elements Of Matrix A :

7  8  9

4  5  6

1  2  3




C++ Program For Sorting All Elements Of A Matrix.

This Post Contains A C++ Program For Sorting All Elements Of A Matrix With Correct Source Code, Algorithm & Output. This Program Is Written, Compiled & Executed At Turbo C/C++3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays', 'For-Loop', 'If...else' & 'Nested Loops' 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 Sorting All Elements Of A Matrix.
/* Declaration Of Header Files */
#include <iostream.h>
#include <conio.h>

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

/* Declaration Of Variables */
int a[10][10], b[30], i, j, r, c, s, t;

clrscr();

/* Asking For The Input From User */
cout  <<  "  Enter Number Of Rows & Columns Of 2D Array [ Matrix ]  :  ";
cin  >>  r  >>  c ;

      

//  Accepting Values Of 2D Array [ Matrix ]
cout  <<  "  Enter  "  <<  r  *  c  <<  "  Values for 2D Array  :  ";
t=0;
for  (  i  =  0;  i  <  r;  i++  )
{

      for  (  j  =  0;  j  <  c;  j++  )

     {

            cin  >>  a [ i ][ j ];

            b[t]=a[i][j];

            t++

     }
}

/* Source Code For Sorting All Elements Of A Matrix */
for(i=0; i < t; i++)
{

      for(j=i+1; j b[j])

           s=b[i];

           b[i]=b[j];

           b[j]=s;

      }
}

cout  <<  " \n Elements Of Matrix A : ";
for(i=0; i < r; i++)
{

      cout  <<  "\n";

      for(j=0; j < c; j++)

      {

         cout  <<  a[i][j]  <<  "\t";

      }
}

/* Assigning Sorted Elements */
t=0;
for(i=0; i < r; i++)
{

      for(j=0; j < c; j++)

      {

         a[i][j]=b[t];

         t++;

      }
}

/* Printing The Output Onto The Screen/Console */
cout  <<  " \n After Sorting Elements Of Matrix A : ";
for(i=0; i < r; i++)
{

      cout  <<  "\n";

      for(j=0; j < c; j++)

      {

         cout  <<  a[i][j]  <<  "\t";

      }
}

getch();

}
/* End Of Main Program */

Output:
Enter Order For Array A : 3 3

Enter 9 Values For Array :

1  2  3  4  5  6  7  8  9

Array A Is :

1  4  9

2  7  8

5  6  3

After Sorting Elements Of Matrix A :

1  2  3

4  5  6

7  8  9




10 June, 2013

C Program To Find Highest And Lowest Elements Of An Array.

This Post Contains A C Program To Find Highest And Lowest Elements Of An Array 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 'Arrays' & 'For-loop' 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 To Find Highest And Lowest Elements Of An Array.
 
/* Declaration Of Header Files */
#inlcude<stdio.h>
#include<conio.h>

/* Start Of Main Program */
void main()
{
    /* Declaration Of Variables */ 
    int a[20];
    int e, dim, highest, lowest;
    clrscr();

    /* Asking For The Input From User */
    printf(" \n Enter The Dimension Of Array : ");
    scanf("%d", &dim);
    printf(" \n Now Enter The %d Elements Into Array : ", dim);
    for( e=0; e<dim; e++ )
    {
        scanf("%d", &a[e]);
    }

    /* Source Code For Computing Highest And Lowest Elements Of An Array */
    highest=a[0];
    lowest=a[0];
    for( e=0; e<dim; e++ )
    {
        if( a[e] > highest )
        {
            highest = a[e];
        }
        if( a[e] < lowest )
        {
            lowest = a[e];
        }
    }

    /* Printing The Output Onto The Screen/Console */
    printf(" \n Highest Element Is : ", highest);
    printf(" \n Lowest Element Is : ", lowest);
    getch();
}
/* End Of Main Program */


Output :

Enter The Dimension Of Array : 5

Now Enter The 5 Elements Into Array : 1  2  3  4  5

Highest Element Is : 5

Lowest Element Is : 1




C Program For Swapping Of Two Arrays.

This Post Contains A C Program For Swapping Of Two Arrays 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 'Arrays' & 'For-loop' 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.


When It Comes To Arrays, Most Of Us Get Confused & Hence Some Of Us Find Or Thinks That This Particular Concept Is Complicated As Well As Tricky. But The Following Code Will Make It Really Simple For You To Understand.

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

  
C Program For Swapping Of Two Arrays.

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

/* Start Of Main Program */
void main()
{
   /* Declaration Of Variables */
   int a[10], b[10], f, p;
   clrscr();

   /* Asking For The Input From User */
   printf(" \n Enter Dimension : ");
   scanf("%d", &f);
   printf(" \n Enter %d Values For Array A : ", f);
   for ( p = 0; p < f; p++ )
   {
        scanf("%d", &a[p]);
   }

   /* Asking For The Input From User */
   printf(" \n Enter %d Values For Array B : ", f);
   for ( p = 0; p < f; p++ )
   {
     scanf("%d", &b[p]);
   }

   /* Printing The Values Of Array A */
   printf(" \n Values For Array A : ");
   for ( p = 0; p < f; p++ )
   {
     printf(" %d \t ", a[p]);
   }

   /* Printing The Values Of Array B */
   printf(" \n Values For Array B : ");
   for ( p = 0; p < f; p++ )
   {
     printf(" %d \t ", b[p]);
   }

   /* Source Code For Swapping Of Two Arrays */
   for ( p = 0; p < f; p++ )
   {
     a[p] = a[p] + b[p];
     b[p] = a[p] - b[p];
     a[p] = a[p] - b[p];
   }

   /* Printing The Output On The Screen/Console */
   printf(" \n After Swapping : \n ");
   printf(" Values For Array A : ");
   for ( p = 0; p < f; p++ )
   {
     printf(" %d \t ", a[p]);
   }
   printf(" Values For Array B : ");
   for ( p = 0; p < f; p++ )
   {
     printf(" %d \t ", b[p]);
   }
  
   getch();
}
/* End Of Main Program */

Output  :

Enter Dimension  :  3

Enter 3 Values For Array A  :  1  2  3

Enter Dimension  :  3

Enter 3 Values For Array B  :  4  5  6

Values Of Array A  :  1  2  3

Values Of Array B  :  4  5  6

After Swapping  :

Values Of Array A  :   4  5  6

Values Of Array B  :   1  2  3



  




09 June, 2013

C Program To Print An Array Using Pointer.

This Post Contains A C Program To Print An Array Using Pointer With Correct Source Code, Algorithm & Output. This Program Is Written, Compiled & Executed At Turbo C/C++3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays' & 'Pointers' 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.
  


  • A linear array is a list of finite number 'n' of homogeneous data elements.
  • The elements of array are referenced by index set consisting of 'n' consecutive numbers.
  • The elements of array are stored respectively in successive memory locations.
  • The number 'n' of elements is called as 'length' or 'size' of the array.
  • Length Of Array = UB - LB + 1.
          Where UB = largest index i.e. upper bound.
                     LB = smallest index i.e. lower bound.
  • The elements of array A may be denoted by subscript notation.
          A1A2A3,  .......... An
  • But in languages generally bracket notation is used.
          A[0], A[1], A[2], .......... A[n]

   
C Program To Print An Array Using Pointer.

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

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

/* Declaration Of Variables */
int i, a[10], *ptr;
clrscr();

/* Asking For The Input From User */
printf(" \n Please Enter 10 Numbers For An Array 'A' : ");
for(i=0; i<10; i++)
{
   scanf("%d", &a[i]);
}

/* Printing The Output Onto The Screen/Console */
ptr=&a;                                 // Or You Can Also Denote ptr=&a[0];
printf(" \n The Entered Numbers Are : \n ");
for(i=0; i<10; i++)
{
   printf("%d \t", *ptr);
   ptr++;
}
getch();
}
/* End Of Main Program */


Output :

Please Enter 10 Numbers For An Array 'A' :
1  2  3  4  5  6  7  8  9  10

The Entered Numbers Are :
1  2  3  4  5  6  7  8  9  10

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

C Program To Print An Array Onto Screen/Console.

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

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

/* Declaration Of Variables */
int i, a[10];
clrscr();

/* Asking For The Input From User */
printf(" \n Please Enter 10 Numbers For An Array 'A' : ");
for(i=0; i<10; i++)
{
   scanf("%d", &a[i]);
}

/* Printing The Output Onto The Screen/Console */
printf(" \n The Entered Numbers Are : \n ");
for(i=0; i<10; i++)
{
   printf("%d \t", a[i]);
}
getch();
}
/* End Of Main Program */


Output :

Please Enter 10 Numbers For An Array 'A' :
1  2  3  4  5  6  7  8  9  10

The Entered Numbers Are :
1  2  3  4  5  6  7  8  9  10




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 */ 




C Program For Conversion Of Decimal No Into Binary No.

This Post Contains A C Program For Conversion Of Decimal No Into Binary 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' 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 Binary No.

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

/* Start Of Main Program */
void main()
{
 
   /* Declaration Of Variables */
   int Num, i, j, k, a[20], b[20];
   clrscr();

   /* Asking For The Input From User */
   printf(" \n Enter Any No. : ");
   scanf("%d", &Num);
 
   /* Source Code For Conversion Of Decimal No Into Binary No */
   i = 0;
   while ( Num > 0 )
  {
     a[i] = Num % 2;
     i++;
     Num = Num / 2;
   }
   k = i - 1;
   printf("\n\n");
   for ( j = 0; j < i; j++ )
   {
     b[j] = a[k--];
     printf("%d", b[j]);
   }
   getch();
}
/* End Of Main Program */  





C Program For Conversion Of Binary No. Into Decimal No.

This Post Contains A C Program For Conversion Of Binary No. Into Decimal 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 'Arrays' & 'While-loop' 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 Binary No Into Decimal No.

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

/* Start Of Main Program */
void main()
{
 
   /* Declaration Of Variables */
   int p, q, r, b[20];
   long Num;
   clrscr();
 
   /* Asking For The Input From User */
   printf(" \n Enter Any Binary Number : ");
   scanf("%d", &Num);
 
   /* Source Code For Computing Conversion Of Binary Into Decimal */
   p = 0;
   while ( Num > 0 )
   {
     b[p++] = Num % 10;
     Num = Num / 10;
   }
   q = p - 1;
   r = 0;
   while ( q >= 0 )
   {
     r = r + ( b[q] * pow ( 2 , q ) );
     q--;
   }
   printf(" \n Decimal No. Of Given Binary No. Is : %d ", r);
   getch();
}
/* End Of Main Program */     




Subscribe To:

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

Blog Archive