5. A(5) vektornining eng kichigini va element nomerini topish dasturi ?
//---------------------------------------------------------------------------
#include
#include
#include
#pragma hdrstop
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
int a1,a2,a3,a4,a5,m,s;
int maxx(int a, int b){
if(a>b)
return b;
else
return a;}
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner){}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender){
vector vektor;
a1 = Edit1->Text.ToInt();
a2 = Edit2->Text.ToInt();
a3 = Edit3->Text.ToInt();
a4 = Edit4->Text.ToInt();
a5 = Edit5->Text.ToInt();
vektor.push_back(a1);
vektor.push_back(a2);
vektor.push_back(a3);
vektor.push_back(a4);
vektor.push_back(a5);
m = maxx(maxx(maxx(a1,a2),maxx(a3,a4)),a5);
for(int i=0; i<5; i++){
if(m==vektor.at(i))
{s = i;
break; }
}
Edit6->Text = m;
Edit7->Text = s;
}
//---------------------------------------------------------------------------
6.Sonni ikkilik sanoq sistemasidan o’nlik sanoq sistemasiga o‘tkazuvchi dastur tuzing.
using System;
namespace Sanoq_sistemasi_1
{
class Program
{
public static void Main(string[] args)
{
Console.Write("Sanoq sistemasi!");
int k,i;
double s=0;
Console.Write("Ikkilik sanoq sistemasidagi sonni kiriting: n= ");
k=int.Parse(Console.ReadLine());
int [] a=new int[120];
int j=k;
for(i=0;k!=0;i++)
{
a[i]=j%10;
k=k/10;
j=k;
s+=a[i]*Math.Pow(2,i);
}
Console.WriteLine(s);
Console.ReadKey(true);
}
}
}
Natija:
Do'stlaringiz bilan baham: |