Masalaning C# dasturlash tilidagi matni


Download 1.79 Mb.
bet1/2
Sana19.06.2023
Hajmi1.79 Mb.
#1608778
  1   2
Bog'liq
topshiriq 19




1. Butun son berilgan. Berilgan sonni “musbat toq son”,”manfiy juft son”, “son
nolga teng” va hakazoni ekranga yozuvchi dastur tuzilsin.
Masalaning C# dasturlash tilidagi matni:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication11


{
class Program
{
static void Main(string[] args)
{
double a;
Console.Write("Sonni kiriting: a= ");
a = double.Parse(Console.ReadLine());
if (a > 0 && a % 2 == 1) { Console.WriteLine("a toq musbat son"); }
else { if (a > 0 && a % 2 == 0) { Console.WriteLine("a juft musbat son"); } }
if (a < 0 && (-a) % 2 == 1) { Console.WriteLine("a toq manfiy son"); }
else { if (a < 0 && (-a) % 2 == 0) { Console.WriteLine("a juft manfiy son"); } }
Console.ReadKey(true);
}
}
}
Natija:



2. natural son berilgan. Quyidagi yig’indining qiymatini hisoblash dasturi
tuzilsin:





Mazkur masalani yechishda shart operatorlari hamda Math sinfi metodlaridan foydalanilmasin.

using System;


using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication12


{
class Program
{
static void Main(string[] args)
{
double n, S=0;
Console.Write("Sonni kiriting: n= ");
n = double.Parse(Console.ReadLine());
for (int i = 1; i < (n + 1); i++)
{
S += Math.Pow(i, n + 1 - i);
}
Console.WriteLine("Natija: " + S);
Console.ReadKey(true);
}
}
}
Natija:


3. o’lchamli massiv berilgan, barcha elementlari birinchi elementdan tashqari
o’sish tartibida. Birinchi elementni yangi o’ringa ko’chirilsin natijada o’sish
tartibida massiv hosil bo’lsin.
Masalaning C# dasturlash tilidagi matni:

using System;


using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication13


{
class Program
{
static void Main(string[] args)
{
int i = 0, n, k = 0; bool b = true; double c;
Console.Write("Massivlar elementlari sonini kiriting: n=");
n = int.Parse(Console.ReadLine());
double[] a = new double[n];
Console.Write("a[" + (i + 1) + "]=");
a[i] = Convert.ToDouble(Console.ReadLine()); c = a[0];
for (i = 1; i < n; i++)
{
Console.Write("a[" + (i + 1) + "]=");
a[i] = Convert.ToDouble(Console.ReadLine());
if (a[0] > a[i]) { k = i; b = false; }
}
if (!b) { for (i = 0; i < k; i++) a[i] = a[i + 1]; a[k] = c; }
else { Console.WriteLine("Massiv o'zi o'sish tartibida joylashgan."); }
for (i = 0; i < n; i++)
{
Console.Write(a[i] + " ");
}
Console.ReadKey();
}
}
}
Natija:


4. o’lchamli matritsa berilgan. Matritsaning faqat musbat elementdan tashkil topgan birinchi ustunini o’chirish dasturi tuzilsin. Agar bunday ustun bo’lmasa matritsa o’zgarishsiz qolsin.
Masalaning C# dasturlash tilidagi matni:

using System;


using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication14


{
class Program
{
static void Main(string[] args)
{
int m, n, i, j, k = 0;
bool h = true, b = true;
Console.Write("Matritsaning satrlari sonini kiriting: m=");
m = int.Parse(Console.ReadLine());
Console.Write("Matritsaning ustunlari sonini kiriting: n=");
n = int.Parse(Console.ReadLine());
double[,] a = new double[m, n];
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write("a[" + i + "," + j + "]=");
a[i, j] = double.Parse(Console.ReadLine());
}
}
for (j = 0; j < n; j++)
{
for (i = 0; i < m; i++) if (a[i, j] <= 0) h = false; if (h & b)
{ b = false; k = j; }
}
if (!b)
{
for (j = k; j < n - 1; j++) for (i = 0; i < m; i++) a[i, j] = a[i, j + 1];
for (i = 0; i < m; i++)
{
for (j = 0; j < n - 1; j++)
Console.Write(a[i, j] + "\t"); Console.WriteLine();
}
}
else for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
Console.Write(a[i, j] + "\t"); Console.WriteLine();
}
Console.ReadKey(true);
}
}
}

5. Turli tomonli uchburchakning bissektrisalarini aniqlovchi metodi hosil qilinsin. Bunda , va musbat haqiqiy sonlar kirish parametrlari bo’lib, uchburchakning tomonlarini ifodalasa, , va parametrlar mos ravishda uchburchakning mos bissektrisalarini ifodalovchi chiqish parametrlaridir. metodidan foydalanib kamida uchta uchburchakning bissektrisalari uzunliklari topilsin.



Download 1.79 Mb.

Do'stlaringiz bilan baham:
  1   2




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling