Facebook
From dwadwa, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 244
  1. #include<iostream>
  2. #include<cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. bool first(int n)
  7. {
  8.         if (n < 2)
  9.                 return false;                  
  10.         for (int i = 2; i * i <= n; i++)
  11.                 if (n % i == 0)
  12.                         return false;          
  13.         return true;
  14. }
  15. int main()
  16. {
  17.         int up, down,sum;
  18. sum=0;
  19.         cout << "Podaj liczbę gorna: ";
  20.         cin >> up;
  21.         cout << "Podaj liczbę dolna: ";
  22.         cin >> down;
  23.         for (; down <= up; down++)
  24.         {
  25.         if (first(down)==true) {
  26.                 sum+=down;
  27.                 cout<<"liczba "<<down<<"jest pierwsza\n";
  28.                 }  
  29.         }
  30.         cout<<sum;
  31.     cout<<endl;
  32.         system("pause");
  33.         return 0;
  34. }
  35.  
  36.  
  37.  
  38. ==========================================================================================
  39.  
  40.  
  41.  
  42. #include <iostream>
  43. #include <cstdlib>
  44. #include <windows.h>
  45.  
  46. using namespace std;
  47.  
  48.         void gotoxy ( int x, int y)
  49.         {
  50.                 COORD coord;
  51.                 coord.X = x;
  52.                 coord.Y = y;
  53.                 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  54.         }
  55. int main(int argc, char** argv)
  56. {
  57.     for (int i=1;i<=9;i++)
  58.    {
  59.        gotoxy(2,i);
  60.        cout<<"|";
  61.        }
  62.    for (int i=1;i<=23;i++)
  63.    {
  64.        gotoxy(i,2);
  65.        cout<<"-";
  66.        }
  67.    for (int i=3;i<=23;i++)
  68.    {
  69.        gotoxy(3,1);
  70.        cout<<"  1  2  3  4  5  6  7";
  71.        }
  72.    for (int i=1;i<=9;i++)
  73.    {
  74.        gotoxy(1,3);
  75.        cout<<"1\n 2\n 3\n 4\n 5\n 6\n 7\n";
  76.        }
  77.     for (int i=3;i<=23;i++)
  78.    {
  79.        gotoxy(3,3);
  80.        cout<<"  1  2  3  4  5  6  7";
  81.        }
  82.    for (int i=3;i<=23;i++)
  83.    {
  84.        gotoxy(3,4);
  85.        cout<<"  2  4  6  8 10 12 14";
  86.        }
  87.        for (int i=3;i<=23;i++)
  88.    {
  89.        gotoxy(3,5);
  90.        cout<<"  3  6  9 12 15 18 21";
  91.        }
  92.        for (int i=3;i<=23;i++)
  93.    {
  94.        gotoxy(3,6);
  95.        cout<<"  4  8 12 16 20 24 28";
  96.        }
  97.        for (int i=3;i<=23;i++)
  98.    {
  99.        gotoxy(3,7);
  100.        cout<<"  5 10 15 20 25 30 35";
  101.        }
  102.        for (int i=3;i<=23;i++)
  103.    {
  104.        gotoxy(3,8);
  105.        cout<<"  6 12 18 24 30 36 42";
  106.        }
  107.    for (int i=3;i<=23;i++)
  108.    {
  109.        gotoxy(3,9);
  110.        cout<<"  7 14 21 28 35 42 49";
  111.        }
  112.        cout<<endl;
  113.             system("PAUSE");
  114.     return EXIT_SUCCESS;
  115. }
  116.