Write in C language Description You have 2 tables, courses and scores. courses consists 3 columns, sid, student_id, and course_id. scores consists 2 columns,sid and score. Please find that how many students failed on at least one course. Input First line consists 2 integers m and n, shows number of rows in courses and scores. Followed m lines are records of courses. student_id are 8-digits numbers begin with non-zero digit. sid and scores are positive integers smaller than 1000. Followed n lines are records of scores. sid are positive integers smaller than 1000. score are integers in range [0, 100]. Output

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter3: Performing Calculations With Formulas And Functions
Section: Chapter Questions
Problem 3.9CP
icon
Related questions
Question

Write in C language

Description

You have 2 tables, courses and scorescourses consists 3 columns, sidstudent_id, and course_idscores consists 2 columns,sid and score. Please find that how many students failed on at least one course.

Input

First line consists 2 integers m and n, shows number of rows in courses and scores.

Followed m lines are records of coursesstudent_id are 8-digits numbers begin with non-zero digit. sid and scores are positive integers smaller than 1000.

Followed n lines are records of scoressid are positive integers smaller than 1000. score are integers in range [0, 100].

Output

Student will be flunked when his/her average score in the course less than 60. Output is 2 integers shows number of student and student failed on at lease one course.

Sample Input 1 

2 4
1 10800001 5
2 10800002 5
1 90
1 29
2 65
2 60

Sample Output 1

2 1

Expert Answer (Sample Input and Output need to be the same as the input and output nothing else)

 
Step 1

There are 2 tables, courses and scores. The courses consists of 3 columns, sidstudent_id, and course_id whereas scores consists 2 columns, sid and score.

The ask is to find out the total number of students and the number of students who have failed in atleast one course.

Step 2

The scores table contains multiple scores of a student for a course. So, we would need to find out the average score obtained in a given course for a student.

So, we would need to start with defining 2-D arrays to store the courses and scores details.

#include<stdio.h>
int main(){
   /* 2D array declaration*/
   int m=0;
   int n=0;
   printf("Enter value for m:");
   scanf("%d",&m);
   printf("Enter value for m:");
   scanf("%d",&n);
   int course[m][3];
   /*Counter variables for the loop*/
   int i, j;
   for(i=0; i<m; i++) {
      for(j=0;j<3;j++) {
         printf("Enter value for course[%d][%d]:", i, j);
         scanf("%d", &course[i][j]);
      }
   }
    int score[n][2];
   /*Counter variables for the loop*/
   
   for(i=0; i<n; i++) {
      for(j=0;j<3;j++) {
         printf("Enter value for score[%d][%d]:", i, j);
         scanf("%d", &score[i][j]);
      }
   }

 int prevSid=0, prevScore=0, noOfOccurence=0, noOfFailedStudents=0;
 for(i=0;i<n; i++) {
  
  sid = score[i][0];
  if(prevSid==sid) {
   totalScore=prevScore+score[i][1];
   prevSid=sid; noOfOccurence++;
  } else {
   if(totalScore/noOfOccurence<60) {
    noOfFailedStudents++;
   }
   prevSid=0; prevScore=0;
  }
 }

 printf("Output: ");
 printf("%d", m);
  printf("%d", noOfFailedStudents);
   return 0;
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Computing Algorithms
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage