Solution with out using functions(Using For Loop)
Solution with out using functions(Using While Loop)
Solution using functions without passing arguments
C program to print all prime numbers from 100 to 150(Using For Loop)
Solution : Without using function
Program/Source Code
#include <stdio.h> int main() { int n=2,i,z=0; for(n=100;n<=150;n++) { z=0; for(i=2;i<n;i++) { if(n%i==0) { z=1; break; } } if(z==0) printf("%d, ",n); } return 0; }
Output:
101, 103, 107, 109, 113, 127, 131, 137, 139, 149,
C program to print all prime numbers from 100 to 150(Using While Loop)
Solution : Without using function
Program/Source Code
#include <stdio.h> int main() { int n=100,i,z=0; while(n<=150) { i=2; z=0; while(i<n) { if(n%i==0) { z=1; break; } i++; } if(z==0) printf("%d ",n); n++; } return 0; }
Output:
101, 103, 107, 109, 113, 127, 131, 137, 139, 149,
C program to print all prime numbers from 100 to 150(Using For Loop)
Solution : Using function Without Passing Arguments
Program/Source Code
#include <stdio.h> void check() { int n,i,z=0; for(n=100;n<=150;n++) { z=0; for(i=2;i<n;i++) { if(n%i==0) { z=1; break; } } if(z==0) printf("%d, ",n); } } int main() { check(); return 0; }
Output:
101, 103, 107, 109, 113, 127, 131, 137, 139, 149,
Previous:
Next: |
Tutorials | Technical Questions | Interview Questions |
---|---|---|
C Programming C++ Programming Class 11 (Python) Class 12 (Python) |
C Language C++ Programming Python |
C Interview Questions C++ Interview Questions C Programs C++ Programs |