Print the prime or composite numbers upto limit using While Loop in C


This program is about checking and print the prime or composite numbers upto given limits using While Loop

Source Code

#include<stdio.h>
int main()
{
  int i,n=2,a,b,prime=0;
  printf("\nEnter the starting number:");
  scanf("%d",&i);
  printf("\nEnter the ending number:");
  scanf("%d",&b);
  while(i<=b)
  {
    prime=0;
    n=2;
    while(n<i)
    {
      if(i%n==0)
      {
        prime++;
      }
      n++;
    }
    if(prime==0)
    {
      printf("\n%d",i);
    }
    i++;
  }
  return 0;
}
To download raw file Click Here

Output


Enter the starting number:1
Enter the ending number:15
1
2
3
5
7
11
13


List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes