Writing a C Program to Print Prime Numbers Between 50 and 100 using while loop

21 May 2023 Balmiki Mandal 0 C Programming

Printing Available Prime Numbers Between 50 to 100 Using a While Loop

If you are looking for an easy way to print out the available prime numbers between 50 to 100, a while loop is a great option. In this tutorial we will discuss how to write a C program to print out the available prime numbers using a while loop.

What is a Prime Number?

A prime number is a whole number that is only divisible by itself and 1. It is an important concept in mathematics and many programming algorithms use prime numbers as part of their calculations. For example, any number that is divisible by 2, 3, 5, or 7 is not a prime number.

How to print Available Prime Numbers Using a While Loop

In order to print out the available prime numbers between 50 to 100 using a while loop, we first need to set up a loop that starts at 50 and ends at 100. The loop should first check if the current number is divisible by any other number between 2 and the number itself. If it is not, then it is a prime number and should be printed out. The following is the C code to print out the available prime numbers using a while loop.

C programming

#include<stdio.h>
 
int main()
{
    int num, i, flag;
    num = 50;
 
    while(num <= 100)
    {
        flag = 0;
 
        for(i=2; i<=num/2; ++i)
        {
            if(num%i == 0)
            {
                flag = 1;
                break;
            }
        }
 
        if (flag == 0)
            printf("%d ",num);
 
        ++num;
    }
 
    return 0;
}

Output

51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99

Top Resources

Prime Numbers: C Program Example and Explanation

Design a function to check the given number is prime or not if prime return 1 else 0

Write a C Program to Check if a Number is Prime or Not Using For Loop

Writing a C Program to Print Prime Numbers Between 50 and 100

write a program to print prime numbers in 10 array elements.

Write a C program to input 10 numbers through the keyword and find the number of prime counts it stores the into a separate array and display it.

Further Reading:

 For further information and examples, Please visit[ C-Programming From Scratch to Advanced 2023-2024]

 

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

 

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.