Computer Science, asked by churamansaw9508, 4 months ago

write a program using 'if- then' statement to print the count of student who scored more than 299 marks​

Answers

Answered by rahulerramuri
0

Answer:

Using C++

// using nested if-else  

#include<bits/stdc++.h>  

using namespace std;  

 

int main()  

{  

 

   // Store marks of all the subjects in an array  

   int marks[] = { 25, 65, 46, 98, 78, 65 };  

 

   // Max marks will be 100 * number of subjects  

   int len = sizeof(marks) / sizeof(marks[0]);  

   int max_marks = len * 100;  

 

   // Initialize student's total marks to 0  

   int total = 0;  

 

   // Initialize student's grade marks to F  

   char grade = 'F';  

 

   // Traverse though the marks array to find the sum.  

   for (int i = 0; i < len; i++)  

   {  

       total += marks[i];  

   }  

 

   // Calculate the percentage.  

   // Since all the marks are integer,  

   // typecast the calculation to double.  

   double percentage = ((double)(total) / max_marks) * 100;  

 

   // Nested if else  

   if (percentage >= 90)  

   {  

       grade = 'A';  

   }  

   else  

   {  

       if (percentage >= 80 && percentage <= 89)  

       {  

           grade = 'B';  

       }  

       else  

       {  

           if (percentage >= 60 && percentage <= 79)  

           {  

               grade = 'C';  

           }  

           else  

           {  

               if (percentage >= 33 && percentage <= 59)  

               {  

                   grade = 'D';  

               }  

               else  

               {  

                   grade = 'F';  

               }  

           }  

       }  

   }  

   cout << (grade) << endl;;  

}

Using JAVA:

class GFG {  

   public static void main(String args[])  

   {  

 

       // Store marks of all the subjects in an array  

       int marks[] = { 25, 65, 46, 98, 78, 65 };  

 

       // Max marks will be 100 * number of subjects  

       int max_marks = marks.length * 100;  

 

       // Initialize student's total marks to 0  

       int total = 0;  

 

       // Initialize student's grade marks to F  

       char grade = 'F';  

 

       // Traverse though the marks array to find the sum.  

       for (int i = 0; i < marks.length; i++) {  

           total += marks[i];  

       }  

 

       // Calculate the percentage.  

       // Since all the marks are integer,  

       // typecast the calculation to double.  

       double percentage  

           = ((double)(total) / max_marks) * 100;  

 

       // Nested if else  

       if (percentage >= 90) {  

           grade = 'A';  

       }  

       else {  

           if (percentage >= 80 && percentage <= 89) {  

               grade = 'B';  

           }  

           else {  

               if (percentage >= 60 && percentage <= 79) {  

                   grade = 'C';  

               }  

               else {  

                   if (percentage >= 33 && percentage <= 59) {  

                       grade = 'D';  

                   }  

                   else {  

                       grade = 'F';  

                   }  

               }  

           }  

       }

Using Python:

if __name__ == "__main__":  

 

   # Store marks of all the subjects  

   # in an array  

   marks = [25, 65, 46, 98, 78, 65 ]  

 

   # Max marks will be 100 * number  

   # of subjects  

   max_marks = len(marks)* 100

 

   # Initialize student's total  

   # marks to 0  

   total = 0

 

   # Initialize student's grade  

   # marks to F  

   grade = 'F'

 

   # Traverse though the marks array  

   # to find the sum.  

   for i in range(len(marks)):  

       total += marks[i]  

 

   # Calculate the percentage.  

   # Since all the marks are integer,  

   percentage = ((total) /max_marks) * 100

 

   # Nested if else  

   if (percentage >= 90):  

       grade = 'A'

         

   else :  

       if (percentage >= 80 and

           percentage <= 89) :  

           grade = 'B'

             

       else :  

           if (percentage >= 60 and  

               percentage <= 79) :  

               grade = 'C'

                 

           else :  

               if (percentage >= 33 and  

                   percentage <= 59) :  

                   grade = 'D'

                     

               else:  

                   grade = 'F'

         

   print(grade)  

Similar questions