Advertisement
MyGrandma

oskar instrukcije: naloga1 resitve

Jul 6th, 2022
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 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. void izpisRange(int a, int b);
  13. void kalkuliraj(int n);
  14. void sestejStevke(int n);
  15.  
  16. int main()
  17. {
  18.     sestejStevke(987654321);
  19.  
  20.     return 0;
  21. }
  22.  
  23. void sestejStevke(int n){
  24.     int rezultat = 0;
  25.    
  26.     while(n > 0){
  27.         // iz številke pridobi zadnjo števko
  28.         int s = n % 10;
  29.         // prištej jo rezultatu
  30.         rezultat += s;
  31.         // deli število
  32.         n = n / 10;
  33.         // cout << s << " " << n << endl;
  34.     }
  35.     cout << rezultat;
  36. }
  37.  
  38. void kalkuliraj(int n){
  39.     int rezultat = 0;
  40.    
  41.     for (int i = 0; i < n; i++) {
  42.         int delni_rezultat = 0;
  43.        
  44.         for(int j = 0; j < (i + 1); j++){
  45.             delni_rezultat += j+1;
  46.             cout << (j+1) << " ";
  47.             if (j == i){
  48.                 cout << "= " << delni_rezultat;
  49.                 rezultat += delni_rezultat;
  50.             } else{
  51.                 cout << "+ ";
  52.             }
  53.         }
  54.        
  55.         cout << endl;
  56.     }
  57.     cout << "Skupni seštevek: " << rezultat;
  58. }
  59.  
  60. void izpisRange(int a, int b){
  61.     for(int i = a; i < b; i++){
  62.         cout << i << " ";
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement