Need help in writing a C program using array and loop statement

Write a C program using arrays and any loop statements that asks the user to enter the number of students. For each student, enter the number of courses. The user should enter the students ID number and the marks for each course. Compute and display the total and average of the students marks.
Sample Output:
Enter the number of students: 2
Enter Student ID No. 1: 082367
Enter student name: Amal
Enter the number of courses: 2
Enter the mark for course 1: 80
Enter the mark for course 2: 80
Total marks = 160
Average = 80
Enter Student ID No. 2: 12345
Enter the number of courses: 3
Enter mark for course 1 : 80
Enter mark for course 2 : 90
Enter mark for course 3 : 85
Total Marks = 255
Average = 85

Questions by Abdul Hamid

Showing Answers 1 - 2 of 2 Answers

sree

  • Jul 4th, 2012
 

/*Write a C program using arrays and any loop statements that asks the user to enter the number of students. For each student, enter the number of courses. The user should enter the students ID number and the marks for each course. Compute and display the total and average of the students marks. Sample Output: Enter the number of students: 2 Enter Student ID No. 1: 082367 Enter student name: Amal Enter the number of courses: 2 Enter the mark for course 1: 80 Enter the mark for course 2: 80 Total marks = 160 Average = 80 Enter Student ID No. 2: 12345 Enter the number of courses: 3 Enter mark for course 1 : 80 Enter mark for course 2 : 90 Enter mark for course 3 : 85 Total Marks = 255 Average = 85*/


This code is executed using linux OS...

Code
  1. #include<stdio.h>

  2. int main()

  3. {

  4.         int stud[10],stud_id,total,avg;

  5.         int mark,num_of_studs,nu_of_course,i,j;

  6.         printf("Enter number of students

  7. ");

  8.         scanf("%d",&num_of_studs);

  9.         for(i=0;i<num_of_studs;i++)

  10.         {

  11.                 total=0;

  12.                 avg=0;

  13.                 printf("ENter Student Id num:");

  14.                 scanf("%d",&stud_id);

  15.                 printf("

  16. Enter the number of courses:");

  17.                 scanf("%d",&nu_of_course);

  18.                 for(j=0;j<nu_of_course;j++)

  19.                 {

  20.                         printf("

  21. Enter the mark for course%d :",j+1);

  22.                         scanf("%d",&mark);

  23.                         total=total+mark;

  24.                 }

  25.                 avg=total/nu_of_course;

  26.                 printf("==================================================

  27. ");

  28.                 printf("

  29. Student id:%d",stud_id);

  30.                 printf("

  31. Total marks: %d",total);

  32.                 printf("

  33. Average:%d

  34. ",avg);

  35.                 printf("==================================================

  36. ");

  37.                

  38.         }

  39.  

  40. }

  Was this answer useful?  Yes

memo

  • Oct 16th, 2012
 

use the structure to write this program

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions