Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

hurr durr

Name: Anonymous 2012-06-16 15:53

so I just started programing like two days ago (c++) , and Im doing basic exercises, nothing really complicated, but for some reason I cant get this, any help is welcome

Pd: I have never been so scared of posting in a board
---------------------------------------
#include <iostream>

using namespace std;

int main()
{
  int n;
  int c;
  int crash;
  cout<<"Insert a number"<<endl;
  cin>>n;

  /*do{
    if(n%c==0){
     crash = 1;
    }
    c = c - 1;
    }while(c == 1);*/

    for(c = n-1; c == 1; c--){
      if(n%c == 0){
      crash = 1;
     }
    }


    if(crash == 1){
    cout<<"The number is prime"<<endl;
    } else{
    cout<<"The number is not prime"<<endl;}

    return 0;
  }

Name: Anonymous 2012-06-16 21:22

1. You only need to go from 2 to the square root of n.
2. Go to www.projecteuler.net.  It has math-related exercises that will really make you think about how to write right code.
3. That's a pretty good first try.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List