Commit 88ae0f88 by msiita

lab2

parent 2966c5f6
File added
#include <stdio.h>
int main()
{
int array[10];
int i=0;
int n=0.0000;
float sum=0.0000;
float average;
printf("Enter the amonut of numbers you want averaged. Max 10 numbers. \n");
scanf("%d", &n);
if (n > 10){
printf("Too many numbers!! Max 10 numbers. Enter a new amount\n");
scanf("%d", &n);
if (n > 10){
printf("You didn't give me an acceptable amount of numbers. Game over\n");
return 0;
}
if (n < 10){
for(i=0; i<n; i=i+1)
{
printf("Enter a number: ");
scanf("%d", &array[i]);
sum+=array[i];
}
}
}else{
for(i=0; i<n; i=i+1)
{
printf("Enter a number: ");
scanf("%d", &array[i]);
sum+=array[i];
}
}
average=sum/n;
printf("Average= %f", average);
return 0;
}
File added
#include <stdio.h>
int main()
{
int marks[10], i, n, sum = 0, average;
printf("Enter n: ");
scanf("%d", &n);
for(i=0; i<n; ++i)
{
printf("Enter number%d: ",i+1);
scanf("%d", &marks[i]);
sum += marks[i];
}
average = sum/n;
printf("Average = %d", average);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment