Example of Array to find out the average of 4 integers

#include <stdio.h> int main() { int avg = 0, sum = 0, x = 0; /* Array- declaration – length 4*/ int num[4]; /*int arr[] = {1, 2, 3, 4, 5}; int arr[5] = {1, 2, 3, 4, 5}; */ /* We are using a for loop to traverse through the array * while storing the entered values in the array */ for (x=0; x<4;x++) { printf("Enter number %d \n", (x+1)); scanf("%d", &num[x]); } for (x=0; x<4;x++) { sum = sum+num[x]; } avg = sum/4; printf("Average of entered number is: %d", avg); return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.