Prime vs Composite Number

I want help about this problem;

input a number: 6
the output will be
1 >> PRIME
2 >> PRIME
3 >> PRIME
4 >> COMPOSITE
5 >> PRIME
6 >> COMPOSITE

my code is this:

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


int main()
{
int x,i,y,temp;
int cnt = 0;
printf("Input a number: ");
scanf("%d",&x);


for(i = x; i > 0; i--)
{
printf("%d", i);
temp = x % i;


if (temp==0)
cnt++;

printf(" ->> %s\n", ((temp) == 0)? "Prime":"Composite" );
}

system("pause");
return 0;
}


what is the problem of my code??help me..please
Can you give more details of your assignment? Are you supposed to be identifying prime numbers in [1,x]? Or are you supposed to be printing whether or not each digit is evenly divisible into x (considering the cnt variable's apparent intent)?

BTW, your for statement should look like this
for (i = 1; i <= x; i++)

Also, 1 is not prime.

Hope this helps.
when input a number, all number will be place and it will be determine whether it is prime or composite. 0
Just like this: when i input 7, the output will be:
input a number: 7
the output will be

Input Number: 7

1 >> PRIME
2 >> PRIME
3 >> PRIME
4 >> COMPOSITE
5 >> PRIME
6 >> COMPOSITE
7 >> PRIME
Press any key to continue..

help me.
help me.


Missing something?

No one is going to help you on your homework. What does the compiler say? Why are you using printf to output to command line not cout?
What you'll prerequisitely need is an understanding of the algorithm to determine whether a number is prime or not, or else i cannot see you doing this piece of homework.

Then you check each number to see if it is prime. If it is not prime, then it's got to be composite!

I posted a piece of code to your post of the "largest prime number"...you'll get the algorithm of determining whether a number is prime or not there.

Good luck.
Thanks arun.
thanks for the help guys. I have solve this problem. thanks very much.
Topic archived. No new replies allowed.