2 topshiriq
1. A butun soni berilgan. Jumlani rostlikka tekshiring: “A soni juft son”.
Yechilishi C++
#include
using namespace std;
int main(int argc, char** argv) {
int A;
cout<<"A=";cin>>A;
if(A%2==0)
{
cout<<"A juft son";
}
else {
cout<<" Juft emas?";
}
return 0;
}
|
Javobi
Konsoldan A ga qiymat beramiz
A=26
A juft son
A=19
Juft emas?
...Program finished with exit code 0
Press ENTER to exit console.
|
2. A, B va C sonlari berilgan. Jumalani rostlikka tekshiring: “A
Yechilishi C++
#include
using namespace std;
int main(int argc, char *argv[])
{
int A, B, C;
cout << "A=";
cin >> A;
cout << "B=";
cin >> B;
cout << "C=";
cin >> C;
if (C > A && C > B && B>A)
{
cout << " Tengsizlik orinli ✓";
}
else
{
cout << " orinli emas";
}
return 0;
}
|
Javobi
Konsoldan o’qib olamiz
A=4
B=6
C=12
Tengsizlik orinli ✓
A=8
B=4
C=9
orinli emas
...Program finished with exit code 0
Press ENTER to exit console.
|
3. A va B sonlari berilgan. Jumlani rostlikka tekshiring: “A va B larning faqat bittasi toq son”
Yechilishi C++
#include
using namespace std;
int main(int argc, char** argv) {
int A,B;
cout<<"A=";cin>>A;
cout<<"B=";cin>>B;
if(A%2==0 && B%2==1)
{
cout<<"B Toq son";
}
else if(A%2==1 &&B%2==1) {
cout<<" 2 alasi toq son";
}
else if(B%2==0 && A%2==1){
cout<<"A toq son "<}
else if(A%2==0 && B%2==0){
cout<<" Ikkalasi juft son";
}
return 0;
}
|
Javobi:
Konsoldan o’qib olamiz
A=4
B=5
B Toq son
A=5
B=6
A toq son
A=6
B=10
Ikkalasi juft son
...Program finished with exit code 0
Press ENTER to exit console.
|
4.
Yechilishi C++
#include
using namespace std;
int main(int argc, char** argv) {
int A,B,C;
cout<<"A=";cin>>A;
cout<<"B=";cin>>B;
cout<<"C=";cin>>C;
if(A>=0 && B>=0 && C>=0)
{
cout<<"Hammasi Musbat son";
}
else {
cout<<" Hammasi musbat emas";
}
return 0;
}
|
Javobi:
A=5
B=-3
C=3
Hammasi musbat emas
A=8
B=4
C=2
Hammasi Musbat son
...Program finished with exit code 0
Press ENTER to exit console.
|
5.
Yechilishi C++
#include
using namespace std;
int main()
{
int x,y, chorak=0;
cout<<" x = "; cin>>x;
cout<<" y = "; cin>>y;
if(x<0&&y>0) chorak=2;
if(x<0&&y<0) chorak=3;
cout << " \n Koordinata " << chorak << "-chorakda \n "<main();
return 0;
}
|
Javobi:
x = 7
y = 4
Koordinata 0-chorakda
...Program finished with exit code 0
Press ENTER to exit console.
|
Do'stlaringiz bilan baham: |