Example:6
Write a C program to print alll odd numbers from upto 25 in reverse order
Sol:
#include <stdio.h> int main() { int i; for(i=25;i>=1;i=i-2) { printf("%d\n",i); } return 0; }
Output:
25 23 21 19 17 15 13 11 9 7 5 3 1
Example: 7
Write a C program to print numbers from 1 to 10 and also print sum of all the numbers?
Sol:
#include <stdio.h> int main() { int i,s=0; for(i=1;i<=10;i=i+1 ) { printf("%d\n",i); s=s+i; } printf("Sum = %d\n",s); return 0; }
Output:
1 2 3 4 5 6 7 8 9 10 Sum = 55
Example: 8
Write a C program to print all even numbers from 30 and also print sum of all the numbers?
Sol:
#include <stdio.h> int main() { int i,s=0; for(i=2;i<=30;i=i+2) { printf("%d\n",i); s=s+i; } printf("Sum = %d\n",s); return 0; }
Output:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 Sum = 240
Example:9
Write a C program to Print all odd numbers up to 35 and print sum of all the nos?
Sol:
#include <stdio.h> int main() { int i,s=0; for(i=1;i<=35;i=i+2) { printf("%d\n",i); s=s+i; } printf("Sum = %d\n",s); return 0; }
Output:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 Sum = 324
Example:10
Write a C program to Print all multiples of 5 upto 100 and print sum of all the nos?
Sol:
#include <stdio.h> int main() { int i,s=0; for(i=5;i<=100;i=i+5) { printf("%d\n",i); s=s+i; } printf("Sum = %d\n",s); return 0; }
Output:
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 Sum = 1050