Digital जीवन

Free Online Education for India...

Full width home advertisement

Computer Basic

C Programming

Engineering Graphics

Post Page Advertisement [Top]

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;
               int i;

               //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);
               }

               return 0;
};

Output

Input number: 23
23 is Prime.



No comments:

Post a Comment

Please do not post spam links.

Bottom Ad [Post Page]

| Designed by Colorlib