To’liq shartli sonli, mazmunli (mantiqli) tarmoqlanuvchi jarayonlarni algoritmlash va dasturlashtirish


Download 76.5 Kb.
Sana25.04.2023
Hajmi76.5 Kb.
#1399397
Bog'liq
6 С


6- МАЪРУЗА

To’liq shartli sonli, mazmunli (mantiqli) tarmoqlanuvchi jarayonlarni

algoritmlash va dasturlashtirish





  1. Ikkita sondan eng kattasini (kichigini) aniqlash algoritmi va dasturi.

  2. Uchta sondan eng kattasini (kichigini) aniqlash algoritmi va dasturi.

  3. To’rtta sondan eng kattasini (kichigini) aniqlash algoritmi va dasturi.

  4. Mazmunli shartli gaplarni algoritmi va dasturi.




  1. Ikkita sondan eng kattasini (kichigini) aniqlash algoritmi va dasturi.

1. Masalani matematik rasmiylashtirish:
Berigan sonlar: A va B. Eng kattasini topish Y=max{A,B}.

  1. Masalani echish algoritmi:

Birinchi variant:

//M6-1
// C++ da 2 ta sonni kattasini aniqlash


// dasturi if else buyrug'i bilan
#include
#include
#include
int main()
{
float a,b;
float y;
cout<<" a,b (float) sonlar"<cin>>a>>b;
cout<cout<<"a="<cout<<"b="<if (aelse cout<<"2 sonni kattasi "<return 0;
}

1. 2 ta sonni kattasini aniqlashning samarali algoritmi


//M6-2
// C++ da 2 ta sonni kattasini aniqlash


// dasturi if buyrug'i bilan
#include
#include
#include
int main()
{
float a,b;
float y;
cout<<" a,b (float) sonlar"<cin>>a>>b;
cout<cout<<"a="<cout<<"b="<y=a;
if (ycout<<"2 ta sonni kattasi y="<return 0;
}
2. 3 ta sonni kattasini aniqlashning samarali algoritmi

//M6-3
// C++ da 3 ta sonni kattasini aniqlash


// dasturi if buyrug'i bilan
#include
#include
#include
int main()
{
float a,b,c;
float y;
cout<<" a,b,c (float) sonlar"<cin>>a>>b>>c;
cout<cout<<"a="<cout<<"b="<cout<<"c="<y=a;
if (yif (ycout<<"3 ta sonni kattasi y="<return 0;
}
3. 4 ta sonni kattasini aniqlashning samarali algoritmi

//M6-4
// C++ da 4 ta sonni kattasini aniqlash


// dasturi if buyrug'i bilan
#include
#include
#include
int main()
{
float a,b,c,d;
float y;
cout<<" a,b,c,d (float) sonlar"<cin>>a>>b>>c>>d;
cout<cout<<"a="<cout<<" b="<cout<<" c="<cout<<" d="<y=a;
if (yif (yif (ycout<<"4 ta sonni kattasi y="<return 0;
}
4.Mazmunli shartli gaplarni algoritmi va dasturi.
Mazmunli misol.
Seshanba kuni C++ fanidan bo’ladigan nazoratga tayyorlanish uchun Boltaboynikiga boraman. Agar u uyida bo’lsa, u holda birga nazoratga tayyorlanamiz, aks holda Teshavoynikiga boraman. Teshavoy uyida bo’lsa birga tayyorlanamiz, bo’lmasa yakka o’zim tayyorlanaman.
Misolni qisqacha varianti: Agar Boltaboy yoki Teshavoy uyida bolsa seshanba kuni bo’ladigan C++ fanidan nazoratga birga tayyorlanar edim.

Mazmunli misolning algoritmi:




Algoritmni muloqotli varianti:




//M6-5
// C++ da mazmunli, shartli gapni


// dasturi if buyrug'i bilan
#include
#include
#include
int main()
{
float x;
cout<<" C++ fanidan nazoratga tayyorlanishim zarur"<cout<<" Boltaboy uydamisiz - HA - 1 , YOQ - 0 ";
cin>>x;
cout<if (x==1){cout<<"HA"<cout<<" Boltaboy bilan nazoratga tayyorlanaman"<goto mt;}
cout<<" YOQ"<cout<cout<<" Teshavoy uydamisiz - HA - 1 , YOQ - 0 ";
cin>>x;
cout<if (x==1){cout<<"HA"<cout<<" Teshavoy bilan nazoratga tayyorlanaman"<goto mt;}
cout<<" YOQ"<cout<cout<<"Na chora,nazoratga yakka o'zim tayyorlanishimga to'g'ri keladi"<mt:
return 0;
}
Misollar:

  1. Agar Boltaboy uyida bo’lsa, bo’sh vaqti bo’lsa katta tennis o’nar edik, aks holda Teshavoy bilan internet kafega boraman.

  2. Begun yomg’ir yog’sa uyda dars qilaman, yog’masa Natasha bilan bog’ sayriga boraman.

график чизмаларни алгоритмлаш:






Download 76.5 Kb.

Do'stlaringiz bilan baham:




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