PPS Practical 43

PPS Practical 43
  • Aim: Write a function in the program to return 1 if number is prime otherwise return 0.
  • Code:
    //For turbo C++ remove below comments
    #include <stdio.h>
    //#include<conio.h>
    int prime(int n){
        for (int i = 2; i <= n/2; i++){
            if (n%i==0){
                return 0;
            }
        }
        return 1;
    }
    void main()
    {
        int n;
        //clrscr();
        printf("Enter Number : ");
        scanf("%d",&n);
        if (prime(n)){
            printf("Number %d is Prime",n);
        }else{
            printf("Number %d is not Prime",n);
        }
        // getch();
    }
  • Output:
    Output of practical 43

Comments