Example:11
Write a C program to Print all multiples of 7 up to 70 and print sum of all the nos?
Sol:
#include <stdio.h>
int main()
{
int i=7,s=0;
while(i<=70)
{
printf("%d\n",i);
s=s+i;
i=i+7;
}
printf("Sum = %d\n",s);
return 0;
}
Output:
7 14 21 28 35 42 49 56 63 70 Sum = 385
Example:12
Write a C program to to take input for 5 numbers calculate and print their sum?
Sol:
#include <stdio.h>
int main()
{
int i=1,n,s=0;
while(i<=5 )
{
printf("Enter any no ");
scanf("%d",&n);
s=s+n;
i=i+1;
}
printf("Sum = %d\n",s);
return 0;
}
Output:
Enter any no 2 Enter any no 3 Enter any no 6 Enter any no 5 Enter any no 4 Sum = 20
Example:13
Write a C program to take input for 3 numbers calculate and print their product?
Sol:
#include <stdio.h>
int main()
{
int i=1,n,p=1;
while(i<=3 )
{
printf("Enter any no ");
scanf("%d",&n);
p=p*n;
i=i+1;
}
printf("Prod = %d\n",p);
return 0;
}
Output:
Enter any no 2 Enter any no 3 Enter any no 5 Prod = 30
Example:14
Write a C program to take input for 5 nos , check and print total +ve elements entered by the user.
Sol:
#include <stdio.h>
int main()
{
int i=1,n,p=0;
while(i<=5)
{
printf("Enter any no ");
scanf("%d",&n);
if(n>0)
p++;
i=i+1;
}
printf("Total +ve elements = %d\n",p);
return 0;
}
Output:
Enter any no 25 Enter any no -96 Enter any no 35 Enter any no -85 Enter any no 4 Total +ve elements = 3
Example:15
Write a C program to take input for 5 nos , check and print total -ve elements entered by the user.
Sol:
#include <stdio.h>
int main()
{
int i=1,n,p=0;
while(i<=5)
{
printf("Enter any no ");
scanf("%d",&n);
if(n<0)
p++;
i=i+1;
}
printf("Total -ve elements = %d\n",p);
return 0;
}
Output:
Enter any no 25 Enter any no -5 Enter any no 2 Enter any no -6 Enter any no -7 Total -ve elements = 3




