the lesson is about using arrays
1) Write a program that will take N positive numbers
from the user and print the average of the numbers.
The input can be terminated by entering a negative
number. You can assume N<1000
the code i have, thus far (not working):
Code:
#include <stdio.h>
#include <string.h>
int main(int argv, char** argc){
int n, i;
float sum = 0.0, average;
char num[1000];
for (i = 0; i < 1000; ++i)
{
printf("%d. Enter number: ", i + 1);
scanf("%f", &n, &num[i]);
if (n < 0)
{
break;
}
}
sum += num[i];
average = sum / strlen(num);
printf("Average = %.2f", average);
return 0;
}