Kodi: #include


Download 1.96 Mb.
Sana13.02.2023
Hajmi1.96 Mb.
#1193598
Bog'liq
Boytorayeva Mohichehra


1-Vazifa while takrorlash operatori
1-topshiriq
6.A.

Kodi:
#include
#include
using namespace std;
int main ()
{ int n,x,S=0,i=1;
float Pi=3.1415;
cout<<"n ning qiymatini kiriting n="; cin>>n;
cout<<"x ning qiymatini kiriting x="; cin>>x;
while(i S+=(pow(x,i)*cos(i*Pi/3))/i;
i++; }
cout<<"Natija -> "<return 0;
}

23.B


Kodi
#include
#include
using namespace std;
int main ()
{int n=1; double x, m,S=1;
cout<<"m="; cin>>m;
cout<<"x="; cin>>x;
while(n<=m)
{S*=pow(-1,n+1)*pow(x,2*n)/(2*n*(2*n-1)); n++;}
cout<<"S="<return 0;
}

2-toshiriq


1.Birinchi elementi bir bo’lgan, qolgan ixtiyoriy elementi o’zidan oldingiz elementlar yig’indisiga teng bo’lgan ketma-ketlikning n-hadi qiymatini aniqlovchi rekursiv algoritmini tuzing.
Kodi:
#include
using namespace std;
int main()
{
int n, i=2, r = 1;
cout<<"n = "; cin>>n;
if(n == 1 || n == 2)
cout<<1;
else{
while(ii++;
r*=2;
}
cout<}
return 0;
}


2. Birinchi elementi bir bo’lgan, qolgan ixtiyoriy elementi o’zidan oldingiz elementlar
Kvadratlarining yig’indisiga teng bo’lgan ketma-ketlikning n-hadi qiymatini aniqlovchi rekursiv algoritmini tuzing.
Kodi:
#include
using namespace std;

long long top(int n){


if(n == 1)return 1;
long long natija = 0, i = n - 1;
while(i >= 1){
long long ai = top(i);
natija += ai * ai;
i -= 1;
}
return natija;
}

int main()


{
int n;
cout<<"n = ";
cin>>n;
cout<

return 0;


}


3. a haqiqiy va n butun berilgan(n ). Shu a soning n-darajaga ko’taruvchi rekursiv algoritmini tuzing.
Kodi:
#include
using namespace std;
double daraja(double a, int n){
if(n == 0)return 1;
double yarim = daraja(a, n / 2);
double natija = yarim * yarim;
if(n % 2)natija *= a;
return natija;
}
int main()
{

double a;


int n;
cout<<"a = ";
cin>>a;
cout<<"n = ";
cin>>n;
cout<return 0;
}


3-toshiriq

  1. Y=

Kodi:
#include
#include
using namespace std;
int main ()
{ double n,s; int i=n;
cout<<"n ning qiymatini kiriting "; cin>>n;
s=sqrt(pow(3*n,2));
n=n-1;
while (i>0)
{
s=sqrt(s+3*i); i=n; i--;
}
cout<<"S="<return 0;
}



  1. Y=

Kodi:
#include
#include
using namespace std;
int main ()
{ double n,s; int i=n;
cout<<"n ning qiymatini kiriting "; cin>>n;
s=sqrt(pow(3*n,3));
n=n-1;
while (i>0)
{
s=sqrt(s+3*i); i=n; i--;
}
cout<<"S="<return 0;
}


2-Vazifa do-while takrorlash operatori


1-topshiriq
23.A

:

#include


#include
using namespace std;
int main()
{
double s =1, i=1;
do{
s+=(i+6)/(pow(i,4)+24*i+27); i++;
} while(i<=17);
cout<<"natija: "<return 0;}
}
23.B


#include
#include
using namespace std;
int main()
{
double n=1,p =1;
do{
p *= (n+6)/(n*n+4*n); n++;
} while(n<=8);
cout<<"natija: "<
return 0;}

23.C


Kodi:
#include
#include
using namespace std;
int main()
{
double m=-12,p =1;
do{
p *= (m+2)/(m*m+4*m); m++;
} while(m<=0);
cout<<"natija: "<
return 0;}
2-toshiriq do-while такрорлаш оператори ёрдамида дастурини тузинг

Kodi:
#include
#include
using namespace std;
int main()
{ double s=0, x0, xn,N,x;
cout<<"x0="; cin>>x0;
cout<<"xn="; cin>>xn;
cout<<"N="; cin>>N;
x=(xn-x0)/N;
do {s+=2*cos(x*x*x); x++;}
while(x<=xn);
cout<<"s="<return 0; }

3-topshiriq

Kodi:
#include
#include
using namespace std;
int main()
{ double s, p, n,S,x=1;

cout<<"n="; cin>>n ;


do {
s+=x; p+=x*x; x++;}


while(x<=n);
S=s-p;
cout<<"S="<return 0; }

Download 1.96 Mb.

Do'stlaringiz bilan baham:




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