Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <iostream>
- using namespace std;
- void izpisRange(int a, int b);
- void kalkuliraj(int n);
- void sestejStevke(int n);
- int main()
- {
- sestejStevke(987654321);
- return 0;
- }
- void sestejStevke(int n){
- int rezultat = 0;
- while(n > 0){
- // iz številke pridobi zadnjo števko
- int s = n % 10;
- // prištej jo rezultatu
- rezultat += s;
- // deli število
- n = n / 10;
- // cout << s << " " << n << endl;
- }
- cout << rezultat;
- }
- void kalkuliraj(int n){
- int rezultat = 0;
- for (int i = 0; i < n; i++) {
- int delni_rezultat = 0;
- for(int j = 0; j < (i + 1); j++){
- delni_rezultat += j+1;
- cout << (j+1) << " ";
- if (j == i){
- cout << "= " << delni_rezultat;
- rezultat += delni_rezultat;
- } else{
- cout << "+ ";
- }
- }
- cout << endl;
- }
- cout << "Skupni seštevek: " << rezultat;
- }
- void izpisRange(int a, int b){
- for(int i = a; i < b; i++){
- cout << i << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement