Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Working with switch case



" ; " after loop



Iterative statement



Comment



Specifer




Prime number in a range




// 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,i,j; //taking the number to continue loop as start point pf("Enter the first number: "); scanf("%d",&n); //taking the number to stop loop pf("\nEnter the second number: "); scanf("%d",&m); for(i=n;i<=m;i++) { int fact=0; //for no error in the result for(j=2;j<i/2;j++) //testing calculation for every number { if(i%j==0) { fact=1; break; //test will end and testing for another number will start from first loop } } if(fact==0) { pf("\n%d is prime number",i); continue; //the result will print and testing for another number will start from first loop } } return 0; }
OUTPUT:


© 2018 - All rights reserved