Advertisement
Guest User

Untitled

a guest
May 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void gerade(int zahl);
  6. void ungerade(int zahl);
  7.  
  8. int main()
  9. {
  10.     int zahl, op;
  11.    
  12.     cout << "Bitte geben Sie eine ganzstellige Zahl ein: ";
  13.     cin >> zahl;
  14.  
  15.     cout << "geben Sie die 1 fuer gerade und 2 fuer ungerade Zahlen ein: ";
  16.     cin >> op;
  17.  
  18.     switch (op)
  19.     {
  20.         case 1: gerade(zahl); break;
  21.         case 2: ungerade(zahl); break;
  22.  
  23.         default: cout<<"Dieser Befehl existiert nicht!!"<<endl;
  24.     }
  25.  
  26.     system("pause");
  27. }
  28.  
  29. void gerade(int zahl)
  30. {
  31.     for(int i=0; i<=zahl; i++)
  32.         if (i%2==0)
  33.             cout<<i<<"; ";
  34. }
  35.  
  36. void ungerade(int zahl)
  37. {
  38.     for(int i=0; i<=zahl; i++)
  39.         if (i%2 == 1)
  40.             cout << i <<"; ";
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement