C++ tilida takrorlanuvchi jarayonlar dasturlar tuzish. For,while va do while takrorlash operatorlari. lab
Labaratoriya №2 Mavzu: C++ tilida takrorlanuvchi jarayonlar dasturlar tuzish. For,while va do while takrorlash operatorlari. Misollar
1. Misol. (Namuna) Butun son berilgan agar a>0 bo’lsa a+1 aks holsa a hisoblansin. #include <iostream.h> #include <math.h> int main () { int a; cin>>a; if(a>0){a++;} cout<<a; return 0; } Javob: 1-misol. Dastur kodi: #include <iostream> using namespace std; int main() { int n; double s=0; cin>>n; for(int i=1; i<=n; i++) { s+=1./i; } cout<<s; return 0; }
Natija: 2-misol. Dastur kodi: #include <iostream> using namespace std; int main() { int n, s=0; cin>>n; for(int i=n; i<=2*n; i++) { s+=i*i; } cout<<s; return 0; }
Natija: 3-misol. Dastur kodi: #include <iostream> using namespace std; int main() { int n; double p=1,k=1; cin>>n; for(int i=1; i<=n; i++) { k+=0.1; p*=k; } cout<<p; return 0; }
Natija : 4-misol. Dastur kodi: #include <iostream> using namespace std; int main() { double A, p; int n; cin>>A; cin>>n; p=A; for(int i=1; i<=n; i++) { cout<<p<<" "; p*=A; } return 0; }