0% found this document useful (0 votes)
9 views1 page

C Program for Sum and Average Calculation

This C program calculates the sum and average of a user-defined number of integers. It prompts the user to input the number of integers, reads them into an array, computes the sum, and then calculates the average. Finally, it prints the sum and average to the console.

Uploaded by

mimahim1209
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

C Program for Sum and Average Calculation

This C program calculates the sum and average of a user-defined number of integers. It prompts the user to input the number of integers, reads them into an array, computes the sum, and then calculates the average. Finally, it prints the sum and average to the console.

Uploaded by

mimahim1209
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include<stdio.

h>

int main() {
int i, N;
int sum;
float avg;
printf("How many numbers: ");
scanf("%d", &N);
int a[N];
printf("Enter the numbers: ");
for ( i = 0; i < N; i++) {
scanf("%d", &a[i]);
}
sum = 0;
for ( i = 0; i < N; i++) {
sum = sum + a[i];
}
avg = sum/ (float)N;
printf("Sum: %d\n", sum);
printf("Avg: %f\n", avg);
return 0;
}

You might also like