Created
March 28, 2023 13:34
-
-
Save hamzamuric/7145c9a5de27379690011256a5aef3b7 to your computer and use it in GitHub Desktop.
35 Коеираіте апликациду коіом се за дати природни бро) п (Пе100), у зависности од избора корисника, одреБуде и приказуе: * сума цифара, • наімаа цифра, • навеа цифра, • цифра навете тежине, • броі добиен записом цифара броа п у обрнутом поретку.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class HelloWorld { | |
static int SumaCifara(int n) { | |
int s = 0; | |
while (n > 0) { | |
s += n % 10; | |
n /= 10; | |
} | |
return s; | |
} | |
static int NajmanjaCifra(int n) { | |
int c = n % 10; | |
while (n > 0) { | |
if (n % 10 < c) { | |
c = n % 10; | |
} | |
n /= 10; | |
} | |
return c; | |
} | |
static int NajvecaCifra(int n) { | |
int c = n % 10; | |
while (n > 0) { | |
if (n % 10 > c) { | |
c = n % 10; | |
} | |
n /= 10; | |
} | |
return c; | |
} | |
static int CifraNajveceTezine(int n) { | |
while (n / 10 > 0) { | |
n /= 10; | |
} | |
return n; | |
} | |
static int Obrnuti(int n) { | |
int o = 0; | |
while (n > 0) { | |
o = 10 * o + n % 10; | |
n /= 10; | |
} | |
return o; | |
} | |
static void Main() { | |
Console.WriteLine("Unesite prirodan broj n: "); | |
int n = Convert.ToInt32(Console.ReadLine()); | |
Console.WriteLine("Odaberite operaciju (1, 2, 3, 4): "); | |
int op = Convert.ToInt32(Console.ReadLine()); | |
int res = 0; | |
switch (op) { | |
case 1: | |
res = SumaCifara(n); | |
break; | |
case 2: | |
res = NajmanjaCifra(n); | |
break; | |
case 3: | |
res = NajvecaCifra(n); | |
break; | |
case 4: | |
res = CifraNajveceTezine(n); | |
break; | |
case 5: | |
res = Obrnuti(n); | |
break; | |
} | |
Console.WriteLine(res); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment