Answer to Question #250174 in C for Hazzy

Question #250174

Exercise 1: Practice to store and print data in an array

a) Write a C program that reads marks of 10 students into a single subscripted array.

b) Above marks should be between 0 to 20. Modify the above program to add marks to the array only if the input mark is between the given range.

c) Display the values stored in the array.

Exercise 2: Practice accessing data stored in an array

Modify the above program to find the mean of the marks stored in the array.


1
Expert's answer
2021-10-13T00:29:55-0400
#include <stdio.h>
int main()
{
    int arr[10]; 
    int n;
    printf("\nEnter elements of the array:\n");
    for (int i = 0; i < 10; i++) { 
        scanf("%d",&n);
        while (n < 0 || n > 20) { 
             printf("Range is 0 to 20. Re-enter.");
             scanf("%d",&n);
        } 
        arr[i] = n; 
    } 
    printf("\nElements of the array\n");
    for (int i = 0; i < 10; i++) {
        printf("%d\t",arr[i]);
    }
    int sum=0;
    for (int i = 0; i < 10; i++) {
        sum+=arr[i];
    }
    float mean=sum/10.0;
    printf("\nMean= %f",mean);
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS