Muhammad al Horazmiy nomidagi Toshkent Axborot Texnologiyalari universiteti
1 – bosqich talabasining
“Dasturlash 1” fanidan
4 – Labaratoriya ishi.
Tekshirdi. Ablaqulov K. _________.
Bajardi. Risqulov O. _________.
Masala: 1. k va n (n>0) butun sonlar berilgan. N marta k soni chiqarilsin.
Yechilishi:
#include
#include
using namespace std;
int main(){
int n, k, i, j;
cout<<"Sonni kiriting: "; cin>>k;
cout<<"Necha marta chiqarilsin: "; cin>>n;
for(int i=1; i<=n; i++){
cout<
}
return 0;
}
Natija:
Sonni kiriting: 7
Necha marta chiqarilsin: 3
7 7 7
Masala: 2. a va b butun sonlar berilgan(a>b). a va b sonlari orasidagi sonlarni o'sish tartibida chiqarilsin(a va b sonlari ham kiradi) hamda shu sonlar miqdori (soni) n chiqarilsin.
Yechilishi:
#include
#include
using namespace std;
int main(){
int a, b, i, j;
cout<<" a ni kiriting: "; cin>>a;
cout<<" b ni kiriting: "; cin>>b;
for(int i=b; i<=a; i++){
cout<
}
cout<<"\n"<
return 0;
}
Natija:
a ni kiriting: 5
b ni kiriting: 2
2 3 4 5
4
Masala: 3 a va b butun sonlar berilgan(a
Yechilishi:
#include
#include
using namespace std;
int main(){
int a, b, i, j;
cout<<" a ni kiriting: "; cin>>a;
cout<<" b ni kiriting: "; cin>>b;
for(int i=b; i>=a; i--){
cout<
}
cout<<"\n"<
return 0;
}
Natija:
a ni kiriting: 3
b ni kiriting: 7
7 6 5 4 3
5
Masala: 4. 1 kg konfetning narxi haqiqiy sonda berilgan. 1,2,..., 10 kg konfetning bahosi chiqarilsin.
Yechilishi:
#include
#include
using namespace std;
int main(){
float a, i, x;
cout<<"1 kilogram konfetning narxini kiriting: "; cin>>a;
for(float i=1; i<=10; i++){
x=i*a;
cout<
}
return 0;
}
Natija:
1 kilogram konfetning narxini kiriting: 1
1 2 3 4 5 6 7 8 9 10
Masala: 5.1 kg konfetning narxi berilgan. 0,1. 0,2, ..., 1 kg konfetning bahosi chiqarilsin.
Yechilishi:
#include
#include
using namespace std;
int main(){
float a, i, x;
cout<<"1 kilogram konfetning narxini kiriting: "; cin>>a;
for(float i=1; i<=10; i++){
x=i*a/10;
cout<
}
return 0;
}
Natija:
1 kilogram konfetning narxini kiriting: 10
1 2 3 4 5 6 7 8 9 10
Masala: 6.1 kg konfetning narxi berilgan. 1,2, 1,4,..., 2 kg konfetning bahosi chiqarilsin.
Yechilishi:
#include
#include
using namespace std;
int main(){
float a, i, x;
cout<<"1 kilogram konfetning narxini kiriting: "; cin>>a;
for(float i=1; i<=5; i++){
x=(1+i/5)*a;
cout<
<<"\t";
}
return 0;
}
Natija:
1 kilogram konfetning narxini kiriting: 10
12 14 16 18 20
Masala: 7.2 ta a va b butun sonlar berilgan. (a
Yechilishi:
#include
#include
using namespace std;
int main(){
int a, i, b, x;
cout<<"a sonini kiriting: "; cin>>a;
cout<<"b sonini kiriting: "; cin>>b;
if(a
for(int i=a; i<=b; i++){
x=x+i;
}
cout<
};
if(a>b||a<0||b<0||a==b){
cout<<"a soni b dan kichik bo'lsin va albatta musbat.";
};
return 0;
}
Natija:
a sonini kiriting: 2
b sonini kiriting: 5
14
Masala: 8.2 ta a va b butun sonlar berilgan. (a
Yechilishi:
Natija:
Masala: 9. a va b butun sonlar berilgan. (a
Yechilishi:
#include
#include
using namespace std;
int main(){
int a, i, b, x;
cout<<"a sonini kiriting: "; cin>>a;
cout<<"b sonini kiriting: "; cin>>b;
if(a
for(int i=a; i<=b; i++){
x=x+i*i;
}
cout<
};
if(a>b||a<0||b<0||a==b){
cout<<"a soni b dan kichik bo'lsin va albatta musbat.";
};
return 0;
}
Natija:
a sonini kiriting: 1
b sonini kiriting: 4
30
Masala: 10. n(n>0) butun soni berilgan 1+ 1 1 2 (Yigʻindi haqiqiy son). Yig'indi hisoblansin.
Yechilishi:
#include
#include
using namespace std;
int main(){
float n, i, x;
cout<<"n sonini kiriting: "; cin>>n;
if(n>0){
for(int i=0; ix=i+i/2.;
}
cout<
};
return 0;
}
Natija:
n sonini kiriting: 2
1.5
Masala: 11. n butun soni berilgan n²+(n+1)+(n+2)...+(2n). (Yigʻindi butun son). Yig'indi hisoblansin.
Yechilishi:
#include
#include
using namespace std;
int main(){
int n, i, x;
cout<<"n sonini kiriting: "; cin>>n;
if(n>0){
for(int i=0; i<=n; i++){
x+=pow((n+i),3);
}
cout<
};
return 0;
}
Natija:
n sonini kiriting: 2
99
Masala: 12. n butun soni berilgan 1,1-1,2-1.31,n) (n ta ko'paytuvchi). Ko'paytma 2 1.32 hisoblansin.
Yechilishi:
#include
#include
using namespace std;
int main()
{
float n,s=1,b=1.1;
cin>>n;
for(int i=0; i
s=s*b;b=b+0.1;
}
cout<
return 0;
}
Natija:
2
1.32
Masala: 13. n(n-0) butun soni berilgan. 1,1-1,2+1,3-... Ifodaning qiymati topilsin. Shart operatori qo'llanilmasin.
Yechilishi:
#include
#include
using namespace std;
int main()
{
float n,s;
cout<<"n sonini kiriting: "; cin>>n;
s=(n-1)*(-1)/10;
cout<
return 0;
}
Natija:
n sonini kiriting: 2
-0.1
Masala: 14. n(n>0) butun soni berilgan. Quyidagi formuladan foydalanib berilgan sonning kvadrati hisoblansin: n²=1+3+5+...+(2n-1). Har bir qadamdagi yig'indi chiqarilsin(natijada 1 dan n gacha bo'lgan butun sonlarning kvadrati chiqadi).
Yechilishi:
#include
#include
using namespace std;
int main(){
int n, i, x;
cout<<"n sonini kiriting: "; cin>>n;
if(n>0){
for(int i=1; i<=n; i++){
x=i*i;
cout<
}
};
return 0;
}
Natija:
n sonini kiriting: 4
1 4 9 16
Masala: 15. a haqiqiy va n butun sonlari berilgan(n>0). a"=a*a*…*a. (a, n marta ko'paytirilgan) a ning n- darajasi hisoblansin.
Yechilishi:
#include
#include
using namespace std;
int main(){
float a, y, x;
cout<<"a ni kiriting - "; cin>>a;
cout<<"a ni darajasini kiriting - "; cin>>x;
y = pow(a,x);
cout<
return 0;
}
Natija:
a ni kiriting - 1.5
a ni darajasini kiriting - 2
2.25
Masala: 16. a va n sonlari berilgan. Bitta sikldan foydalanib a sonining 1 dan n gacha boʻlgan darajalari chiqarilsin.
Yechilishi:
#include
#include
using namespace std;
int main(){
float a, n, i, x;
cout<<"a sonini kiriting: "; cin>>a;
cout<<"n sonini kiriting: "; cin>>n;
if(n>0){
for(int i=1; i<=n; i++){
x=pow(a,i);
cout<
}
};
return 0;
}
Natija:
a sonini kiriting: 2
n sonini kiriting: 3
2 4 8
Masala: 17. a va n sonlari berilgan. 1+a+a¹ + a² +...+an . Bitta sikldan foydalanib yig'indi hisoblansin.
Yechilshi:
#include
#include
using namespace std;
int main(){
float a, n, i, x;
cout<<"a sonini kiriting: "; cin>>a;
cout<<"n sonini kiriting: "; cin>>n;
if(n>0){
for(int i=0; i<=n; i++){
x+=pow(a,i);
}
cout<
};
return 0;
}
Natija:
a sonini kiriting: 3
n sonini kiriting: 3
40.
Do'stlaringiz bilan baham: |