Sunday 28 February 2016

Example of Array

Q. Write a C program to read the internal test marks of 25 students in a class and show the number of students who have scored more than 50% in the test.

Ans.

/*We assume that maximum marks in internal test is 500. */ 
#include<stdio.h>
#include<conio.h>
#define SIZE 5
int main()
{
 int arr[SIZE];
 int i,j,max=0,min=0;
 for(i=1; i<=SIZE; i++)
 {
   printf("Enter %d student marks : ",i);
   scanf("%d",&arr[i]);
 }
 for(i=1; i<=SIZE; i++)
 {
  if(arr[i]/5 > 50)
  {
    max++;
    printf("\nMarks which scored more than 50%% is %d",arr[i]);
  }
  else
  {
    min++;
    printf("\nMarks which scored less than 50%% is %d",arr[i]);
  }
 } 
 printf("\n");
 printf("\nTotal number of students who scored more  than 50%% = %d",max);
 printf("\nTotal number of students who scored less than 50%% = %d",min);
 getch();
 return 0;

}


Output of the above program :

Enter 1 student marks : 450Enter 2 student marks : 152Enter 3 student marks : 266Enter 4 student marks : 65Enter 5 student marks : 123Marks which scored more than 50% is 450Marks which scored less than 50% is 152Marks which scored more than 50% is 266Marks which scored less than 50% is 65Marks which scored less than 50% is 123Total number of students who scored more than 50% =  2 Total number of students who scored less than 50% =  3 


No comments:

Post a Comment

Ads Inside Post