21. Write a C program to find the sum and average of different numbers which are accepted by user as many as user wants
#include<stdio.h>
#include<conio.h>
void main()
{
int a,c[100],i;
float avg,sum=0;
printf("How many numbers do you want to enter: ");
scanf("%d",&a);
printf("Enter the Numbers:\n");
for(i=0;i<a;i++)
{
scanf("%d",&c[i]);
}
for(i=0;i<a;i++)
{
sum=sum+c[i];
}
avg=sum/a;
printf("Sum is %f\n Avg is %f",sum,avg);
}
#OUTPUT:
#include<conio.h>
void main()
{
int a,c[100],i;
float avg,sum=0;
printf("How many numbers do you want to enter: ");
scanf("%d",&a);
printf("Enter the Numbers:\n");
for(i=0;i<a;i++)
{
scanf("%d",&c[i]);
}
for(i=0;i<a;i++)
{
sum=sum+c[i];
}
avg=sum/a;
printf("Sum is %f\n Avg is %f",sum,avg);
}
#OUTPUT:
Comments
Post a Comment