4.1-topshiriq 1-masala
def yigindi(a,b):
return (a+b)
natija=0
n=int(input("sonlar soni -->> "))
sonlar=[35,8,18,3,22]
for i in range(n):
sonlar[i].add(int(input()))
k=int(input("2 tasi yig'indisi nechaga teng bo'lsin = "))
for i in range(n):
j=i
for j in range(n):
if (yigindi(sonlar[i],sonlar[j]==k)):
natija=1
break
else:
natija=0
if (natija==1):
print("TRUE")
else:
print("FALSE")
2 masala
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
public static int yig(int a, int b, int c, int d)
{
return (a + b + c + d);
}
static void Main(string[] args)
{
int sanoq=0;
Console.Write("saylanishlar soni = "); int n = Convert.ToInt32(Console.ReadLine());
string[] Votes = new string[n];
Console.WriteLine("'candidate_id, voter_id' shu uslda kiriting");
for (int i = 0; i < n; i++)
{
Votes[i] = Console.ReadLine();
}
for (int i = 0; i < n; i++)
{
for (int j = i+1; j < n; j++)
{
if (Votes[i] == Votes[j]) sanoq++;
}
}
Console.WriteLine(sanoq);
if (!(sanoq == 0)) Console.WriteLine("True");
else Console.WriteLine("False");
Console.ReadKey(true);
}
}
}
3 masala
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
public static int yig(int a, int b, int c, int d)
{
return (a + b + c + d);
}
static void Main(string[] args)
{
string sonlar = "";
string natijalar="";
int sanoq=0;
Console.WriteLine("sonlar ro'yharlarni to'ldiring ixtiyoriy");
Console.WriteLine("har bir ruyhat elemetlari 1 satrda kiriting");
Console.WriteLine("A ruyhat elemetlarini kiriting");
sonlar = Console.ReadLine(); List a = new List(sonlar.Split(' '));
Console.WriteLine("B ruyhat elemetlarini kiriting");
sonlar = Console.ReadLine(); List b = new List(sonlar.Split(' '));
Console.WriteLine("C ruyhat elemetlarini kiriting");
sonlar = Console.ReadLine(); List c = new List(sonlar.Split(' '));
Console.WriteLine("D ruyhat elemetlarini kiriting");
sonlar = Console.ReadLine(); List d = new List(sonlar.Split(' '));
Console.Write("maqsadni kiriting = "); int maq = Convert.ToInt32(Console.ReadLine());
foreach (var i in a)
{
foreach (var j in b)
{
foreach (var k in c)
{
foreach (var l in d)
{
var natija = yig(Convert.ToInt32(i), Convert.ToInt32(j), Convert.ToInt32(k), Convert.ToInt32(l));
if (natija==maq)
{
natijalar+="["+i+", "+j+", "+k+", "+l+"]\n";
sanoq++;
}
}
}
}
}
Console.WriteLine("Dastur natijasi = "+sanoq);
Console.WriteLine("tushunish uchun\n"+natijalar);
Console.ReadKey(true);
}
}}
4 topshiriqit
1 – masala
import java.util.Scanner;
public class test {
public static void main(String[] args) {
int n;
Scanner kirit = new Scanner(System.in);
System.out.print("list uzunligini kiriting >> ");
n = kirit.nextInt();
int[] list = new int[n];
for(int i=0; iSystem.out.print("list["+(i+1)+"] >> ");
list[i] = kirit.nextInt();
}
boolean holat = false;
int l=0;
for (int i = 0; i < n-1; i++) {
if(!(list[i]holat = true;
break;
}
}
public static void main(String[] args) {
int n;
Scanner kirit = new Scanner(System.in);
System.out.print("list uzunligini kiriting >> ");
n = kirit.nextInt();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
public static int yig(int a, int b, int c, int d)
{
return (a + b + c + d);
}
static void Main(string[] args)
{
Console.Write(""); string manba = Console.ReadLine();
double s = 0;
List ikkilik = new List(manba.Split(' '));
for (int i = ikkilik.Count-1,j=0; i >= 0; j++,i--)
{
s += Convert.ToDouble(ikkilik[i])*Math.Pow(2, j);
}
Console.WriteLine("Dastur natijasi = " + s);
Console.ReadKey(true);
}
}
}
4 misol
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write(""); string manba = Console.ReadLine();
List tuplam = new List(manba.Split(' '));
Console.Write("maqsad = "); string maqsad = Console.ReadLine();
foreach (var indek in tuplam)
{
if (!(indek == maqsad))
{
Console.Write(indek + " ");
}
}
Console.ReadKey(true);
}
}
}