This simple C program prints all the prime numbers between 1 and 100. A Prime number is a natural number greater than 1 that is only divisible by either 1 or itself. All numbers other than prime numbers are known as composite numbers. There are infinitely many prime numbers, here is the list of first few prime numbers 2 3 5 7 11 13 17 19 23 29 31 37.... This C program illustrates the use of nested for loops. The outer for loop iterate from 2 to 100 while the inner loop check the number for prime condition.

/*C program to print all the prime numbers between 1 and 100*/ #include<stdio.h> int main() { int number,j,flag; printf(" The prime numbers between 1 and 100 : \n"); for(number=2;number<=100;number++) { flag=0; for(j=2;j<=number/2;j++) { if(number % j == 0){ flag = 1; break; } } if(flag==0) printf("\n %d ",number); } return 0; }

The prime numbers between 1 and 100 : 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

1. This C program uses nested for loops to find and print all the prime numbers between 1 and 100. 2. The outer loop iterate through 2 to 100, while the inner loop use the modulus operator to check whether the number in current iteration is prime or not. If a prime number is found, the variable flag is set to 1 and the inner loop is existed using the break statement. 3. Otherwise, if flag variable remains zero, the number in current iteration is displayed on the screen as prime number.

Questions from Previous year GATE question papers

UGC NET Previous year questions and practice sets

Attempt a small test to analyze your preparation level. This GATE exam includes questions from previous year GATE papers.

Practice test for UGC NET Computer Science Paper. The questions asked in this NET practice paper are from various previous year papers.