Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Working with switch case



Test expression



Header file



" ; " after loop



Iterative statement




Print whether given number is prime or composite




// AHF C PROGRAM SOLVING

//solving here ITERATIVES STATEMENTS type of programming problem

#include<stdio.h> #include<math.h> #define pf printf int main() { int n,m,fact=0,i; //taking the number to continue loop pf("Enter any number: "); scanf("%d",&n); //testing the given number is prime or not for(i=2;i<n/2;i++) { if(n%i==0) { fact=1; break; } } //printing the result if(fact==0) pf("\n%d is prime number",n); else pf("\n%d is composite number",n); return 0; }
OUTPUT:


© 2018 - All rights reserved