Printing Prime Numbers Till N in C++
Clash 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.