اكتب برنامج C لحساب متوسط علامات الرياضيات لبعض الطلاب. أدخل 0 أو قيمة سالبة لإنهاء عملية الإدخال

  • برمجة
  • برمجة سي c

اكتب برنامج C لحساب متوسط علامات الرياضيات لبعض الطلاب. أدخل 0 أو قيمة سالبة لإنهاء عملية الإدخال

مثال عن الخرج المتوقع :

Input Mathematics marks (0 to terminate): 10
15
20
25
0
Average marks in Mathematics: 17.50

الأجوبة

/*Write a C program to calculate the average marks of mathematics of some students. Input 0 (excluding to calculate the average) or negative value to terminate the input process*/

#include <stdio.h>
int main() 
{
	int marks[99], m, i, a=0, total=0;
	float f;
	printf("Input Mathematics marks (0 to terminate): ");
	for(i = 0; ; i++) 
	{
		scanf("%d", &marks[i]);
		if(marks[i] <= 0) {
		break;
		}
		a++;
		total += marks[i];
	}
	f = (float)total/(float)a;
	printf("Average marks in Mathematics: %.2f\n", f);
	return 0;
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...