DO NOT MISS

Ads

Showing posts with label C-Programs Using While Loop. Show all posts
Showing posts with label C-Programs Using While Loop. Show all posts

Tuesday, 2 August 2016

Program 20 Using While loop



Reverse of the given no. is equal to the given no. is known as a Palindrome no.

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

void main()

    {

            int rev=0,r,n,t=0;
            clrscr();

            printf("enter a number:");
            scanf("%d",&n);

            t=n;
           
while(n!=0)
                 {
                      r=n%10;
                      rev=rev*10+r;
                      n=n/10;
                 }

            if(rev==t)
            printf("palindrome");
            else
            printf("not palindrome");

            getch();

   }


Output:-

______________________________________________________
______________________________________________________
______________________________________________________
_____________________________________________________




Program 19 Using While loop



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

void main() 

     { 

            int rev=0,r,n; 
            clrscr(); 

            printf("enter a number:"); 
            scanf("%d",&n); 

            while(n!=0) 

                  { 
                          r=n%10; 
                          rev=rev*10+r; 
                          n=n/10; 
                  } 

                          printf("the revers of the no. is:=%d\n",rev); 

            getch(); 

     }

Output:-

______________________________________________________
______________________________________________________
______________________________________________________
_____________________________________________________




Sunday, 31 July 2016

Program 18 Using While Loop



The sum of the digits of the qubes is equal to the given number is known as a Armstrong number.


Example:- (153,371,407)


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

void main() 

      { 

           int n,sum=0,r,t=0; 
           clrscr(); 

           printf("enter a number:"); 
           scanf("%d",&n); 

           t=n; 
           while(n!=0) 
                 { 
                      r=n%10; 
                      sum=sum+r*r*r; 
                      n=n/10; 
                 } 


           if(sum==t) 
           printf("the no is armstrang"); 
           else 
           printf("the no is not armstrang"); 

           getch(); 

      }


Output:-



Explanation:
______________________________________________________
______________________________________________________
______________________________________________________
_____________________________________________________



Program 17 Using While Loop


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

void main()

     {

           int n,sum=0,r;
           clrscr();

           printf("enter a number:");
           scanf("%d",&n);

     
     while(n!=0)
                    {
                          r=n%10;
                          sum=sum+r;
                          n=n/10;
                     }

            printf("the sum of the digits of the given no. is:=%d",sum);

            getch();

       }

Output:-


Explanation:
enter the number:34=3 + 4 =7
enter the number:59=5 + 9=14

______________________________________________________
______________________________________________________
______________________________________________________
_____________________________________________________

Program 16 Using While loop


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

void main()

       {

            int a,i,sum=0;
            clrscr();

            printf("enter a range:");
            scanf("%d",&a);

            i=1;
           
while(i<=a)
                     {
                          sum=sum+i*i*i;
                          i++;
                     }

            printf("the sum of the Qube natural no is:=%d\n",sum);

            getch();

      }

Output:-

Explanation:-
The Number is :3 (1 + 2 + 3 )
Qube of (1*1*1+2*2*2+3*3*3) = 1 + 8 + 27  =36.
______________________________________________________
______________________________________________________
______________________________________________________

_____________________________________________________



Program 15 Using While loop


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

void main()

       {

             int a,i,sum=0;
             clrscr();

             printf("enter a range:");
             scanf("%d",&a);

             i=1;
           
 while(i<=a)
                         {
                                sum=sum+i*i;
                                i++;
                         }

             printf("the sum of the Squre natural no is:=%d\n",sum);

             getch();

        }

Output:-


Explanation:-
The Number is :4 (1 + 2 + 3 + 4)
 Square of (1*1+2*2+3*3+4*4) = 1 + 4 + 9 + 16 =30.
______________________________________________________
______________________________________________________
______________________________________________________
_____________________________________________________



Program 14 Using While loop


The positive numbers 1, 2, 3, 4... are known as natural numbers. The programs below takes a positive integer as an input from the user and calculates the sum up to n.

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

void main()

       {

               int a,i,sum=0;
               clrscr();

               printf("enter a range:");
               scanf("%d",&a);

               i=1;
             
 while(i<=a)

                    {

                       sum=sum+i;
                       i++;

                    }

              printf("the sum of the natural no is:=%d\n",sum);

              getch();

       }


Output:-


Explanation:
enter the number:3=1+2+3 =6
enter the number:5=1+2+3+4+5=15
______________________________________________________
______________________________________________________
______________________________________________________
_____________________________________________________

Program 13 Using While loop



The sum of the factors of the given no. is equal to the twice of the given no. then the number is called Perfect no.

Ex:- 
Number 6 is Perfect Number
Number 6 Factors =1,2,3,6
1*6=6
2*3=6
3*2=6
6*1=6
1+2+3+6=12 (6+6)


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

void main() 

       { 

              int n,i,sum=0; 
              clrscr(); 

              printf("enter a number:"); 
              scanf("%d",&n); 

              i=1; 
              while(i<=n)

                       { 

                            if(n%i==0) 
                            sum=sum+i; 
                            i++; 

                       } 

             if(sum==n*2) 
             printf("the number is perfect number\n"); 
             else 
             printf("the number is not perfect number"); 

             getch(); 

     }


Output:-

______________________________________________________
______________________________________________________
______________________________________________________
_____________________________________________________




Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims