AbdulFathaah

average using function

Nov 13th, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. /* average using a function */
  2. #include<conio.h>
  3. #include<stdio.h>
  4. void main()
  5. {
  6. float avg(float[]);
  7. float a[5]={12.5,11.5,13.5,15.2,20.5};
  8. float average;
  9. clrscr();
  10. average=avg(a);
  11. printf("Average of 5 numbers is %f",average);
  12. getch();
  13. }
  14. float avg(float a[5])
  15. {
  16. int i;
  17. float sum=0;
  18. for(i=0;i<5;i++)
  19. {
  20. sum=sum+a[i];
  21. }
  22. return (sum/5);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment