Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.  
  10.     int n, c, d, g=0, p;
  11.     double e, f;
  12.     int    z, x;
  13.     cout << "Program sumujacy trzecia potege kazdej z cyfr z ktorych sklada sie wprowadzona liczba 'n'." << endl;
  14.  
  15.     cout << "###########################################################################################" << endl;
  16.  
  17.     cout << "Podaj liczbe 'n': ";
  18.     cin >> n;
  19.  
  20.     int n2 = n;
  21.     int len = 1;
  22.  
  23.     if (n2 > 0) {
  24.         for (len = 0; n2 > 0; len++) {
  25.             n2 = n2 / 10;
  26.         }
  27.     }
  28.  
  29.  
  30.     for (int i = 1; i < len+1; i = i++)
  31.     {
  32.  
  33.         e = (pow(10, i)) / 10;
  34.         z = (int) e;
  35.         d = n / z;
  36.         c = d % 10;
  37.  
  38.  
  39.         f = pow(c, 3);
  40.         x = (int) f ;
  41.         if (e == 0)
  42.             break;
  43.         cout << "Potega " << i << " cyfry: " << x << endl;
  44.  
  45.         g = g + x;
  46.  
  47.  
  48.     }
  49.  
  50.     cout << "Suma szescianow cyfr liczby: "<< g << endl;
  51.     cin >> p;
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement