a) Write a C program that reads marks of 10 students in to a single subscripted array. b) Above marks should be between 0 to 20. Modify the above program to add marks to the array only if the input mark is between the given range. c) Display the values stored in the array
#include <stdio.h>
int main()
{
int marks[10];
int temp=0;
int low=0;
int hight=0;
for(unsigned int i=0; i<sizeof(marks)/sizeof(int); i++)
marks[i]=-1;
scanf("%i %i",&low,&hight);
for(unsigned int i=0; i<sizeof(marks)/sizeof(int); i++) {
scanf("%i",&temp);
if (temp>=low && temp<=hight && temp>=0 && temp<=20) //b part.
marks[i]=temp;
}
for(unsigned int i=0; i<sizeof(marks)/sizeof(int); i++) //c part.
if(marks[i]!=-1) printf("out:%i\n",marks[i]);
return 0;
}
Comments
Leave a comment