Advertisement
Guest User

Hana

a guest
Nov 19th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3.                               Online C++ Compiler.
  4.                Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10.  
  11. using namespace std;
  12. bool
  13. isPrime (int n)
  14. {
  15.   for (int i = 2; i <= (n / 2); ++i)
  16.     {
  17.         if ((n % i) == 0)
  18.         {
  19.           return false;
  20.         }
  21.      
  22.     }
  23.      return true;
  24. }
  25.  
  26. int
  27. main ()
  28. {
  29.   int end;
  30.   cout<<"Masukkan nilai akhir:";
  31.   cin >> end;
  32.   //i j k l m n o p
  33.   for (int i = 0; i < end; i++)
  34.     {
  35.  
  36.           //jika ganjil maka *, selainnya #;
  37.         if (i % 2)
  38.         {
  39.           //print desimal
  40.           for (int j = end; j >= 1; j--)
  41.           {
  42.               cout << j;
  43.           }
  44.           cout << endl;
  45.    
  46.           for (int j = 1; j <= end; j++)
  47.             {
  48.               cout << "*";
  49.             }
  50.         }
  51.         else
  52.         {
  53.           //print desimal tapi kebalik
  54.           for (int j = 1; j <= end; j++)
  55.             {
  56.               cout << j;
  57.             }
  58.           cout << endl;
  59.           for (int j = 1; j <= end; j++)
  60.             {
  61.               cout << "#";
  62.             }
  63.         }
  64.         cout << endl;
  65.         for(int j = 2,k=1; k <= end;j++)
  66.         {
  67.             if(isPrime(j))
  68.             {
  69.                 cout<<j;
  70.                 k++;
  71.             }
  72.         }
  73.         cout<<endl;
  74.         for(int j = 0; j< end; j++)
  75.         {
  76.             cout<<end-i;
  77.         }
  78.         cout<<endl;
  79.     }
  80.   return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement