View Single Post
Old 10-24-2006, 05:47 AM   #1 (permalink)
neeven
Recruit
 
Join Date: Oct 2006
Posts: 7
neeven is on a distinguished road
can anyone give me another way of solving this problem?

i need to write a program that- allow the user to enter the number of students-allow the user to enter each mark-calculate the frequency for each mark-the interval that exists between identical marks
this is what i have done
i want to know if there is a different way of doing it
Code:
#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;
neeven is offline   Reply With Quote