Showing posts with label while. Show all posts
Showing posts with label while. Show all posts

Monday, 8 October 2012

Loop control structure071

Write a program to determine G.C.D. of two input number. 

#include <stdio.h>
#include <conio.h>
void main ( )
{                              
        int         n1, n2, d;
        clrscr ( );
                                      
        printf("\n\n\n\t\t Enter a number..:");    scanf("%d",&n1);
        printf("\n\n\t\t Enter a number..:");    scanf("%d",&n2);
                             
        while ( n2 != 0 )
        {                               
                       d = n1 % n2;
                       n1 = n2;
                       n2 = d;
        }
              
        printf("\n\n\n\t\t G.C.D = %d",n1);
        getch();
}
Click here to contact us 

Thursday, 6 September 2012

Loop control structure070

Input a number and check whether the number is palindrome or not.
N.B.: A number is said to be palindrome when its reverse number is equal to the original number. e.g. 121.

#include <stdio.h>
#include <conio.h>
void main ( )
{
           int       n, d, m, s = 0;
           clrscr ( );
           printf("\n\n\t\t\t Enter a number..:"); scanf("%d",&n);
                                         
           m = n;
           while ( n > 0)
           {                          
                         d = n % 10;
                         n = n / 10;
                         s = s * 10 + d;
           }                
                   
           if ( s == m )
           {                               
                         printf("\n\n\n\t\t\t The number is palindrome.");
           }                                       
           else              
           {                                                  
                         printf("\n\n\n\t\t\t The number is not palindrome.");
           }
           getch ( );
}
Click here to contact us 

Loop control structure069

Write a program to print Fibonacci Series up to 'n', 'n' will be input by user.
N.B. : - 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233

#include <stdio.h>
#include <conio.h>
void main ( )
{
            int       p = 1, c = 1, f, n;
            clrscr ( );
            printf("\n\t\t\t Enter a number..:"); scanf("%d",&n);
           
            printf("\n\n\n\t The Fibonacci Series: - ");
            printf(" %d %d",p, c);
            f = p + c;
                                
            while ( f <= n )
            {                               
                           printf(" %d",f);
                           p = c;
                           c = f;
                           f = p + c;
            }
            getch ( );
}
Click here to contact us 

Friday, 31 August 2012

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

Thursday, 9 August 2012

Loop control structure018


Write a program to display 1   2    3    5    8 .............nth term.

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

void main ( )
{
        int        n, n1 = 1, n2 = 2, n3 =0, c = 1;
        clrscr ( );
                     
        printf ("\n\t Enter a number (less than 21).......:"); scanf ("%d", &n);
        printf (" %d    %d",n1, n2);
                 
        do                   
        {              
                      n3 = n1 + n2;
                      printf ("\t %d", n3);
                      n1 = n2;
                      n2 = n3;
                      c ++;
        } while (c <= n );
        
        getch ( );
}

Loop control structure017


Write a program to print out all Armstrong numbers between 1 and 500. For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 ).
N.B. [ Armstrong Numbers : - 1, 153, 370, 371, 407. ]

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

void main ( )
{
        int           no = 1, no1, md, s;
        clrscr ( );
                          
        printf ("\n\t ARMSTRONG NUMBER FROM 1 TO 500 \n\n");
                    
        while ( no <= 500 )
        {                        
                       no1 = no;
                       s = 0;
                       while ( no1 > 0 )
                       {                    
                                        md = no1 % 10;
                                        no1 = no1 / 10;
                                        s = s + ( md * md * md );
                       }                                  
                       if ( no == s)
                                   printf ("\t %d", no);
                       no ++;
        }
        getch ( );
}

Click here to contact us

Wednesday, 8 August 2012

Loop control structure016


Input a number and determin that is an Armstrong number or not. For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 ).
N.B. [ Armstrong Numbers : - 1, 153, 370, 371, 407. ]  

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

void main ( )
{
        int         no, no1, md, s = 0;
        clrscr ( );
               
        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);
        getch ( );
}

Loop control structure015


Write a program to print all the ASCII values and there equivalent charecters using a while loop. The ASCII values vary from 0 to 255.

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

void main ( )
{
        int           co = 0;
        clrscr ( );
                         
        while ( co <= 255 )
        {                       
                        printf ("\n\t %3d -----> %c \n", co, co);
                        if ( co != 0 )
                        {                    
                                   if ( co % 21 == 0)
                                   {                         
                                                     printf ("\n\t Press any key to continue");
                                                     getch ( );
                                                     clrscr ( );
                                   }
                        }
                        co ++;
        }
        getch ( );
}

Loop control structure014


Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another.

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

void main ( )
{
int m, n, co = 1;
long pow = 1;
  clrscr ( );
                    
printf ("\n\t Enter a number for base value .........:"); scanf ("%d",&m);
  printf ("\n\t Enter a number for power value .......:"); scanf ("%d",&n);
               
  while ( co <= n )  
  {                     
  pow = pow * m;
  co ++;
  }
   
  printf ("\n\t %d to the power %d is %ld", m, n, pow);
  getch ( );
}

Click here to contact us

Tuesday, 7 August 2012

Loop control structure013


