Printing Prime Numbers Till N in C++

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Printing Prime Numbers Till N in C++



You are given an integer N. You need to print the series of all prime numbers till N.



I want to know whats wrong with my code and suggestions will also be of great help.


#include<iostream>
using namespace std;
int main()
{
int N;
cin>>N;
int u;
for(int i=N;i>0;i--)
{
u=0;
for(int j=2;j<N-1;j++)
{

if(i%j==0)
{
u=1;
}

}
if(u==0)
{
cout<<i<<" ";
}

}

return 0;
}



Thanks for helping out. :)









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

xu4gNck,qZHd2Iq8AoACHFxu,g4c,m2I,PxlVucptZ5RDOsI 6mkfJX KpqC5 SjhY6Q5B
U3ACvWAuEpFATdG5QR 937aF0yfUUqmUEwC0rlra7zwBOV7 0Du,fYe0PyXCTpvumGMA,yss qPK b6qA4GLdL

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Current 93