pjobro

for/while day 3

Mar 12th, 2017
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. suma niza.
  2. {
  3. int n;
  4. int z;
  5. int zbroj = 0;
  6. int i = 1;
  7. cin >> n;
  8. while (i <= n)
  9. {
  10. i++;
  11. cin >> z;
  12. zbroj += z;
  13. }
  14. cout << zbroj;
  15. system("pause");
  16. return 0;
  17. }
  18.  
  19.  
  20. prost broj....return*
  21. {
  22.     int broj = 1;
  23.     cin >> broj;
  24.  
  25.     if (broj == 2 || broj == 3)
  26.     {
  27.         cout << "prost";
  28.         return 0;
  29.     }
  30.     if (broj % 2 == 0 || broj % 3 == 0 || broj % 5 == 0 || broj % 7 == 0)
  31.     {
  32.         cout << "nije prost";
  33.         return 0;
  34.     }
  35.     cout << "prost";
  36.     return 0;
  37. }
  38.  
  39. prvih n brojvea
  40. {
  41.     int broj=1;
  42.     int brojac;
  43.     cin>>broj;
  44.     for (brojac=1;broj>=brojac;brojac++){
  45.    
  46.     cout<<brojac<<endl;
  47.     }
  48.     return 0;
  49. }
  50.  
  51. parni
  52. {
  53.     int broj=1;
  54.     int brojac;
  55.     cin>>broj;
  56.     for (brojac=2;brojac<=broj;brojac++){
  57.         if(brojac%2==0)
  58.  
  59.     cout<<brojac<<endl;
  60.  
  61.     }
  62.     return 0;
  63. }
  64.  
  65. sreca-bomboni
  66. {
  67.     int ucenici=1;
  68.     int bomboni=0;
  69.     int brojac=1;
  70.     int sretni=0;
  71.  
  72.     cin >>ucenici;
  73.  
  74.     for(brojac=1;brojac<=ucenici;brojac++){
  75.         cin>>bomboni;
  76.         if (brojac<=bomboni) {sretni++;}
  77.     }
  78.     cout<<sretni;
  79.  
  80. return 0;
  81. }
Add Comment
Please, Sign In to add comment