for(int j=0;j
cout.width(3);
cout<
} cout<
return 0;
}
3-topshiriq
#include
#include
using namespace std;
void yasashga_tek(int a1, int b1, int a2,int b2,int a3,int b3){
if(((a1==a2)&&(a2==a3))||((b1==b2)&&(b2==b3))){
cout<<"To'rtburchak yasash mumkin emas!"<
}
else{
cout<<"To'rtburchak yasash mumkin !"<
}
}
void turga_tek(int a1, int b1, int a2,int b2,int a3,int b3,int a4,int b4){
int a,b,c,d;
a=sqrt(abs(a1-a2)*abs(a1-a2)+abs(b1-b2)*abs(b1-b2));
b=sqrt(abs(a2-a3)*abs(a2-a3)+abs(b2-b3)*abs(b2-b3));
c=sqrt(abs(a3-a4)*abs(a3-a4)+abs(b3-b4)*abs(b3-b4));
d=sqrt(abs(a4-a1)*abs(a4-a1)+abs(b4-b1)*abs(b4-b1));
if(a==c && b==d && a!=b){
cout<<"Bu to'rtburchak to'g'ri to'rtburchak!";
}
if(a==c && b==d && a==b){
cout<<"Bu to'rtburchak kvadrat!";
}
}
int main(){
int x1,x2,x3,x4;
int y1,y2,y3,y4;
cout<<"To'trburchakni A uchi: "; cin>>x1>>y1;
cout<<"To'trburchakni B uchi: "; cin>>x2>>y2;
cout<<"To'trburchakni C uchi: "; cin>>x3>>y3;
cout<<"To'trburchakni D uchi: "; cin>>x4>>y4;
yasashga_tek(x1,y1,x2,y2,x3,y3);
turga_tek(x1,y1,x2,y2,x3,y3,x4,y4);
_getwch();
return 0;
}
4-topshiriq
Quyidagi jadvalda berilgan nomli struktura yaratib, shu struktura nomli kamida 10 ta elementdan tashkil topgan bir o’lchovli massiv yaratib, massiv elementlariga matnli (input.txt) fayl orqali qiymat berilsin va 3-ustunda berilgan shart bo’yicha ma’lumotlar (output.txt) faylga chop qilinsin.
KORABL (ismi, suvsiljishi, turi, yoshi)
|
Shart: Yoshi>5
|
#include
#include
#include
using namespace std;
struct KORABL {
string Ismi;
int Suvsiljishi;
string Turi;
int Yoshi;
};
int main() {
KORABL a[10];
int n = 0;
ofstream yozish;
yozish.open("output.txt");
ifstream uqish;
uqish.open("input.txt");
if (!uqish.is_open()) {
cout << "Faylni ochishda xatolik sodir bo'ldi!" << endl;
exit(1);
}
while (!uqish.eof()) {
uqish >> a[0].Ismi;
uqish >> a[0].Suvsiljishi;
uqish >> a[0].Turi;
uqish >> a[0].Yoshi;
n++;
}
uqish.close();
for (int i = 0; i < 10; i++) {
if (a[i].Yoshi > 5)
yozish << a;
}
return 0;
}
5-topshiriq
char s[60];
Berilgan satrda polindrom so‘zlar mavjud bo‘lsa ular chop qilinsin, aks holda bunday so‘z yo‘qligi haqida xabar berilsin (satrdagi so‘zlar bir-biridan bitta yoki bir necha probel orqali ajratiladi).
#include
#include
#include
using namespace std;
int main (){
char a[10000];
gets(a);
stringstream kirit(a);
string s, x;
while(kirit >> s){
x = s;
reverse(x.begin(), x.end());
if(s == x) cout << s << endl; }
return 0;
}
6-topshiriq
#include
#include
using namespace std;
int main() {
string a;
string suz[100];
int k = 0,n;
getline(cin, a);
a = a + ' ';
while (a.find(' ') != string::npos) {
suz[k] = a.substr(0, a.find(' ') + 1); k++;
a= a.substr( a.find(' ') + 1,a.length()-a.find(' ')); }
for (int i = 0; i < k; i++) {
n = 0;
for (int j = 0; j < k; j++) {
if (suz[i] == suz[j] && i != j) {