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=25;
while(i>=1)
{
printf("%d\n",i);
i=i-2;
}
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=1,s=0;
while(i<=10)
{
printf("%d\n",i);
s=s+i;
i=i+1;
}
printf("Sum = %d",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=2,s=0;
while(i<=30)
{
printf("%d\n",i);
s=s+i;
i=i+2;
}
printf("Sum = %d",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=1,s=0;
while(i<=35)
{
printf("%d\n",i);
s=s+i;
i=i+2;
}
printf("Sum = %d",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=5,s=0;
while(i<=100)
{
printf("%d\n",i);
s=s+i;
i=i+5;
}
printf("Sum = %d",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




