logo codesdope

write a c++ program to print prime number 1 to 100?

   sahebalam , sagi rama krishna college

write  a c++ program to print prime number 1 to 100?


Answers

  •    Aakhya Singh

    I have written the code below. You can find its explanation here – https://www.codesdope.com/discussion/cprogram-to-display-prime-number-between-two-inter/

    #include <iostream> 
    
    using namespace std; 
    
    int main() {
       int num1 = 1, num2 = 100;
       cout << "Prime numbers between " << num1 <<" and "<< num2 <<": ";
       while (num1 < num2)
        {
            int flag = 0;
    
            for(int i = 2; i <= num1/2; i++)
            {
                if(num1 % i == 0)
                {
                    flag = 1;
                    break;
                }
            }
    
            if (flag == 0)
                cout << num1 << " ";
    
            num1++;
        }
    
       return 0;
    }
    

     



Download Our App.
BlogsDope App
Get it on Google Play
Write your answer
Close

Welcome.please sign up.

Close

Welcome.please login.