C Program to find sum of two numbers



#include<stdio.h>
#include<conio.h>
void main()
{
int number,p,num;
clrscr();
printf("Enter the number:");
scanf("%d",&number);
num=number-1;
while(num>1)
{
if(number%num==0)
{
p=0;
break;
}
else
{
p=1;
}
num--;
}
if(p==0)
{
printf("%d is not a prime number",number);
}
if(p==1)
{
printf("%d is a prime number",number);
}
getch();
}

Explanation:

The above program will print that whether the given number is prime or not. The program takes an integer value from user and assigns that value in the variable 'number'. While loop will be executed till the number does not become less than 1.In the loop we will check that the number is properly divisible by the numbers less than that number or not. If that number is not properly divisible by the any number less then that number then we can say that number is 'prime' and if the number is properly divisible by any single number less then that number then the number is not prime. We can understand this process with the help of given example:

number=5,num=4
num>1,True
iteration1:
5%4==0, False
So p=1
num=3
num>1,True
iteration2:
5%3==0, False
So p=1
num=2
num>1,True
iteration3:
5%2==0, False
So p=1
num=1
num>1,False
So finally p=1,So 5 is a prime number.
The output of the above program is given below:

Output:

c program