开发者

identify smallest integer and number of times it was entered [closed]

开发者 https://www.devze.com 2023-01-07 20:56 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消