Dr. A.P.J. Abdul Kalam Technical University, Lucknow
KCS101 / KCS201 Programming for Problem Solving - Using C Language
Lab Exercises
16. Write a program to check whether the entered number is prime or not.
/*
File: Prgrm16.c
Author: Aditya Saini
Date: Sept 30, 2019
Description: Program to check whether the entered number is prime or not.
*/
#include <stdio.h>
int main (void)
{
int number;
//Checking if the number is prime or not.
for (i = 2; i < number; i++)
int i;
//Input number.
printf ("Input number: ");
scanf ("%d", &number);
//Input number.
printf ("Input number: ");
scanf ("%d", &number);
//Checking if the number is prime or not.
for (i = 2; i < number; i++)
{
if (number % i == 0)
{
printf ("%d is not Prime.", number);
break;
}
}
if (i == number)
{
printf ("%d is Prime.", number);
}
if (number % i == 0)
{
printf ("%d is not Prime.", number);
break;
}
}
if (i == number)
{
printf ("%d is Prime.", number);
}
};
Output
Input number: 23
23 is Prime.
No comments:
Post a Comment
Please do not post spam links.