Friday 31 August 2012

Array013

Input five numbers in two different arrays and print common elements of these arrays.

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

void main ( )
{           
            int           n[5], n1[5], n2[5], a, b, c = 0;
            clrscr ( );
                                                 
            for ( a = 0; a < 5; a++ )
            {                                                 
                             printf ("\n\t\t Enter a number in 1st array......:"); scanf ("%d", & n[a]);
            }                                                                      
            for ( a = 0; a < 5; a++ )
            {                                             
                             printf ("\n\t\t Enter a number in 2nd array......:"); scanf ("%d", & n1[a]);
            }                        
                                                               
            for ( a = 0; a < 5; a++ )
            {                                                     
                             for ( b = 0; b < 5; b++ )
                             {                                                        
                                              if ( n[a] == n1[b] )
                                              {                   
                                                             n2[c++] = n[a];
                                              }                                     
                             }
            }                                                     
                                                                         
            printf ("\n\n\t\t Common elements are\n\n\t\t");
            for ( a = 0; a < c; a++ )
                             printf (" %d", n2[a]);
            getch ( );
}

Click here to contact us

Array012

Input an amount in rupees  and calculate the currency.

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

void main ( )
{               
              int           no, q, c = 0;
              int           d[ ] = { 500, 100, 50, 20, 10, 5, 2, 1 };
              clrscr ( );
                                                     
              printf ("\n\t\t Enter an amount......: Rs."); scanf ("%d", & no);
              while ( no > 0 )
              {                             
                                q = no / d[c];
                                no = no % d[c];
                                if ( q != 0 )
                                           printf ("\n\n\t\t %3d X %3d = %5d", d[c], q, q*d[c]);
                                c++;
              }
              getch ( );
}


Click here to contact us

Array011

Input a decimal number  and print the octal equivalent of that number.

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

void main ( )
{
             int       md[10], no, s = 0, d =0;
             clrscr ( );
                                       
             printf ("\n\t\t Enter a decimal number......:"); scanf ("%d", & no);
             while ( no > 0 )
             {                                  
                               md[s] = no % 8;
                               no = no / 8;
                               s++;
             }
                                                     
             printf ("\n\n\n\t\t The Octal number =  ");
             for ( d = s - 1; d >= 0; d-- )
                               printf ("%d", md[d]);
             getch ( );
}

Click here to contact us

Loop control structure068

Input a octal number  and print the decimal equivalent of that number.

#include <stdio.h>
#include <conio.h>
#include <math.h>
void main ( )
{
          int          md, no, s = 0, d =0;
          clrscr ( );
                                   
          printf ("\n\t\t Enter a octal number......:"); scanf ("%d", & no);
          while ( no > 0 )
          {                                        
                            md = no % 10;
                            no = no / 10;
                            md = md * pow ( 8,d );
                            s = s + md;
                            d++;
          }
                                              
          printf ("\n\n\n\t\t The Decimal number =  %d", s);
          getch ( );
}

Click here to contact us

Thursday 30 August 2012

Loop control structure067

Input a binary number  and print the decimal equivalent of that number.

#include <stdio.h>
#include <conio.h>
#include <math.h>
void main ( )
{
             int          md, no, s = 0, d =0;
             clrscr ( );
                                      
             printf ("\n\t\t Enter a binary number......:"); scanf ("%d", & no);
             while ( no > 0 )
             {                                    
                               md = no % 10;
                               no = no / 10;
                               md = md * pow ( 2,d );
                               s = s + md;
                               d++;
             }
                              
             printf ("\n\n\n\t\t The Decimal number =  %d", s);
             getch ( );
}


Click here to contact us

Array010

Input a number ( less than 32767 ) and print the binary equivalent of that number.

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

void main ( )
{
               int          md[10], no, c = 0, d =0;
               clrscr ( );
                                      
               printf ("\n\t\t Enter a number......:"); scanf ("%d", & no);
               while ( no > 0 )
               {                             
                                 md[c] = no % 2;
                                 no = no / 2;
                                 c++;
               }
                                
               printf ("\n\n\n\t\t The Binary numbers = ");
               for ( d = c - 1; d >= 0; d-- )
               {                                                                                  
                                 printf ("%d ", md[d]);
               }
               getch ( );
}

Click here to contact us

Array009

Input a five digit number ( less than 32767 ) and store all the digits of that number in an array.

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

void main ( )
{
            int         md[6], no, c = 0, d =0;
            clrscr ( );
                                        
            printf ("\n\t\t Enter a number......:"); scanf ("%d", & no);
            while ( no > 0 )
            {                             
                              md[c] = no % 10;
                              no = no / 10;
                              c++;
            }                          
                                   
            printf ("\n\n\n\t\t The digits are = ");
            for ( d = c - 1; d >= 0; d-- )
            {                                        
                              printf ("%d ", md[d]);
            }
            getch ( );
}


Click here to contact us

Wednesday 29 August 2012

Array008

Input five numbers in an array and find the second highest value.

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

void main ( )
{
          int         n[5], i, h = 0, h1 = 0;
          clrscr ( );
                                     
          for ( i = 0; i < 5; i++ )
          {                        
                          printf ("\n\t\t Enter a number in an array......:"); scanf ("%d", & n[i]);
                                    
                          if ( n[i] > h )
                                       h = n[i];   
          }                                 
          for ( i = 0; i < 5; i++ )
          {                                              
                          if ( n[i] > h1 && n[i] < h )
                                        h1 = n[i];
          }   
          printf ("\n\n\n\t\t The highest number is = %d", h);
          printf ("\n\n\n\t\t The  second highest number is = %d", h1);
          
          getch ( );
}

Click here to contact us

Tuesday 28 August 2012

Array007

Input five numbers in an array and print the square root of them.

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

void main ( )
{
          float        n[5], n1[5], i;
          clrscr ( );
                                     
          for ( i = 0; i < 5; i++ )
          {                                     
                          printf ("\n\t\t Enter a number in an array......:"); scanf ("%f", & n[i]);
                                                              
                          n1[i] = sqrt (n[i]);
          }                                                       
                                                           
          printf ("\n\n\n\t\t\t   The Square root of Array\n");
          for ( i = 0; i < 5; i++ )
          {                                                              
                          printf ("\n\t\t\t\t %.2f\t = %.2f", n[i], n1[i]);
          }
          getch ( );
}

Click here to contact us

Array006

Input five numbers in an array and print the square of them. 

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

void main ( )
{
              int          n[5], n1[5], i;
              clrscr ( );
                                         
              for ( i = 0; i < 5; i++ )
              {                                       
                              printf ("\n\t\t Enter a number in an array......:"); scanf ("%d", & n[i]);
                                            
                              n1[i] = n[i] * n[i];
              }
                                                                       
              printf ("\n\n\n\t\t\t   The Square of Array\n");
              for ( i = 0; i < 5; i++ )
              {                                            
                              printf ("\n\t\t\t\t %d = %d", n[i], n1[i]);
              }
              getch ( );
}

Click here to contact us

Array005

Input five numbers in two different array and print the sum of them.

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

void main ( )
{
            int           n[5], n1[5], n2[5], i;
            clrscr ( );
                           
            for ( i = 0; i < 5; i++ )
            {                       
                            printf ("\n\t\t Enter a number in first array......:"); scanf ("%d", & n[i]);
            }                        
            for ( i = 0; i < 5; i++ )
            {                                             
                            printf ("\n\t\t\ Enter a number in second array......:"); scanf ("%d", & n1[i]);
            }
                                      
            printf ("\n\n\n\t\t\t     The Sum of Array\n");
            for ( i = 0; i < 5; i++ )
            {                                                 
                            n2[i] = n[i] + n1[i];
                            printf ("\n\t\t\t\t %d + %d = %d", n[i], n1[i], n2[i]);
            }
            getch ( );
}

Click here to contact us

Monday 27 August 2012

Array004

Input five numbers in an array. If these are even numbers then one will be store in the array or if these are odd numbers then zero will be store in the array.

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

void main ( )
{
          int         n[5], n1[5], i;
          clrscr ( );
                                      
          for ( i = 0; i < 5; i++ )
          {                                        
                          printf ("\n\t\t\t Enter a number......:"); scanf ("%d", & n[i]);
                                                     
                          if ( n[i] % 2 == 0 )
                                            n1[i] = 1;
                          else                           
                                            n1[i] = 0;
          }                                                  
          printf ("\n\n");
          for ( i = 0; i < 5; i++ )
          {                                            
                          printf ("\n\t\t\t\t %d \t %d", n[i], n1[i]);
          }
          getch ( );
}
Click here to contact us

Array003

Input ten numbers in an array and if these are positive numbers then store it in first array or if these are negative numbers then store it in second array.

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

void main ( )
{
            int         i, j = 0, k = 0, num[10], ne[10], po[10];
            clrscr ( );
                                         
            printf ("\n\t\t Sorting of positive and negative numbers\n\n");
            for ( i = 0; i < 10; i++ )
            {                                           
                            printf ("\n\t\t\t Enter a number......:"); scanf ("%d", & num[i]);
                                             
                            if ( num[i] > 0 )
                                           po[ j++] = num[i];
                            else                               
                                           ne[ k++] = num[i];
            }
                                             
            printf ("\n\n\t Positive numbers =");
            for ( i = 0; i < j; i++ )
            {                                             
                            printf (" %d", po[i]);
            }                                              
            printf ("\n\n\t Negative numbers = ");
            for ( i = 0; i < k; i++ )
            {                                                
                            printf (" %d", ne[i]);
            }
            getch ( );
}


Click here to contact us

Array002

Input five numbers in an array and transfer these numbers in reverse order to a different array.

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

