can anyone find an alternate solution to this problem


Read With Formatting | Free Open Source Tutorials Account

C and C++ Programming
Thread: can anyone find an alternate solution to this problem


neeven
i need to write a program that consider the marks scored by students. it

-should allow the user to enter the number of students.
-the user shall then enter the marks for each student.
thus if there are 10 students,the user will enter 10 marks.
the program must now calculate
1)the frequency for each mark
2)the interval which exists between identical marks
this is what i have done:-
i want to find another way of doing it

#include<stdio.h>
#define maxsize 200
int main()
{
int x,i,j;
int marks[maxsize];
int frequency[maxsize];
int interval[maxsize];

printf("Enter the number of Students: ");
scanf("%d",&x);
while(x<0)
{
printf("\nEnter a valid number of Student: ");
scanf("%d",&x);
}

for(i=0;i<x;i++)
{
printf("Enter the marks of student %d: ",i+1);
scanf("%d",&marks[i]);
while(marks[i]<0||marks[i]>100)
{
printf("\nMarks must be between 0 and 100");
printf("\nEnter the marks of student %d: ",i+1);
scanf("%d",&marks[i]);
}

}
printf("\n-------------------");
printf("\nresult:\n");
for(i=0;i<x;i++)
{
printf("\t%d",marks[i]);
}
for(i=0;i<x;i++)
{
frequency[i]=0;
for(j=0;j<x;j++)
{
if(marks[j]==marks[i])
{
frequency[i]+=1;
}
}

if(frequency[i]!=1)
{
interval[i]=0;
for(j=1;j<x;j++)
{
if(marks[i]!=marks[j])
{
interval[i]+=1;
}
}
if(interval[i]==1)
{
interval[i]=0;
}
}

}

for(i=0;i<x;i++)
{
printf("\nFrequency of number %d is %d",i+1,frequency[i]);
printf("\nInterval for number %d is %d",i+1,interval[i]);
}



}
return 0;