sahajjain01

Display prime numbers upto n.

Aug 21st, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. //Program to display prime numbers upto n.
  2. #include<iostream.h>
  3. #include<conio.h>
  4. void main()
  5. {
  6.     clrscr();
  7.     int a,b,c,z;
  8.     cout<<"Enter a number: ";
  9.     cin>>a;
  10.     cout<<"The prime numbers upto "<<a<<" are: "<<endl;
  11.     for(b=2;b<=a;b++)
  12.     {
  13.         z=0;
  14.         for(c=1;c<=b;c++)
  15.         {
  16.             if(b%c==0)
  17.             z++;
  18.         }
  19.         if(z==2)
  20.         cout<<b<<" ";
  21.     }
  22.     getch();
  23. }
Advertisement
Add Comment
Please, Sign In to add comment