Make Simple Calculator in C
To make a simple calculator in C programming which performs basic four mathematical operations, use the switch case to identify the input operator to perform required calculation then display the result
C Programming Code to Make Simple Calculate
Following is a simple C program which is a menu-driven program based on simple calculation like addition, subtraction, multiplication and division according to user's choice:
EXAMPLE C PROGRAM FOR PRIME NUMBER:
#include <stdio.h>
int main()
{
int i, num, p = 0;
printf("Please enter a number: \n");
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);
}
}
OUTPUT OF C PROGRAM FOR PRIME NUMBER:
Please enter a number: 13
Entered number is 13 and it is a prime number.
|