Primzahl oder nicht ! hilfe

nargaroth

Grünschnabel
hallo leute !

ich hab ein frage für euch; die frage ist :

Bestimmen Sie, ob eine eingegebene natürliche Zahl eine Primzahl ist.


ich hab was geschrieben aber das programm ist nicht kompiliert.



#include <iostream.h>
#include <conio.h>
int main()
{
int a;
bool prime=true;
cout<<"Geben Sie bitte eine zahl ein: ";
cin>>a;
for(int divisor=a-1; divisor>1; divisor--)
if(a%divisor==0)
prime=false;
if(prime)
cout<<a<<" ist Primzahl"<<endl;
if(!prime)
cout<<a<<" is nicht Primzahl"<<endl;

return 0;
}



wo liegt mein fehler?

lg nargaroth
 
#include <iostream.h> <--- .h ist c Notation, in c++ bitte nur <iostream>
#include <conio.h>
int main()
{
int a;
bool prime=true;
cout<<"Geben Sie bitte eine zahl ein: "; <--- cout kennt er nicht, was wohl dir auch der Compiler sagt! Entweder: std::cout oder du schreibst vor main(): using namespace std
cin>>a;
for(int divisor=a-1; divisor>1; divisor--)
if(a%divisor==0)
prime=false;
if(prime)
cout<<a<<" ist Primzahl"<<endl;
if(!prime)
cout<<a<<" is nicht Primzahl"<<endl;

return 0;
}



wo liegt mein fehler?

lg nargaroth
 
Zurück