24. Write a program to check whether the given number is prime or not.

#include <stdio.h>
#include<conio.h>
void main()
{
    int a,b,val=0;
    printf("Enter a positive integer: ");
    scanf("%d", &a);
    for(b = 2; b <= a/2; ++b)
    {
        // condition for nonprime number
        if(a%b == 0)
        {
            val = 1;
            break;
        }
    }
    if (b == 1)
    {
      printf("1 is neither a prime nor a composite number.");
    }
    else
    {
        if (val == 0)
          printf("%d is a prime number.",a);
        else
          printf("%d is not a prime number.",a);
    }
    getch();
}



#OUTPUT:




Comments

Popular posts from this blog

12. Write a program to read marks from keyboard and your program should display equivalent grade according to following table(if else ladder) Marks Grade 100 - 80 Distinction 79 - 60 First Class 59 - 40 Second Class < 40 Fail

13. Write a c program to prepare pay slip using following data. Da = 10% of basic, Hra = 7.50% of basic, Ma = 300, Pf = 12.50% of basic, Gross = basic + Da + Hra + Ma, Nt = Gross – Pf.