Advertisement
NoxScourge

Untitled

Sep 9th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include "stdio.h"
  2.  
  3. void main() {
  4.  
  5. int broj, cifra, suma = 0, prethodnacifra, tacnost = 1; //proveravam da li je tacno ili netacno mnogo olaksava
  6.  
  7.  
  8. printf("Unesite n-tocifreni broj:\n");
  9. scanf("%d", &broj); 456789
  10.  
  11. cifra = broj % 10; u startu uzimam da mi je cifra = 9
  12.  
  13. while (broj > 0) {
  14.  
  15.  
  16.  
  17. prethodnacifra = cifra; prethodna cifra = 9
  18. broj = broj / 10; broj je sada 45678
  19. suma += prethodnacifra;
  20. cifra = broj % 10; cifra mi je 8
  21.  
  22. if (cifra > prethodnacifra) { 8>9 ako jeste, onda nije rastuci
  23. tacnost = 0;
  24. }
  25. }
  26.  
  27. if (tacnost)
  28. {
  29. printf("Cifre broja su sortirane u rastuci redosled!!!\n");
  30. printf("Suma svih cifara zadatog broja je %d \n", suma);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement