Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Решење задатака за прву радну недељу

1. Написати програм који приказује број (int), који је дупло већи од броја којег је унео корисник.

class Program
{
static void Main(string[] args)
{
int br = int.Parse(Console.ReadLine());
int novi = br * 2;
Console.WriteLine(novi);
}
}

2. Написати програм који исписује колико цифара има унети број х. (0 < х < 9999)

class Program
{
static void Main(string[] args)
{
int x = int.Parse(Console.ReadLine());
if (x < 10)
{
Console.WriteLine(1);
}
else if (x < 100)
{
Console.WriteLine(2);
}
else if (x < 1000)
{
Console.WriteLine(3);
}
else
{
Console.WriteLine(4);
}
}
}

3. Написати програм који исписује све бројеве од А до В у опадајућем низу. (бројеве А и В бира корисник)

class Program
{
static void Main(string[] args)
{
int A = int.Parse(Console.ReadLine());
int B = int.Parse(Console.ReadLine());
for (int i = B; i >= A; i--)
{
Console.Write(i + " ");
}
}
}

4. Написати програм који исписује све бројеве од 2.2 до 7.5 (у растућем низу са кораком 0.1)

class Program
{
static void Main(string[] args)
{
for (double i = 2.2; i <= 7.5; i += 0.1)
{
Console.WriteLine(i);
//Console.WriteLine(i.ToString("0.#"));
}
}
}
5. Написати програм који исписује збир цифара унетог троцифреног броја t.

class Program
{
static void Main(string[] args)
{
int t = int.Parse(Console.ReadLine()); //t=abc
int a = t / 100;
int b = t / 10 % 10;
int c = t % 10;
int z = a + b + c;
Console.WriteLine(z);
}
}

6. Написати програм који словима исписује вредност унетог броја х. (20 < х < 100) НПР. 25 -> двадесет пет

class Program
{
static void Main(string[] args)
{
int x = int.Parse(Console.ReadLine()); //t=ab
int a = x / 10;
int b = x % 10;
if (a == 2)
{
Console.Write("dvadeset");
}
else if (a == 3)
{
Console.Write("trideset");
}
else if (a == 4)
{
Console.Write("četrdeset");
}
else if (a == 5)
{
Console.Write("pedeset");
}
else if (a == 6)
{
Console.Write("šezdeset");
}
else if (a == 7)
{
Console.Write("sedamdeset");
}
else if (a == 8)
{
Console.Write("osamdeset");
}
else if (a == 9)
{
Console.Write("devedeset");
}
if (b == 1)
{
Console.Write(" jedan");
}
else if (b == 2)
{
Console.Write(" dva");
}
else if (b == 3)
{
Console.Write(" tri");
}
else if (b == 4)
{
Console.Write(" četiri");
}
else if (b == 5)
{
Console.Write(" pet");
}
else if (b == 6)
{
Console.Write(" šest");
}
else if (b == 7)
{
Console.Write(" sedam");
}
else if (b == 8)
{
Console.Write(" osam");
}
else if (b == 9)
{
Console.Write(" devet");
}
Console.WriteLine();
}
}
7. Написати програм који исписује све цифре броја х. (0 < х < 9999) НПР. 257 -> 2 5 7

class Program
{
static void Main(string[] args)
{
int x = int.Parse(Console.ReadLine());
if (x < 10) //x=a
{
Console.WriteLine(x);
}
else if (x < 100) //x=ab
{
int a = x / 10;
int b = x % 10;
Console.WriteLine(a + " " + b);
}
else if (x < 1000) //x=abc
{
int a = x / 100;
int b = x / 10 % 10;
int c = x % 10;
Console.WriteLine(a + " " + b + " " + c);
}
else //x=abcd
{
int a = x / 1000;
int b = x / 100 % 10;
int c = x % 100 / 10;
int d = x % 10;
Console.WriteLine(a + " " + b + " " + c + " " + d);
}
}
}

Д. Решење домаћег задатка за прву недељу курса

class Program
{
static void Main(string[] args)
{
string rec = Console.ReadLine();
for (int i = 0; i < rec.Length; i += 3)
{
Console.Write(rec[i]);
}
Console.WriteLine();
}
}

You might also like