void main ( )
{
            int        no1[5], no2[5], i, j = 4;
            clrscr ( );
                                   
            printf ("\n\t Number transfer from one array to another array\n\n");
                                            
            for ( i = 0; i <= 4; i++ )
            {                                                     
                            printf ("\n\t\t\t Enter a number......:"); scanf ("%d", & no1[i]);
                                                       
                            no2[ j--] = no1[i];
            }                                               
            for ( i = 0; i <= 4; i++ )
            {                                                        
                            printf ("\n\t Number in 1st array : - %d \t Number in 2nd array : - %d",
                                               no1[i], no2[i]);
            }
            getch ( );   
}



Click here to contact us

Array001

Input five number in an array and transfer these number in a different array.

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

void main ( )
{
            int           no1[5], no2[5], i;
            clrscr ( );
                                             
            printf ("\n\t Number transfer from one array to another array\n\n");
                                                       
            for ( i = 0; i <= 4; i++ )
            {                                                   
                            printf ("\n\t\t\t Enter a number......:"); scanf ("%d", & no1[i]);
                                          
                            no2[i] = no1[i];
            }                                         
            for ( i = 0; i <= 4; i++ )
            {                                                 
                            printf ("\n\t Number in 1st array : - %d \t Number in 2nd array : - %d", no1[i],
                                          no2[i]);
            }
            getch ( );   
}


Clink here to contact us

Sunday 26 August 2012

Case structure005

Create a menu driven program.

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

void main ( )
{
             int          cho, no, no1, co, md, fl, s;
             unsigned long    fact;
             clrscr ( );
                                                 
             while ( 1 )
             {                                                    
                      printf ("\n\t\t\tMENU");
                      printf ("\n\t\t\t====");
                      printf ("\n\n\t\t   1. FACTORIAL\n");
                      printf ("\t\t   2. PRIME \n");
                      printf ("\t\t   3. ARMSTRONG \n");
                      printf ("\t\t   4. ODD / EVEN \n");
                      printf ("\t\t   5. EXIT \n");
                                                                           
                      printf ("\n\t\t   Your Choice ?"); scanf ("%d", &cho);
                                                                                       
                      switch ( cho )
                      {                                           
                                 case 1:
                                               fact = 1;
                                               printf ("\n\t Enter the number.......:"); scanf ("%d",&no);
                                                                                                    
                                               for ( co =1; co <= no; co++ )
                                               {                                             
                                                                 fact = fact * co;
                                               }
                                               printf ("\n\t FACTORIAL = %ld", fact);
                                               break;
                                                                
                                 case 2:                    
                                               fl = 0;
                                               printf ("\n\t Enter a number...........:"); scanf ("%d", &no);
                                                                                                                    
                                               for ( co = 2; co < no; co++ )
                                               {                                                        
                                                                  md = no % co;
                                                                  if ( md == 0 )
                                                                  {                                                    
                                                                                fl = 1;
                                                                                break;
                                                                  }
                                               }
                                               if ( fl == 0 )
                                                         printf ("\n\t It is a Prime number");
                                               else                              
                                                         printf ("\n\t It is not a Prime number");
                                               break;
                                                         
                                 case 3:                                
                                               s = 0;
                                               printf ("\n\t Enter a number.........:"); scanf ("%d",&no);
                                               no1 = no;
                                                                                                      
                                               while ( no > 0 )
                                               {                                                      
                                                                 md = no % 10;
                                                                 no = no /10;
                                                                 s = s + ( md * md * md );
                                               }                                                         
                                               if ( no1 == s )
                                                             printf ("\n\t Number = %d is an Armstrong number", no1);
                                               else           
                                                             printf ("\n\t Number = %d is not an Armstrong number",
                                                                              no1);
                                               break;
                                                                      
                                 case 4:      
                                               printf ("\n\t Enter a number.........:"); scanf ("%d",&no);
                                                                            
                                               if ( no % 2 == 0 )
                                                                  printf ("\n\t Even number");
                                               else                                                    
                                                                  printf ("\n\t Odd number");
                                               break;
                                                             
                                 case 5:    
                                               exit ( );
                                                             
                                 default:           
                                               printf("\n WRONG CHOICE.");
                      }
                      getch ( );
                      clrscr ( );
             }

}



Click here to contact us

Saturday 25 August 2012

Loop control structure066

Write a program to construct this figure.
                                              9
                                            8 8
                                          7 7  7
                                        6 6  6  6 
                                     5  5  5  5  5
                                   4  4  4  4  4  4
                                 3  3  3  3  3  3  3
                               2  2  2  2  2  2  2  2
                             1  1  1  1  1  1  1  1  1


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

void main ( )
{
       int         i, j, k, l = 35;
       clrscr ( );

       printf ("\n\t\t\t    Design of Numbers\n\n\n");

       for ( i = 9; i >= 1; i-- )
       {
                for ( j = 0; j < l; j++ )
                {
                         printf(" ");
                }
                for ( k = 1; k <= 10 - i; k++ )
                {
                         printf ("%d ", i);
                }
                printf ( "\n" );
                l--;
           }
           getch( );
}



Click here to contact us 
Related Posts Plugin for WordPress, Blogger...