15,388,688 members
See more:
```Write a C program to read any integer from user and compute the reverse of given number. Also output
whether the reverse number is prime or not. Sample Input/Output:
Enter any integer: 4521
Reverse number is: 1254. It is not a prime number.```

What I have tried:

```#include<stdio.h>

int main()
{
int i,p,num, ans = 0;

scanf("%d",&num);

scanf("%d", &num);
for(i=1; i<=num; i++)
{
if(num%i==0)
{
p++;
}
}
if(p==2)
{
printf("Entered number is %d "\
"and it is a prime number.",num);
}
else
{
printf("Entered number is %d "\
"and it is not a prime number.",num);
}
while(num > 0)
{

int mod = num % 10;

ans = ans * 10 + mod;

num = num / 10;
}

printf("Reversed Number is %d\n",ans);

return 0;
}```
Posted
Updated 24-Feb-22 1:41am

## Solution 1

1) Why are you reading the number first, then prompting for it, then reading it again?
2) What value does `p` have when the app starts?
3) Since every number is divisible by 1 and itself by definition, why are you testing either of those values?
4) Since every number greater than 2 has been test divided by two, why do you have to go past half the number at all?
5) Since every number greater than 2 has been test divided by two, why do you have to heck any multiple of two? Is there a good reason to increment by one?
6) Why do you always run to the end of the loop? if you don't check 1 or the number, just use `break` to exit the loop as soon as you find a divisor.
Sakib1306 24-Feb-22 11:03am

OriginalGriff 24-Feb-22 11:41am

No, that's not what we are here for - this is your homework, not mine, and your teacher wants to see what you can do, not me! LOL.
Plus, if I do it for you, you don't learn anything and the next exercise gets harder for you to do ...

Read my questions above one by one, and see if you can work out what I'm saying.
Start with the first one and it's be pretty obvious what you have to do!