Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.
Ask a Question
Ask a Question
The following code doesn't show if a number is prime or not, where is the problem?
Jun 7, 2018
Jun 30, 2018
int n,i,sum =0;
printf("Enter number = ");
sum = sum + n + i;
if(sum = 2*n+1)
else printf("Not a prime number");
closed with the note:
the answer by the below user is sufficient
Jun 8, 2018
Jun 10, 2018
There is a "problem" in:
sum = 2*n+1(on the "if" just after the loop)
sum = 2*n+1 actually sets the value of sum to 2*n+1, and then evaluates if that is "true"(different from 0) or false(equals 0) .This is not "wrong" in the sense that it is actually valid code, however it is not intended behavior. To fix it you should put "==" instead of "=", because that will actually compare the numbers;
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
To avoid this verification in future, please
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
Snow Theme by