Advertisement
Divyansh_Chourey

average to infinity

Mar 11th, 2024
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.29 KB | Source Code | 0 0
  1. #include<stdio.h>
  2. int main(){
  3.     int num, sum=0, count=0;
  4.     float avg;
  5.     printf("Enter the number: ");
  6.     scanf("%d", &num);
  7.     while(num!=-1){
  8.         count++;
  9.         sum+=num;
  10.         printf("Enter the number: ");
  11.         scanf("%d", &num);
  12.  
  13.     }
  14.     avg=(float)sum/count;
  15.     printf("Average: %.2f", avg);
  16.     return 0;
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement