Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Standard C, C++

Reply
 
LinkBack Thread Tools Display Modes
Old 10-24-2006, 04: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
Old 10-24-2006, 09:26 AM   #2 (permalink)
toe_cutter
Code Monkey
 
Join Date: Aug 2002
Location: Boston, MA
Posts: 79
toe_cutter is on a distinguished road
Send a message via ICQ to toe_cutter Send a message via AIM to toe_cutter Send a message via Yahoo to toe_cutter
It is simple and well written. Even if there is another way I would suggest leaving it the way you have it. Nothing bothers me more then someone who tries to write clever code. Coding should not be clever, and I know some will disagree with me, but I have been maintaining way too many different projects in my career and clever code is difficult to figure out and maintain. I know of a few engineers I would love to meet (or you could say beat) in a dark alley one day.

On another subject, if you want change your code to make it more efficient I am all for that as long as it remains easily read and well documented. There are always trade offs in coding and I prefer easily read code first and formost.

Toe
__________________
toe_cutter is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
parse error problem in game.. can't seem to find problem solution. slashdot Standard C, C++ 5 08-03-2005 08:15 PM
JSP code problem j.gohel Java 7 04-15-2005 02:07 PM
Hashing problem jodders Standard C, C++ 1 02-09-2005 01:51 PM
Problem Assignment (Urgent help req.) Boltress Standard C, C++ 0 01-12-2005 07:59 AM
Help debugging a power problem Belisarius Lounge 0 10-25-2003 04:44 PM


All times are GMT -8. The time now is 08:02 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting