i was jus wondering if u can help me on diz program,, im hav difficulty in findin d mode i hav done everytin jus that d mode iz not coming up. thanx aspa. below is d code i greated so far


/* created by Nokiolurv */

#include <stdio.h>
#include<stdlib.h>


int Array[100];
void getValue();
int Counter = 0;
int getLarge();
int getMode();
int getSmall();
int Value = 0;

main(){

int i;
for(i=0; i< 100; i++){
Array= 0;

}

/************** This print out the largest, Smallest and Median Value*********/
getValue();
printf("The largestNumber is:%d\n",getLarge());
printf("The SmallestNumber is:%d\n",getSmall());
printf("The Mode is:%d\n", getMode());
//printf("And it has occurred %d times\n",);

}

void getValue(){

char garbage [80];
int temp = -1;
int Count = 0;
int i;
/********This gets values from the user*********/

while (Value != -42){
printf("Please Enter An Integer 1 - 100 or 0 to terminate program\n");
scanf("%d", &Value);
Array[Value]++;
Counter++;
printf("Input = %d\n", Value);
gets(garbage);


/*********to Prints out error messages when the user input wrong Vualues********/

while( Count != 0|| garbage [0]!='\0'){
printf("Invalid input. Please Try again: ");
scanf ("%d", &Value);
gets(garbage);
}

}
}

int getLarge(){
int Value =0;
int i;

for(i=100;i>0;i--){ // declares the array to start at the end
if(Array!=0){ // search for the non zero
Value=(i);
return Value;
break;
}
}

}
int getSmall(){
int Value = 0;
int i; // start at the begining of the array
for(i=0;i<100;i++){
if(Array!=0){
Value=(i);
break;
}
}
return Value;
}

/******************** to calculates the mode vaule of the input ******/


int getMode(){
int Array2[100];
int Counter;
int Value = 0;
int mode = 0;
int i;
int highest = 0;

//int Array = new int[large];

for (i = 0; i < 100; i++)
Array2 = 0;

for (i = 0; i < 100; i++)
{
i = Array2;
Array2++;
break;
}

for (i = 0; i < 100; i++)
{
if (Array2 >Counter)
{
Counter = Array2;
mode = i;
break;
}
return Value;
}
}

Recommended Answers

All 4 Replies

You're not going to get much help with the amount of effort put in to presenting your question. Learn to type properly and use code-tags.

was just wondering if anyone can help me on this program, im haven difficulty in finding the mode, i have done everything just that i cant seems to find the way on how to find the mode. thanx aspa. above is the code i created so far

thanks William Hemsworth

1) sort the data
2) count frequency of each data
3) find max number of frequency
4) return that number or index to that number

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.