- Lets discuss a program on how to print prime numbers from 1 to 100.
- Here by default we need to print all prime numbers from 1 to 100.
- No need to ask user to enter a number because we need to end loop at 100.
- Using for loop iterate from 1 to 100
- Take one more loop and check each number is divisible by 1 and itself or not.
- Program to print prime number between 1 to 100 in c
#1.C program to print prime numbers from 1 to 100
- #include <stdio.h>
- // c program to print prime numbers from 1 to 100
- // www.instanceofjava.com
- int main()
- {
- int n, i,k, count = 0;
- printf("Prime numbers from 1 to 100\n");
- for(i=2;i<=100;i++)
- {
- for(k=2;k<i;k++)
- {
- if(i%k==0)
- break;
- else if(i==k+1)
- printf("%d\n",i);
- }
- }
- getch();
- }
No comments