//keep taking number as input from user until user enters a number which is multiple of 5. #include<stdio.h> int main() { int n; do{ printf("enter any number="); scanf("%d", &n); printf("%d\n", n); if(n % 5 == 0){ break; } } while(1); printf("you have entered multiple of 5 "); return 0; } output : enter any number=1 1 enter any number=2 2 enter any number=4 4 enter any number=5 5 you have entered multiple of 5 -------------------------------- Process exited after 5.066 seconds with return value 0 Press any key to continue . .
//program to print the numbers from 0 to n, if n is given by user. #include<stdio.h> int main() { int i=0; int n; printf("enter any number :\n"); scanf("%d", &n); while(i <= n){ printf("%d\n", i); i++; } return 0; } Output : enter any number : 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -------------------------------- Process exited after 5.739 seconds with return value 0 Press any key to continue . . .
//program to print the average of 3 numbers. #include<stdio.h> #include<math.h> int main() { int a,b,c; printf("enter three numbers"); scanf("%d%d%d", &a,&b,&c); printf("Average of three numbers =%d",(a+b+c)/3); //Average = sum of numbers / total number of values. return 0; } Output : enter three numbers 9 8 7 Average of three numbers =8 -------------------------------- Process exited after 7.005 seconds with return value 0 Press any key to continue . . .
Comments
Post a Comment
Please do not enter any spam link in the comment box.