Chiziqli dastur Misol 1
1.// To`ri to`rtburchakni yuzuni topuvchi dastur
Dastur kodi:
#include
#include
using namespace std;
int main(int argc, char** argv) {float a,b,s;
cout<<"a";
cin>>a;
cout<<"b";
cin>>b;
s=a*b;
cout<<"s ni qiymati s="<return 0;
Natija:
}
CHiziqli dastur.Masala 2
2.Berilgan a va b sonini o'rta arifmetigini topuvchi dastur tuzing.
Dastur kodi :
#include
using namespace std;
int main(){
int a, b;
float c;
cout<<" a= "; cin >> a;
cou t<< "b= "; cin >> b;
c = (float) (a+b)/2.0;
cout<< "c="<<(float)c<
return 0;} Natija:
Tarmoqlanuvchi dastur.Masala .3
3. //Berilgan a sonini juft yoki toq son ekanligini aniqlovchi dastur tuzing.
Dastur kodi:
#include
#include
using namespace std;
int main()
{ int a;
cout<<"a=";cin>>a;
if(a%2==0)
cout <<"Juft";
else cout<<"Toq";
return 0;} Natija:
Tarmoqlanuvchi dastur.Masala .4
4. // OX va OY kordenata uqlarida yotmaydegan nuqta berilgan.Nuqta joylashgan kordenata choragi aniqlansin.
Dastur kodi:
#include
using namespace std;
int main()
{int x, y,chorak=0;
cout<<"Nuqtaning kordenatalarini kiriteng"<
cout<<"x=";cin>>x;
cout<<"y=";cin>>y;
if(x>0 && y>0)chorak=1;
if(x<0 && y>0)chorak=2;
if(x<0 && y<0)chorak=3;
if(x>0 && y<0)chorak=4;
if(chorak==0)cout<<"Nuqta kordinatalar o'qida yotadi"<
else cout<
return 0;
} Natija:
Takrorlanuvchi dastur. Masala 5.
5.// Kiritilgan n songacha sonlarni kvadrat yig'indisini hisoblash.
Dastur kodi:
#include
using namespace std;
int main()
{int n;
cout<<"n=";cin>>n ;
int i=1,p=0;
while (i<=n) {
p+=i*i;
i++;
}cout <<"n gacha kvadratlar yig'indisi"<
return 0;} Natija:
Takrorlanuvchi dastur.Masala 6.
6. // Kiritilgan son 3 ning nechinchi darajasi ekanini chiqaradigan dastur tuzing.
Dastur kodi:
#include
using namespace std;
int main()
{
int n,sanagich=0,a=1;
cout<<"n=";cin>>n;
while (a<=n) {
a*=3;
sanagich++;}
cout<<"son 3 ning"<
return 0;
} Natija:
Funksiya.Masala 7.
7. Uchburchak gipotenuzasini hisoblash.
Dastur kodi:
#include
#include
using namespace std;
float hisobla( float , float );
int main()
{float c;
c=hisobla(3,4);
cout <<"c1="<
c=hisobla(6,8);
cout<<"c2="<
c=hisobla(12,5);
cout<<"c3="<
return 0;
}
float hisobla (float a, float b){
float s;
s = sqrtf(a*a+b*b);
return s ;
} Natija:
Takrorlanuvchi.masala 8.
8. Ikkita sonning o`rnini alamshtiruvchi dastur.
#include
using namespace std;
int urinalmashtirish (int a, int b)
{int r;
r=a; a=b; b=r;
cout<<"x="<
return 0;
}
int main()
{int x,y;
cout<<"x=";cin>>x;
cout<<"y=";cin>>y;
cout<
return 0;
} Natija:
Massiv. Massiv. 9
9.//Berilgan massiv elimentigacha bulgan qiymatlar yig'imdisini toping.
Dastur kodi:
#include
using namespace std;
Int main()
{
int s=0;
int a[10];
for(int i=0;i<10;i++){
cout << "a [" <
cin >> a [i];
s=s+a [i];
}
cout<<"Massivning yig'indisi="<
return 0; }
Natija:
Massiv.Masala 10.
10 .//n ta elementdan tashkel topgan massiv berilgan.Uning elementlarini teskari tartibda chiqaruvchi programma tuzilsin.
Dastur kodi:
#include
#include
using namespace std;
int main()
{int n, a[10];
cout <<" n = "; cin >> n;
for (int i=0;i
cout<<"a["<
cin>>a[i];}
cout << "Massiv elimentlarini teskari tartibda chiqarish" << endl;
for(int i=n-1; i>=0; i--)
cout<
return 0;
Natija:
0>0>
Dostları ilə paylaş: |