اكتب برنامج بلغة سي شارب c# لحساب المتوسط الحسابي
- برمجة
- برمجة سي شارب
- 2022-01-22
- esmaaeelaljrf758183302
الأجوبة
using System;
class HelloWorld {
static void Main() {
int total, // sum of grades
gradeCounter, // number of grades entered
gradeValue; // grade value
double average; // average of all grades
// initialization phase
total = 0; // clear total
gradeCounter = 0; // prepare to loop
// processing phase
// prompt for input and convert to integer
Console.Write("Enter Integer Grade, -1 to Quit: ");
gradeValue = Int32.Parse(Console.ReadLine());
// loop until a -1 is entered by user
while (gradeValue != -1)
{
// add gradeValue to total
total = total + gradeValue;
// add 1 to gradeCounter
gradeCounter = gradeCounter + 1;
// prompt for input and read grade from user
// convert grade from string to integer
Console.Write("Enter Integer Grade, -1 to Quit: ");
gradeValue = Int32.Parse(Console.ReadLine());
} // end while
// termination phase
if (gradeCounter != 0)
{
average = (double)total / gradeCounter;
// display average of exam grades
Console.WriteLine("\nClass average is "+ average);
}
else
{
Console.WriteLine("No grades were entered.");
}
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
معلومات ذات صلة