Showing posts with label Loop Control Structure. Show all posts
Showing posts with label Loop Control Structure. Show all posts

Friday, May 11, 2012

Program to check that entered no is divisible by 5 or not.


//program to check that entered no is divisible by 5 or not.
#include<stdio.h>
#include<conio.h>
main()
{ int n,r,s,i;
 printf("Enter the no ");
 scanf("%d",&n);
 s=0;
for(i=0;i<1;i++)
 { r=n%10;
  n=n/10;
 }
 if(r==0||r==5)
 printf("Entered no is divisible by 5");
 else
 printf("Entered no is Not divisible by 5");
getch();
}

Program to count number of digits in a number.


// program to count number of digits in a number.
#include<stdio.h>
#include<conio.h>
main()
{
     int  num,count=0;
  printf("Enter a number: ");
  scanf("%d",&num);
   while(num)
  {
      num=num/10;
      count++;
  }
  printf("Total digits is:  %d",count);
getch();
}

Program to check that entered no is divisible by 9 or not.


//program to check that entered no is divisible by 9 or not.
#include<stdio.h>
#include<conio.h>
main()
{ int n,r,s;
 printf("Enter the no ");
 scanf("%d",&n);
 s=0;
 while(r!=0)
 { r=n%10;
  n=n/10;
  s=s+r;
 }
 if(s%9==0)
 printf("Entered no is divisible by 9");
 else
 printf("Entered no is Not divisible by 9");
getch();
}

Program to check that entered no is divisible by 10 or not.


//program to check that entered no is divisible by 10 or not.
#include<stdio.h>
#include<conio.h>
main()
{ int n,r,s,i;
 printf("Enter the no ");
 scanf("%d",&n);
 s=0;
for(i=0;i<1;i++)
 { r=n%10;
  n=n/10;
 }
 if(r==0)
 printf("Entered no is divisible by 10");
 else
 printf("Entered no is Not divisible by 10");
getch();
}

Thursday, May 3, 2012

Program to check that entered no is divisible by 3 or not.


//program to check that entered no is divisible by 3 or not.
#include<stdio.h>
#include<conio.h>
main()
{ int n,r,s;
 printf("Enter the no ");
 scanf("%d",&n);
 s=0;
 while(r!=0)
 { r=n%10;
  n=n/10;
  s=s+r;
 }
 if(s%3==0)
 printf("Entered no is divisible by 3");
 else
 printf("Not divisible by 3");
getch();
}

Saturday, March 17, 2012

Program to Print fibonacci series.

// The fibonacci series.
#include<stdio.h>
#include<conio.h>
main()
{
      int i,n,f,s,t;
      printf("How many element you want to print:");
      scanf("%d",&n);
      f=0;
      s=1;
      printf("The  fibonacci series up to %d is : %d,%d",n,f,s);
      for(i=0;i<n-2;i++)
      {                
       t=f+s;
       f=s;
       s=t;
       printf(",%d",t);
       }
       getch();
       }
      
     

Saturday, March 10, 2012

Program to print the pyramid of no.

//Program to print the  pyramid of no.
              1
          1  2  3 
       1 2  3  4  5
    1 2 3  4  5  6  7
#include<stdio.h>
#include<conio.h>
main()
{
      int x,y,i,g;
      y=1;
      for(x=3;x>=0;x--)
      {
      for(i=1;i<=x;i++)
       {printf("   ");
       }g=1;
       for(i=0;i<y;i++)
       {printf(" %d",g);g++;
       }
      
       y=y+2;
       printf("\n\n");
       }
       getch();
       }

Program to Print the pyramid.

//Program to Print the pyramid.
       *
     ***
   *****
 *******
#include<stdio.h>
#include<conio.h>
main()
{
      int x,y,i;
      y=1;
      for(x=3;x>=0;x--)
      {
      for(i=1;i<=x;i++)
       {printf(" ");
       }
       for(i=0;i<y;i++)
       {printf("*");
       }
      
       y=y+2;
       printf("\n\n");
       }
       getch();
       }

Program to Print the pyramid.

//Program to Print the pyramid.
             *
         ***
     *****
 *******

#include<stdio.h>
#include<conio.h>
main()
{
      int x,y,i;
      y=1;
      for(x=3;x>=0;x--)
      {
       for(i=1;i<=x;i++)
       {printf("  ");
       }
       for(i=1;i<=y;i++)
       {printf("*");
       }
       y=y+2;
       printf("\n");
       }
       getch();
       }

