C program that allows the user to input scores and will output a table of scores with the mean and standard deviation Sample Input Number of Students: 5 Input Score of Student 1: 5 Input Score of Student 2: 5 Input Score of Student 3: 5 Input Score of Student 4: 5 Input Score of Student 5: 5 5 5 5 5 5 Mean is 5 Sd is 0
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
C
Sample
Input Number of Students: 5
Input Score of Student 1: 5
Input Score of Student 2: 5
Input Score of Student 3: 5
Input Score of Student 4: 5
Input Score of Student 5: 5
5 |
5 |
5 |
5 |
5 |
Mean is 5
Sd is 0
PROGRAM STRUCTURE:
- Include the required header files.
- Start the definition of the main function.
- Declare the required number of variables.
- Take the number of students from the user.
- Take the marks of the students.
- Display the marks in the tabular form.
- Calculate the mean and standard deviation using the given formula.
- Display the result as mean and standard deviation.
PROGRAM CODE:
#include <stdio.h> // header file for standard input output
#include <math.h> // header file for maths related functions
void main() // main function definition
{
int x[100], n, average, variance, std_deviation, sum = 0, sum1 = 0; // variables
printf("Input Number of Students: ");
scanf("%d", &n); // take number of students
for (int i = 0; i < n; i++)
{
printf("Input Score of Student %d: ",i+1);
scanf("%d", &x[i]); // take score of the students
}
printf("\n _______\n");
for(int i=0; i<n; i++)
{
printf("|%d\t|",x[i]);
printf("\n _______\n"); // display the score in tabular form
}
for (int i = 0; i < n; i++)
{
sum = sum + x[i]; // calculates the sum
}
average = sum / n; // calculates the average
for (int i = 0; i < n; i++)
{
sum1 = sum1 + pow((x[i] - average), 2);
}
variance = sum1 / n;
std_deviation = sqrt(variance); // calculate the standard deviation
printf("\nMean is %d\n", average); // displays the results
printf("Sd is %d\n", std_deviation);
}
Step by step
Solved in 3 steps with 1 images