|
Shartli operatorga doir tarmoqlanuvchi algoritmga misol
|
bet | 43/135 | Sana | 22.05.2024 | Hajmi | 15,08 Mb. | | #250347 |
Bog'liq Fizik jarayonlarni kompyuterda modellashtirishShartli operatorga doir tarmoqlanuvchi algoritmga misol.
C++ tilida tarmoqlash operatoridan farqli shart bo’yicha o’zlashtirish (yoki shartli o‟zlashtirish) operatori ham bo‟lib, uning ko‟rinishi quyidagicha: o’zgaruvchi = (shart) ? ifoda1: ifoda2;
Tarmoqlanuvchi algoritmga misol.
Masala: Elektr zanjiridagi tok manbai klemmalaridagi kuchlanish U=100 v bo`lib, qarshiliklari R1=5 a va R2=4 a bo`lgan iste‟molchilar ketma-ket va parallel ulangan holda tok kuchlari qanday bo`lishini aniqlash dasturini tuzing.
Misol dasturi:
1 # include
2 # include
3 using namespace std;
5 int main()
6 {
7 float R1,R2,R,I,U;
8 string s;
9 cout<<"Tok manbai klemmalaridagi kuchlanishni kiriting:=U”;
10 cin>>U;
11 cout<<"Birinchi istemolchi qarshiligini kiriting:=R1”;
12 cin>>R1;
13 cout<<"Ikkinchi istemolchi qarshiligini kiriting:=R2”;
14 cin>>R2;
15 cout<<"Istemolchilar ulanish turini kiriting:=s”;
16 cin>>s;
17 if (s=="parallel")
18 {
19 R=R1*R2/(R1+R2); I=U/R;
20 }
21 if (s=="ketmaket")
22{
23 R=R1+R2; I=U/R;
24 }
25 cout<<"Istemolchilar "<
C++da
|
Pythonda
|
Ixtiyoriy butun tok qiymati noldan katta bo’lsa tok bor yoki yoqligini hisoblash dasturini tuzing.
|
1 # include
2 # include
3 using namespace std;
4 int main()
5{
6 int i;
7 cout<<(“tok kuchini kiriting: i=”)
8 if (i>0))
9 cout<<(“Tok kuchi bor ”)
else
10 cout<<(“Tok kuchi yo’q”);
11 return 0;
12 }
|
1 print (‘i tok kuchi qiymatini kiriting’)
2 i=int(input())
3 if i>0:
4 print(‘tok kuchi bor’)
else
5 print(‘tok kuchi yo’q’)
|
| |
|