-1
# include <stdio.h>
# include <stdlib.h>

int main()
{
   int n, tg=0;
   printf("Enter the number of subjects : ");
   scanf("%d", &n);

   while (n>0)
   {
      int grade;
      printf("Enter the marks : ");
      scanf("%d", &grade);
      n--;
      tg+=grade;
   }
   float avg;
   avg = (tg/n);
   printf("\nYour Average Grade is %f\n", avg);
   return 0;
}

/* It is supposed to show the average grade but it is not displaying any result, but displays this instead "Process returned -1073741676 (0xC0000094) execution time: 6.532 s"

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335

1 Answers1

0

After the while loop

while (n>0)
{
   //...
   n--;
}

the variable n is equal tp 0. So this statement

 avg = (tg/n);

throws exception dividing by zero.

You could change the while loop for a for loop like for example

int n = 0;

//...

for ( int i = 0; i < n; i++ )
//..

and then after the loop

 avg = n > 0 ? ( float )tg/n : 0.0f;
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335