Ajutatima va rog...Am nevoie de 4 programe c++; toate cazurile a,b,c,d...vedeti in poza.
Mersi mult!!!
Răspunsuri la întrebare
Răspuns:
Explicație:
***************** problema d **********************
#include <iostream>
#include <cstring>
using namespace std;
void afiseaza_prin_indici(char *sir)
{
int k;
cout << "\n Sirul afisat utilizandu-se tablou cu indice: ";
for (k=0; sir[k]; ++k)
cout << sir[k];
}
void afiseaza_prin_pointer(char *s)
{
cout << "\n Sirul afisat utilizandu-se pointeri: ";
while (*s)
{
cout << *s++;
}
}
int main()
{
char sirdat[20];
cout << "\n Dati un sir de maxim 20 caractere: "; cin.getline(sirdat,20);
afiseaza_prin_indici(sirdat);
afiseaza_prin_pointer(sirdat);
}
***************************** problema c *****************
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream f("f.txt");
ofstream g("g.txt");
char line[256];
int i, n;
int main()
{
while (f.getline(line,256))
{
n=strlen(line);
for (i=n-1; i>=0; --i)
g << line[i];
g << "\n";
}
}
*********************** problema a ******************
#include <iostream>
using namespace std;
int n,m,i,j,a[100][100], b[100][100];
int main()
{
cout << "nr de linii n= "; cin >> n;
cout << "nr de coloane m= "; cin >> m;
cout << "Dati elementele matricei: \n";
for (i=1; i<=n; ++i)
for (j=1; j<=m; ++j)
cin >> (a[i][j]);
int schimb=0;
while (schimb==0)
{
schimb=1;
for (j=1; j<m; ++j)
if (a[1][j]>a[1][j+1]) {swap(a[1][j],a[1][j+1]); schimb=1;}
}
for (i=1; i<=n; ++i)
{
for (j=1; j<=m; ++j)
b[i][j]=a[i][j];
}
cout << "Matricea b[][]: \n";
for (i=1; i<=n; ++i)
{
for (j=1; j<=m; ++j)
cout << b[i][j] << " ";
cout << "\n";
}
}