O’zbekiston respublikasi axborot texnologiyalari


Download 47.15 Kb.
Sana05.01.2022
Hajmi47.15 Kb.
#226744
Bog'liq
Dasturlash top 5

    Bu sahifa navigatsiya:
  • Gurux

O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI

VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI

MUHAMMAD AL-XORAZMIY NOMIDAGI

TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI



Programming I(c++) fani bo’yicha

Gurux : 417-20

Bajardi : Solijonov D. Q.

Tekshirdi: Mo’minov B.B.



  1. Berilgan sonni kubini topadigan funksiya yarating. Ushbu funksiya yordanida a,b,c,d sonlarini kubini hisoblang.

Dastur:

#include

using namespace std;

float Kub1(int &x){

x = x*x*x;

}

int Kub2(int x){



return x*x*x;

}

int main(){



int a,b,c,d,x;

cout << "a = "; cin >> a;

cout << "b = "; cin >> b;

cout << "c = "; cin >> c;

cout << "d = "; cin >> d;

Kub1(a);

cout << "a ni Kubi " << a << endl;

Kub1(b);

cout << "b ni Kubi " << b << endl;

Kub1(c);

cout << "c ni Kubi " << c << endl;

Kub1(d);

cout << "d ni Kubi " << d << endl;

cout << "-------------------------------------------------------------------------------------\n";

cout << "a = "; cin >> a;

cout << "b = "; cin >> b;

cout << "c = "; cin >> c;

cout << "d = "; cin >> d;

/*cout << "a ni kubi = " << Kub2(a) << endl;

cout << "b ni kubi = " << Kub2(b) << endl;

cout << "c ni kubi = " << Kub2(c) << endl;

cout << "d ni kubi = " << Kub2(d) << endl;*/



}

Natija:



b)Berilgan ikkita sonni “do’st son” larga tekshiradigan funksiya yarating. Ushbu funksiya yordamida a va a1, b va b1, c va c1 sonlarini o’zaro do’stlikka tekshiring. Izoh: do’st sonlar deb birinchi sonning bo’luvchilari yig’indisi ikkinchi sonni, ikkinchi sonni bo’luvchilari soni birinchi sonni tashkil qilgan sonlar juftiga aytiladi.

Dastur:

#include

#include

using namespace std;

int main(){

int a,a1,b,b1,c,c1;

int sa=0,sb=0,sc=0,ka=0,kb=0,kc=0,min,max;
cout << "a = "; cin >> a;

cout << "a1 = "; cin >> a1;

cout << "b = "; cin >> b;

cout << "b1 = "; cin >> b1;

cout << "c = "; cin >> c;

cout << "c1 = "; cin >> c1;

if(a>a1){ min = a1; max = a;}

else { max = a1; min = a;}

for(int i=1; i<=min; i++) if(min%i==0) sa+=i;

for(int i=1; i<=max; i++) if(max%i==0) ka++;

if(sa==max && ka==min) cout << a << " & " << a1 << " - dust sonlar" << endl;

else cout << a << " & " << a1 << " - dust sonlar emas ! " << endl;

// ------------------------------------------------------------------------------------

if(b>b1){ min = b1; max = b;}

else { max = b1; min = b;}

for(int i=1; i<=min; i++) if(min%i==0) sb+=i;

for(int i=1; i<=max; i++) if(max%i==0) kb++;

if(sb==max && kb==min) cout << b << " & " << b1 << " - dust sonlar" << endl;

else cout << b << " & " << b1 << " - dust sonlar emas ! " << endl;

//--------------------------------------------------------------------------------------

if(c>c1){ min = c1; max = c;}

else { max = c1; min = c;}

for(int i=1; i<=min; i++) if(min%i==0) sc+=i;

for(int i=1; i<=max; i++) if(max%i==0) kc++;

if(sc==max && kc==min) cout << c << " & " << c1 << " - dust sonlar" << endl;

else cout << c << " & " << c1 << " - dust sonlar emas ! " << endl;



}

Natija:



Download 47.15 Kb.

Do'stlaringiz bilan baham:




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