02-14-2012, 09:11 PM
Uite ce facem noi la info!
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int a[101][101],aux,ok,max,m,n,i,j,p[101];
ifstream f("mat.in");
f>>n>>m;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
f>>a[i][j];
f.close();
ofstream g("mat.out");
for(j=1;j<=n;j++)
{
p[j]=1;
for(i=1;i<=m;i++)
p[j]=p[j]*a[i][j];
}
max=p[1];
for(i=1;i<=n;i++)
if(max<p[i])
max=p[i];
for(i=1;i<=m;i++)
if(max==p[i])
cout<<i<<" ";
do{
ok=1;
for(j=1;j<n;j++)
if(a[1][j]>a[1][j+1])
{
aux=a[1][j];
a[1][j];
a[1][j+1]=aux;
ok=0;
}
}while(ok==0);
for(i=1;i<=n;i++)
{
cout<<endl;
for(j=1;j<=n;j++)
cout<<a[i][j]<<" ";
}
g.close();
return 0;
}
Deja mi s-a acrit de matrici. Vectorii sunt mult mai faini si mai usori ca matricile.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int a[101][101],aux,ok,max,m,n,i,j,p[101];
ifstream f("mat.in");
f>>n>>m;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
f>>a[i][j];
f.close();
ofstream g("mat.out");
for(j=1;j<=n;j++)
{
p[j]=1;
for(i=1;i<=m;i++)
p[j]=p[j]*a[i][j];
}
max=p[1];
for(i=1;i<=n;i++)
if(max<p[i])
max=p[i];
for(i=1;i<=m;i++)
if(max==p[i])
cout<<i<<" ";
do{
ok=1;
for(j=1;j<n;j++)
if(a[1][j]>a[1][j+1])
{
aux=a[1][j];
a[1][j];
a[1][j+1]=aux;
ok=0;
}
}while(ok==0);
for(i=1;i<=n;i++)
{
cout<<endl;
for(j=1;j<=n;j++)
cout<<a[i][j]<<" ";
}
g.close();
return 0;
}
Deja mi s-a acrit de matrici. Vectorii sunt mult mai faini si mai usori ca matricile.
"Errare humanum est sed perseverare diabolicum."
"Gutta cavat lapidem non vi, sed saepe cadendo."
"Inter arma silent leges."
"Gutta cavat lapidem non vi, sed saepe cadendo."
"Inter arma silent leges."