Thursday, January 1, 2015

loop(4)

1:
#include <stdio.h>
#include <stdlib.h>
///***terminating program:
int main()
{
int a;
while(scanf("%d",&a)&& a!=0){
    printf("%d\n",a);
}
return 0;
}

output:the program will terminate when you will input zero:

2:
#include <stdio.h>
///***summation:

int main()
{
 int a,sum,range;
 printf("please enter a number:",range);
 scanf("%d",&range);
 sum=0;
for(a=1;a<=range;a++)
      sum+=a;
 printf("\nthe sum of 1 to %d is %d\n",range,sum);
 return 0;
}



input: 6
output: 21

3:
#include <stdio.h>
///***print multiply number:

int main()
{
int a,b,sum;
a=5;
for(b=1;b<=5;b++){
sum=a*b;
printf(" %d ",sum);
}
return 0;
}




 output: 5 10 15 20 25

No comments:

Post a Comment