Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- void main() {
- int broj, cifra, suma = 0, prethodnacifra, tacnost = 1; //proveravam da li je tacno ili netacno mnogo olaksava
- printf("Unesite n-tocifreni broj:\n");
- scanf("%d", &broj); 456789
- cifra = broj % 10; u startu uzimam da mi je cifra = 9
- while (broj > 0) {
- prethodnacifra = cifra; prethodna cifra = 9
- broj = broj / 10; broj je sada 45678
- suma += prethodnacifra;
- cifra = broj % 10; cifra mi je 8
- if (cifra > prethodnacifra) { 8>9 ako jeste, onda nije rastuci
- tacnost = 0;
- }
- }
- if (tacnost)
- {
- printf("Cifre broja su sortirane u rastuci redosled!!!\n");
- printf("Suma svih cifara zadatog broja je %d \n", suma);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement