Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Working with switch case



Comment



" ; " after loop



Test expression



Iterative statement




Function_ find prime number in range




// 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,b,i,result; pf("Enter first number: "); scanf("%d",&a); pf("\nEnter second number: "); scanf("%d",&b); for(i=a;i<=b;i++) { //function call result=prime(i); if(result==1) pf("\n%d is prime number",i); else pf("\n%d is not prime number",i); } 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