program to print whether the number is prime or not

so ready guys what we are going to do today?
any guess?
facing Problem?


don't worry c4fun is here to help you
today we are going to find some prime numbers, not few you may find as many as you want using the simple code and with basic knowledge of c coding, you would be able to find the program logic.
first, think of the number, now think of what makes it prime and nonprime, when you are done with that think of the other factor which you might have thought it would make it a prime number but they were not applying there.
yes you have got it
yes you are on right track you will find that you are assuming the code how it should be ,go on like this you will imagine whole code ,
now you should make your own code ,if you are not able to make it in one go on problem you might have use any wrong loop, this might happen .in many cases this happens,but don't worry below is the source code with explanations you would be requiring and thus you would be able to get the desired result.

enter a number and checks whether it is a  prime or not?
 Solution....
. Take an input.
. Check if  number is divisible by any ,natural numbers
. If yes, then it is not a prime number. 
else it is a prime .
.
Code
c4fun brings the code of the C program 
to check if a given number is prime or not?.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j=0;
clrscr();
printf("\n enter the number ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{

if(n%i==0)
j=j+1;
}
if(j==2)
printf("\n number is prime");
else
printf("\n not prime");

getch();
}




have you done making it?
running?
so now its time to share the result of the code.
if it was not ruined by you in first go what was the mistake?
if you make the code but the result was wrong then what mistake you made?
did you catch the mistake?

now if you have found the program simple and basic and think it would be a help if you share it with the friends that are you delaying it share it, among your friends and knowing so that they might get the benefits of the blog.
as remember the basic sharing is caring and thus if you share the code among your friends then you are doing the best work .thanks to you and yes if you help one then it would help other thus forming a loop which will never break.




input different numbers and do find the numbers which you may think of maybe prime but comes out to be non-prime numbers.
upload different output image and let's play prime vs non-prime game...


will be waiting for the comment and let's make this session little interesting, share your thoughts and problem you face when you make the code?


if you are facing any doubt then comment the doubt below and it would be resolved soon, share your query and doubt it would be answered as soon as possible.
happy coding
happy learning.

No comments

thanks for reading and sharing.I hope it would help you!!!!

Powered by Blogger.