Commit 0bc77a0a authored by Nighz's avatar Nighz
Browse files

+matrices exercise 2

*minor changes to array exercise 4
parent f17a7b1d
......@@ -4,14 +4,14 @@ using namespace std;
int main()
{
int sum_max, sum = 0, a[1000], g, io_max = 0, iu_max = 0;
int sum_max, sum, a[1000], n, io_max = 0, iu_max = 0;
cout<<"Geben Sie die Anzahl der einzugebenden Zahlen ein: (1-1000) ";
cin>>g;
cin>>n;
if(g < 1 || g > 1000) return 1;
if(n < 1 || n > 1000) return 1;
for(int i = 0; i < g; i++)
for(int i = 0; i < n; i++)
{
cout<<"Wert "<<i+1<<": ";
cin>>a[i];
......@@ -19,11 +19,11 @@ int main()
sum_max = a[0];
for(int i = 0; i < g; i++)
for(int i = 0; i < n; i++)
{
sum = 0;
for(int j = i; j < g; j++)
for(int j = i; j < n; j++)
{
sum += a[j];
if(sum > sum_max)
......
#include <iostream>
using namespace std;
int main()
{
int a[5][3], b[5][3], c[5][3], sum[3] = {0, 0, 0};
//A einlesen
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 3; j++)
{
cout<<"Zeile "<<i+1<<", Spalte "<<j+1<<" : ";
cin>>a[i][j];
//Spaltensumme
sum[j] += a[i][j];
//Quadrate in B speichern
b[i][j] = a[i][j] * a[i][j];
//C berechnen
c[i][j] = a[i][j] + b[i][j];
}
}
//Spaltensummen ausgabe
cout<<"\n\nSpaltensummen:\n";
for(int i = 0; i < 3; i++) cout<<"Summe Spalte "<<i+1<<" : "<<sum[i]<<"\n";
//Ausgabe C
cout<<"\n\nMatrix C:\n";
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 3; j++)
{
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment