Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int broj,broj2=0,broj3=0, cifra=0, kopija, najmanji = 9, brojac = 0;
  9.     cout << "Unesite cijeli broj N " << endl;
  10.     cin >> broj;
  11.     kopija = broj;
  12.     while (broj > 0)
  13.     {
  14.         cifra = broj % 10;
  15.         if (cifra < najmanji)
  16.         {
  17.             najmanji = cifra;
  18.         }
  19.         brojac++;
  20.         broj= broj / 10;
  21.     }
  22.     broj = kopija;
  23.     for (int i = 0; i < brojac; i++)
  24.     {
  25.         broj2 = kopija % 10;
  26.  
  27.         if (broj2 == najmanji)
  28.         {
  29.             broj3 += 3 * pow(10, i);
  30.         }
  31.  
  32.         else {
  33.             broj3 += broj2*pow(10, i);
  34.         }
  35.         kopija /= 10;
  36.     }
  37.     cout << "Broj nakon promijenjene najmanje cifre iznosi " << broj3 << endl;
  38.     cout << "Razlika izmedu ova dva broja je " << broj - broj3 << endl;
  39.  
  40.     system("pause>0");
  41.     return 0;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement