MUHAMMAD AL-XORAZMIY NOMIDAGI TOOSHKENT AXBOROT TEXNALOGIYALARI UNIVERSITETI I-KURS 211-21 GURUH TALABASI ADHAMOV MUHAMMAD SODIQNING CLASSLAR, SATRLAR, MASSIVLAR MAVZULARI BO’YICHA BAJARGAN
Toshkent-2021 1. Satrni teskarisini topadigan dastur tuzing.
#include using namespace std; void reverseStr(string& str) { int n = str.length(); for (int i = 0; i < n / 2; i++) swap(str[i], str[n - i - 1]); } int main() { string str = "Birorta gap"; reverseStr(str); cout << str; return 0; }
2. Char turidagi A satrdagi soʻzlarning har birini katta harflardagi nusxasini joylashtiruvchi dastur tuzing.
#include #define MAX 100
int main()
{ char str[MAX]={0};
int i ;
printf("Bironta gap kiriting: ");
scanf("%[^\n]s",str);
for (i=0; str[i]!='\0'; i++)
{ if(i==0)
{
if((str[i]>='a' && str[i]<='z'))
str[i]=str[i]-32;
continue; }
if(str[i]==' ')
{ ++i;
if(str[i]>='a' && str[i]<='z')
{
str[i]=str[i]-32;
continue;
} }
else
{ if(str[i]>='A' && str[i]<='Z')
str[i]=str[i]+32;
} }
printf("So'zlar bosh harflar bilan: %s\n",str);
return 0;
}
3. String turidagi Satr berilgan. Undagi elementlarni byte turidagi A massivga joylashtirib, oʻsish tartibida saralovchi, B massivga kamayuvchi tartibida saralovchi dastur tuzing.
#include using namespace std; int main() { string s , a, b; cout<<"Satr kiriting: "; getline(cin,s); for(int i=0 ; i { sort(s.begin() , s.end()); a[i] = s[i] ; cout<<"a["< } for(int i=s.size() ; i>=0 ; i--) { cout<<"b["< } }