Tuesday, December 30, 2014

While looping pro in c



Program 1

#include
#include
void main()
{
int i=1;
clrscr();
          while(i<=10)
          {
          printf("%d",i);
          i=i+1;
          }
getch();
}

Output
          
        1,2,3,4,5,6,7,8,9,10

Program 2

#include
#include
void main()
{
char name[25];
int i=1;
clrscr();
          printf("Enter any name\n");
          scanf("%s",name);
          while(i<=10)
          {
          printf("%d. Hai Ragul %s\n",I,name);
          i=i+1;
          }
getch();
}

Output
         
         Enter any name
          Raja
1.     Hai Raja
2.     Hai Raja
3.     Hai Raja
4.     Hai Raja
5.     Hai Raja
6.     Hai Raja
7.     Hai Raja
8.     Hai Raja
9.     Hai Raja
10.            Hai Raja

Program 3

#include
#include
void main()
{
int i,n,m,total=0;
float avg;
clrscr();
          printf("Enter how many numbers\n");
          scanf("%d",&n);
          i=1;
          while(i<=n)
          {
          printf("\n Enter mark     : %d). ",i);
          scanf("%d",&m);
          total = total+m;
          avg=total/n;
          i=i+1;
          }
          printf("\n Sum of given numbers      : %d",total);
          printf("\n Average                                      : %f",avg);
getch();
}

Output
       
           Enter how many numbers
          3
          Enter mark: 1). 50
          Enter mark:  2). 50
          Enter mark:  3). 50
          Sum of given numbers   : 150
          Average                         : 50

No comments:

Post a Comment