Program to print the reverse pyramid of no.

//Program to print the reverse pyramid of no.
1 2 3 4 5 6 7 8 9

  1 2 3 4 5 6 7

    1 2 3 4 5

       1 2 3

          1
#include<stdio.h>
#include<conio.h>
main()
{
      int x,y,i,g;
      y=9;
      for(x=4;x>=0;x--)
      {
      for(i=4;i>x;i--)
       {printf(" ");
       }g=1;
       for(i=0;i<y;i++)
       {printf("%d",g);g++;
       }
      
       y=y-2;
       printf("\n");
       }
       getch();
       }

Program to Print the pyramid.

//Print the pyramid like..
*********
  *******
   *****
     ***
       *
#include<stdio.h>
#include<conio.h>
main()
{
      int x,y,i;
      y=9;
      for(x=4;x>=0;x--)
      {
      for(i=4;i>x;i--)
       {printf(" ");
       }
       for(i=0;i<y;i++)
       {printf("*");
       }
      
       y=y-2;
       printf("\n");
       }
       getch();
       }

Program to check entered character is special symbol or not.

//Program to check entered character is special symbol or not.
#include<stdio.h>
#include<conio.h>
main()
{ int i;
char c;
printf("Enter character");
scanf("%c",&c);
i=c;
if((c>=0&&c<=47)||(c>=58&&c<=64))
printf("You entered a special character ");
else
printf("Not special character");
getch();
}

Friday, March 9, 2012

Program to print the triangle of no.

// Program to calculate the triangle of no.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
#include<stdio.h>
#include<conio.h>
main()
{
       int x,i;
       for(x=1;x<=5;x++)
       {
          for(i=1;i<=x;i++)
         {
                          printf("  %d",i);
          }
                          printf("\n\n");
       }
 getch();
   }

Program to Print the triangle of star.

// Program to calculate the triangle of star.





*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
#include<conio.h>
main()
{
       int x,i;
       for(x=1;x<=5;x++)
       {
        for(i=1;i<=x;i++)
        {
                          printf("  *");
                          }
                          printf("\n\n");
                          }
                          getch();
                          }

Thursday, March 8, 2012

Entered no is Armstrong no or not.

//Entered no is Armstrong no or not.
#include<stdio.h>
#include<conio.h>
main()
{ int d,r,n,s;
 printf("Enter no:");
 scanf("%d",&n);
 d=n;
 s=0;
do
 {
  r=d%10;
  d=d/10;
  s=s+(r*r*r);
 }while(d!=0);
 if(s==n)
 printf("Armstrong no");
 else
 printf("Not Armstrong no");
getch();
}

Program to reverse the entered no .

//Program to reverse the entered no .
#include<stdio.h>
#include<conio.h>
main()
{ int d,r,n;
 printf("Enter no:");
 scanf("%d",&n);
 d=n;
do
 {
  r=d%10;
  printf("%d",r);
  d=d/10;

}while(d!=0);
getch();
}

Program to find factorial of any no.

//Program to find factorial of any no.
#include<stdio.h>
#include<conio.h>
main()
{
      int i,fact,n;
      printf("Enter the no:");
      scanf("%d",&n);
      fact=1;
      for(i=1;i<=n;i++)
      { 
        fact=fact*i;
        }
        printf("The factorial of %d no is :- %d",n,fact);
        getch();
 }

Program to print first n natural no and their sum

//Program to print first n natural no and their sum.
#include<stdio.h>
#include<conio.h>
main()
{
      int i,sum,n;
      printf("How many natural no?");
      scanf("%d",&n);
      sum=0;
      for(i=1;i<=n;i++)
      {  printf("%d\n",i);
         sum=sum+i;
      }
      printf("The sum of first %d natural no is :-%d",i,sum);
      getch();
      }

Show all odd numbers from 0 to your entered no.

//Show all odd numbers from o to your entered no.
#include<stdio.h>
#include<conio.h>
main()
{ int i,n;
  printf("Enter any no-");
  scanf("%d",&n);
  printf("Odd no is-");
  for(i=1;i<=n;i=i+2)
  {
     printf("%d\n",i);
 
     }
     getch();
     }
    

Count backwards of any no.

//Count backwards of any no using a for loop.
#include<stdio.h>
#include<conio.h>
main()
{ int i,n;
 printf("Enter any no-");
 scanf("%d",&n);
 printf("backwards of no--");
 for(i=n;i>=0;i--)
 { printf("%d\n",i);
}
getch();
}