1. ## Please help me (urgent)

The question is as follows:

Write a program to prompt the user to input five integers in the range [0,9] and then output the followings:

1. the numbers in ascending order.
2. the numbers that occur three times in the user input.
3. the numbers that occur twice in the user input.

Example: For the user input: 2 3 5 5 3,
1. the sorted order is: 2 3 3 5 5
2. no numbers occur three times
3. the numbers that occur twice are: 3 5

One possible idea:
Declare an array (size of 5) of integers named hand for storing the five user inputs.

Declare an array (size of 10) of integers named count for counting the number of occurrences of each possible value in the user input.

Example:
count becomes [0 0 1 2 0 2 0 0 0 0 ] for the user input: 2 3 5 5 3

Then print the sorted array using count.
Use the array count to check for values that occur twice or three times.

i have done the first question

but i have no idea with question 2 and 3

my program is as follows:

#include<stdio.h>

void main()

{
int hand,count={0,1,2,3,4,5,6,7,8,9},j,i=0,temp;
for (i=0;i<4;i++)
{
do {printf("Enter the num%d:",i);
scanf(" %d",&hand[i]);
} while (hand[i]<0 || hand[i]>9);
}

for(j=0;j<4;j++)

{

for(i=0;i<4;i++)

{

if(hand[i]>hand[i+1])

{

temp=hand[i];

hand[i]=hand[i+1];

hand[i+1]=temp;

}

}

}

printf("The sorted order is");

for(i=0;i<4;i++)

printf("%3d",hand[i]);
getch();

} 2. Declare an array (size of 10) of integers named count for counting the number of occurrences of each possible value in the user input.

Example:
count becomes [0 0 1 2 0 2 0 0 0 0 ] for the user input: 2 3 5 5 3

just declare an array ARRAY
then when ever you read a number in you say ARRAY[number-1]++

Then when you want to print out only numbers that are in twice you do a loop like this
Code:
```for(i = 0; i < 10; i++)
{
if(ARRAY[i] == 2)
printf("%d", i+1);
}```
you should use code tags when you post your code, they make it a lot easier to read 3. In your haste, you forgot to read the important things. Don't post as "urgent", and please use code tags.

>void main()
is wrong. Use
>int main(void)

If you know how to loop through the array, you know how to count... 4. Code:
```for(j=0;j<4;j++)
{
for(i=0;i<4;i++)
{
if(hand[i]>hand[i+1])
{
temp=hand[i];
hand[i]=hand[i+1];
hand[i+1]=temp;
}
}
}```
In the last for-loop run with i=3 hand[i+1] will cause trouble, because hand is out of bounds.
You've declared hand as an array of size 4. That means the array goes from index 0 to n-1 = 3, with n = 4. Popular pages Recent additions 