0% found this document useful (0 votes)
4 views27 pages

C# Input Validation and Logic Examples

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views27 pages

C# Input Validation and Logic Examples

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Dastur kodi: Natija:

using System; Kiruvchi qiymat: Chiquvchi qiymat:


Input Output:
public class MyProgram
{
public static void Main(string[] args)
{
double a, b, c;

a = inputValue();
b = inputValue();
c = inputValue();
if (a - b > 9 || a - c > 9 || b - a > 9 || b - c > 9 || c - a > 9
|| c - b > 9)
{
[Link]("True");
}
else
{
[Link]("False");
}
}

// .NET can only read single characters or entire lines from


the
// console. The following function safely reads a double
value.
private static double inputValue()
{
double result;
while (![Link]([Link](), out result));
return result;
}
}
Dastur kodi: Natija:

using System; Kiruvchi qiymat: Chiquvchi qiymat:


Input Output:
public class MyProgram
{ 12 False
public static void Main(string[] args) 4 1 True
{
double a, b;

a = inputValue();
b = inputValue();
if (a > 2 && b <= 3)
{
[Link]("True");
}
else
{
[Link]("False");
}
}

// .NET can only read single characters or entire lines from the
// console. The following function safely reads a double value.
private static double inputValue()
{
double result;
while (![Link]([Link](), out result));
return result;
}
}
Dastur kodi: Natija:

using System; Kiruvchi qiymat: Chiquvchi qiymat:


Input Output:
public class MyProgram
{ 1 3 5 True
public static void Main(string[] args) 2 -3 -9 False
{
int a, b, c;

a = (int) inputValue();
b = (int) inputValue();
c = (int) inputValue();
if (a > 0 && b > 0 && c < 0 || a > 0 && b < 0 && c > 0 && a < 0
&& b > 0 && c > 0)
{
[Link]("True");
}
else
{
[Link]("False");
}
}

// .NET can only read single characters or entire lines from the
// console. The following function safely reads a double value.
private static double inputValue()
{
double result;
while (![Link]([Link](), out result));
return result;
}
}
Dastur kodi: Natija:

using System; Kiruvchi qiymat: Chiquvchi qiymat:


Input Output:
public class MyProgram
{ 123 Raqamlar o‘suvchi
public static void Main(string[] args) tartibda
{
int son, yuzlik, onlik, birlik;
Raqamlar o‘suvchi
son = (int) inputValue(); 251
tartibda emas
yuzlik = (int) ((double) son / 100);
onlik = (double) son / 10 % 10;
birlik = son % 10;
if (yuzlik < onlik && onlik < birlik)
{
[Link]("Raqamlar o‘suvchi tartibda");
}
else
{
[Link]("Raqamlar o‘suvchi tartibda emas");
}
}

// .NET can only read single characters or entire lines from the
// console. The following function safely reads a double value.
private static double inputValue()
{
double result;
while (![Link]([Link](), out result));
return result;
}
}
Dastur kodi: Natija:

using System; Kiruvchi qiymat: Chiquvchi qiymat:


Input Output:
public class MyProgram
{ 123 Raqamlar ketma-ket
public static void Main(string[] args) o‘suvchi yoki
{ kamayuvchi tartibda
int son, yuzlik, onlik, birlik;

son = (int) inputValue();


yuzlik = (int) ((double) son / 100);
onlik = (double) son / 10 % 10;
birlik = son % 10;
if (yuzlik < onlik && onlik < birlik || yuzlik > onlik && onlik >
birlik)
{
[Link]("Raqamlar ketma-ket o‘suvchi yoki
kamayuvchi tartibda");
}
else
{
[Link]("Raqamlar ketma-ket o‘suvchi yoki
kamayuvchi tartibda emas");
}
}

// .NET can only read single characters or entire lines from the
// console. The following function safely reads a double value.
private static double inputValue()
{
double result;
while (![Link]([Link](), out result));
return result;
}
}
Dastur kodi: Natija:

using System; Kiruvchi qiymat: Chiquvchi qiymat:


Input Output:
public class MyProgram
{
public static void Main(string[] args)
{
int son, yuzlik, onlik, birlik, engkatta;

son = (int) inputValue();


yuzlik = (int) ((double) son / 100);
onlik = (double) son / 10 % 10;
birlik = son % 10;
engkatta = yuzlik;
if (onlik > engkatta)
{
engkatta = onlik;
}
else
{
if (birlik > engkatta)
{
engkatta = birlik;
}
}
[Link](engkatta);
}

// .NET can only read single characters or entire lines from


the
// console. The following function safely reads a double
value.
private static double inputValue()
{
double result;
while (![Link]([Link](), out result));
return result;
}
}
Dastur kodi: Natija:

using System; Kiruvchi qiymat: Chiquvchi qiymat:

public class MyProgram


{
public static void Main(string[] args)
{
int yosh, onlik, birlik;
string onlikmatn, birlikmatn;
Input Output:
yosh = (int) inputValue();
onlik = (int) ((double) yosh / 10); 20 Yigirma yosh
birlik = yosh % 10;
if (onlik == 2)
{
onlikmatn = "yigirma";
}
else
{
if (onlik == 3)
{
onlikmatn = "o'ttiz";
}
else
{
if (onlik == 4)
{
onlikmatn = "qirq";
}
else
{
if (onlik == 5)
{
onlikmatn = "ellik";
}
else
{
if (onlik == 6)
{
onlikmatn = "oltmish";
}
}
}
}
}
if (birlik == 0)
{
birlikmatn = " yosh";
}
else
{
if (birlik == 1)
{
birlikmatn = " bir yosh";
}
else
{
if (birlik == 2)
{
birlikmatn = " ikki yosh";
}
else
{
if (birlik == 3)
{
birlikmatn = " uch yosh";
}
else
{
if (birlik == 4)
{
birlikmatn = " to'rt yosh";
}
else
{
if (birlik == 5)
{
birlikmatn = " besh yosh";
}
else
{
if (birlik == 6)
{
birlikmatn = " olti yosh";
}
else
{
if (birlik == 7)
{
birlikmatn = " yetti yosh";
}
else
{
if (birlik == 8)
{
birlikmatn = " sakkiz yosh";
}
else
{
if (birlik == 9)
{
birlikmatn = " to'qqiz yosh";
}
}
Dastur kodi: Natija:

using System; Kiruvchi qiymat: Chiquvchi


qiymat:
public class MyProgram Input Output:
{
public static void Main(string[] args)
{
[Link]("4 honali kirit:");
int a;

a = (int) inputValue();
int b;

b = (int) ((double) a / 1000);


int c;

c = (double) a / 100 % 10;


int d;

d = (double) a / 10 % 10;
int e;

e = a % 10;
if (b == 3 || e == 3)
{
[Link]("Ishtirok etgan");
}
else
{
[Link]("Ishtirok etmagan");
}
}

// .NET can only read single characters or entire lines from the
// console. The following function safely reads a double value.
private static double inputValue()
{
double result;
while (![Link]([Link](), out result));
return result;
}
}
Dastur kodi: Natija:

using System; Kiruvchi qiymat: Chiquvchi


qiymat:
public class MyProgram
{ Input Output:
public static void Main(string[] args)
{
int a, b, c, d, max, min, yigindi, farq;

a = (int) inputValue();
b = (int) inputValue();
c = (int) inputValue();
d = (int) inputValue();
max = a;
min = a;
if (b > max)
{
max = b;
}
else
{
if (c > max)
{
max = c;
}
else
{
if (d > max)
{
max = d;
}
}
}
if (b < min)
{
min = b;
}
else
{
if (c < min)
{
min = c;
}
else
{
if (d < min)
{
min = d;
}
}
}
if (a == b && b == c && c == d)
{
yigindi = a + b + c + d;
[Link]("Yig‘indi: " + yigindi);
}
else
{
farq = max - min;
[Link]("Farq: " + farq);
}
}

// .NET can only read single characters or entire lines from


the
// console. The following function safely reads a double
value.
Dastur kodi: Natija:

using System; Kiruvchi qiymat: Chiquvchi


qiymat:
public class MyProgram Input Output:
{
public static void Main(string[] args)
{
int a, b, c, kopaytma;

a = (int) inputValue();
b = (int) inputValue();
c = (int) inputValue();
if (a == b && a == c && b == c)
{
kopaytma = 0;
}
else
{
if (a == b && a == c)
{
kopaytma = a;
}
else
{
if (a == b || a == c)
{
kopaytma = b * c;
}
else
{
if (b == c || a == c)
{
kopaytma = a * c;
}
else
{
kopaytma = a * b * c;
}
}
}
}
[Link]("Ko‘paytma: " + kopaytma);
}

// .NET can only read single characters or entire lines from


the
// console. The following function safely reads a double
value.
private static double inputValue()
{
double result;
while (![Link]([Link](), out
result));
return result;
}
}

You might also like