C Language

May 31, 2023

How to use sum and average in c language

program to use sum and average in c language


#include<stdio.h>
int main()
{
    int i=1,n,sum=0;
    float avg;
    printf("Enter 10 positive numbers : \n");
    while(i<=10)
    {
        printf("Enter number %d : ",i);
        scanf("%d",&n);
        if(n<0)
        {
            printf("enter only positive numbers\n");
            continue;
        }
        sum+=n;
        i++;
    }
    avg=sum/10.0;
    printf("sum=%d avg=%f\n",sum,avg);
    return 0;
}

output


Enter 10 positive numbers : 
Enter number 1 : 2
Enter number 2 : 4
Enter number 3 : 5
Enter number 4 : 6
Enter number 5 : 9
Enter number 6 : 4
Enter number 7 : 3
Enter number 8 : 1
Enter number 9 : 8
Enter number 10 : 5
sum=47 avg=4.700000

by : Ajaj Khan

Quick Summary:

इस program मैं scanf के सहायता से enter 10 positiv numbers डाल रहे है जब 10 numbers ad हो जाए गा तो 10 numbers को जोड़ की उन का avg निकल रहा है