0

Hello everyone! How do you guys write a program that will prompt the user input scores and will output the average? (C language)

15th Sep 2023, 4:02 AM
Pentett
2 ответов
+ 4
Please share your attempt firstly, this is not a platform to give you a readymade code.
15th Sep 2023, 4:07 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
0
Im sorry, here's my attempt: #include <stdio.h> int main() { int numScores; double score, total = 0.0; printf("Enter the number of scores: "); scanf("%d", &numScores); if (numScores <= 0) { printf("Please enter a valid number of scores.\n"); return 1; } for (int i = 1; i <= numScores; i++) { printf("Enter score #%d: ", i); scanf("%lf", &score); total += score; } double average = total / numScores; printf("The average score is: %.2lf\n", average); return 0; }
15th Sep 2023, 4:15 AM
Pentett