Write a program to calculate overtime pay of ten empoloyes. Overtime is paid at the rate of Rs. 12.00 per hour for every hour worked above 40 hours. Assume that employees do not work for fractional part of an hour.

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

void main ( )
{
        float       otpay;
        int          hour, i = 1;
        clrscr ( );
              
        while ( i <=10 )              /* Loop for ten employees */
        {                   
                printf ("\n\n\t Enter number of hours worked ......:"); scanf ("%d",&hour);
                if ( hour >= 40 )
                {                            
                             otpay = (hour - 40 ) * 12;
                             printf ("\n\t Number of hours worked = %d \n\t Overtime pay = %f",hour, otpay);
                }                          
                else                     
                {                             
                             otpay = 0;
                             printf ("\n\t Number of hours worked (%d) is less than 40 hours \n\t Hence no 
                                                no overtime pay", hour);
                }
                i ++;
        }
        getch ( );
}

Loop control structure012


If a four digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of that number.

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

void main ( )
{
        int       md, no, co = 1, s = 0;
        clrscr ( );
             
        printf ("\n\t Enter a four digit number ......:"); scanf ("%d",&no);
                 
        while ( no > 0 )
{                   
                       md = no % 10;
                       no = no / 10;
                       if ( co == 1)
                                   s = s + md;
                       co ++;
        }
        s = s + md;
        printf ("\n\t SUM = %d",s);
        getch ( );
}

Loop control structure011


If a five digit number is input through the keyboard, write a program to calculate the sum of its digits.

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

void main ( )
{
        int        md, no, s = 0;
        clrscr ( );
                 
        printf ("\n\t Enter a five digit number (less than 32767)......:"); scanf ("%d",&no);
             
        while ( no > 0 )
        {                     
                       md = no % 10;
                       no = no / 10;
                       s = s + md;
        }         
        printf ("\n\t SUM = %d",s);
        getch ( );
}

Click here to contact us

Loop control structure010


If a five digit number is input through the keyboard, write a program to reverse that number.

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

void main ( )
{
  int          md, no;
           clrscr ( );
           
           printf ("\n\t Enter a five digit number (less than 32767)......:"); scanf ("%d",&no);
           printf ("\n\t Reverse number.....:");
           while ( no > 0 )
  {                   
  md = no % 10;
  no = no /10;
  printf ("%d",md);
  }
  getch ( );
}

Loop control structure009


Input three numbers and find the product of these number.

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

void main ( )
{
        int            co = 1, no, pro = 1;
        clrscr ( );
          
        while ( co <= 3 )
        {                          
                       printf ("\n\t Enter a number.....:"); scanf ("%d",&no);
                       pro = pro * no;
                       co ++;
        }                       
        printf ("\n\t PRODUCT = %d", pro);
        getch ( );
}

Monday, 6 August 2012

Loop control structure008


Input five number and find the sum and average.

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


void main ( )
{
        int           co = 1, no, avg, s = 0;
        clrscr ( );
         
        while ( co <= 5 )
        {                     
                       printf ("\n\t Enter a number.....:"); scanf ("%d",&no);
                       s = s + no;
                       co ++;
        }
        avg = s / 5;
        printf ("\n\t SUM = %d", s);
        printf ("\n\t AVARAGE = %d", avg);
        getch ( );
}

Loop control structure007


Write a program to print a factorial table. 

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


void main ( )
{
long          num = 1, fact = 1;
clrscr ( );


printf ("\n\t\t   FACTORIAL TABLE\n\n");
printf ("\n\t      NUMBER \t\t FACTORIAL");
printf ("\n\t ==================================");


while ( num <= 10 )
{
fact = fact * num;
printf ("\n\t\t %ld \t\t %ld",num, fact);
num ++;
}
printf ("\n\t ===================================");
getch ( );
}

Loop control structure006


Write a program to find the factorial value of an input number.

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


void main ( )
{
        int          no, co = 1, fact = 1;
        clrscr ( );
                   
        printf ("\n\t Enter the number.......:"); scanf ("%d",&no);
               
        while ( co <= no )
        {                                                     
                       fact = fact * co;
                       co ++;
        }
        printf ("\n\t FACTORIAL = %d", fact);
        getch ( );
}

Loop control structure005


Write a program to print a multyplication table of an input number.

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


void main ( )
{
        long              no, co = 1, ans;
        clrscr ( );
 
        printf ("\n\t Enter the number.......:"); scanf ("%ld",&no);
        clrscr ( );
        printf ("\n\t MULTYPPLICATION TABLE OF %ld", no);
        printf ("\n\t ==========================");
          
        while ( co <= 15 )
        {                           
                       ans = no * co;
                       printf ("\n\t %ld \t X \t%ld = \t%ld\n",no, co, ans);
                       co ++;
        }
        printf ("\n\t ==========================");
        getch ( );


Loop control structure004


Write a program to print all the even number between one to ten (intrger) along with the sum.

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


void main ( )
{
        int          a = 2, s = 0;
        clrscr ( );

        while ( a <= 10 )
        {                   
                     printf ("\n\n %d ",a);
                     s = s + a;
                     a = a + 2;
        }
        printf ("\n\n SUM OF EVEN NUMBERS = %d",s);
        getch ( );


Related Posts Plugin for WordPress, Blogger...