Output:

C Codes:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main() | |
{ | |
int i, x; | |
float y, sum = 0.0; | |
printf("Enter the Sample Size: "); | |
scanf("%d", &x); | |
printf("Enter the Data: "); | |
for(i = 1; i <= x; ++i){ | |
scanf("%f", &y); | |
sum += y; | |
} | |
float mean = sum/x; | |
printf("Mean: %2.2f\n", mean); | |
return 0; | |
} |
C++ Codes:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> // Library for input/output | |
#include<iomanip> // Library for precision | |
using namespace std; | |
int main() | |
{ | |
int i, x; | |
float y, sum = 0.0; | |
cout << "Enter the Sample Size: "; | |
cin >> x; | |
cout << "Enter the Data: "; | |
for(i = 1; i <= x; ++i){ | |
cin >> y; | |
sum += y; | |
} | |
float mean = sum/x; | |
cout << "Mean: " << setprecision(4) << mean << endl; | |
return 0; | |
} |