identify smallest integer and number of times it was entered [closed]
How can i write the code to identify the smallest integer i entered and how many times it appeared in the list i key in? Can somebody please help?
开发者_JAVA技巧#include<stdio.h>
#define constant-999
int main()
{
int num, count;
printf("Enter a list of integers (-999 to stop) : ");
while(scanf("%d", &num) != -999)
With a text editor.
Notepad++ is quite nice, but really anything will do.
I agree with Steven's comment but as a hint, since you need to count occurrences you'll need to iterate through the entire thing anyway.
A simple solution is to declare an array of numeric counts and using the number read as the index. You may have to offset the index if you deal with negative numbers:
unsigned int number_counts[1000] = {0};
//...
number_counts[num]++;
// or
number_counts[num + 500]++;
If you are using a linked list, add a count field and increment that.
精彩评论