SEARCH C# PROGRAMMING CODES HERE

 Array

How to declare Array in C
int num[35];  /* An integer array of 35 elements */
char ch[10];  /* An array of characters for 10 elements */
Similarly, an array can be of any data type such as double, float, short and more.
So lets find out the average of 4 integers
*********************************************************
#include <stdio.h>
int main()
{
    int avg = 0;
    int sum =0;
    int x=0;
    int num[4];
    for (x=0; x<4;x++)
    {
        printf("Enter the number=%d \n", (x+1));
        scanf("%d", &num[x]);
    }
    for (x=0; x<4;x++)
    {

        sum = sum+num[x];
    }

    avg = sum/4;
    printf("Average =: %d", avg);
    return 0;
}
******************************************************
Output:
Enter the number= 1
10
Enter the number= 2
10
Enter the number= 3
20
Enter the number= 4
40
Average = 20

No comments:

Post a Comment