Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Test expression



Comment



Specifer



Working with switch case



Header file




Function_ find prime number




// AHF C PROGRAM SOLVING

//The problem are solving here using FUNCTION

#include<stdio.h> #include<math.h> #define pf printf //function declaration int prime(int n); int main() { int a,result; pf("Enter any integer number: "); scanf("%d",&a); //function call result=prime(a); if(result==1) pf("%d is prime number",a); else pf("%d is not prime number",a); return 0; } //function definition int prime(int n) //function header //function body { int i,flag=0; for(i=2;i<n/2;i++) { if(n%i==0) { flag=1; break; } } if(flag==0) return 1; else return 0; }
OUTPUT:


© 2018 - All rights reserved