Commit f17a7b1d authored by Nighz's avatar Nighz
Browse files

Added arrays exercice 3 and 4 and modified exercice 2

parent 54baa397
......@@ -66,7 +66,7 @@ char to_upper(char b)
case 'T':
case 't':
return 'T';
case 'T':
case 'U':
case 'u':
return 'U';
case 'V':
......
#include <iostream>
using namespace std;
int main()
{
int num[10] = {2, 5, 2, 3, 3, 6, 3, 7, 4, 5}, singlenum[10], l = 1;
for(int i = 0; i < 10; i++)
{
bool found = false;
if(i != 0)
{
for(int j = 0; j < l; j++)
{
if(singlenum[j] == num[i]) found = true;
}
if(!found)
{
cout<<", "<<num[i];
singlenum[l] = num[i];
l++;
}
}
else
{
cout<<num[0];
singlenum[0] = num[0];
}
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int sum_max, sum = 0, a[1000], g, io_max = 0, iu_max = 0;
cout<<"Geben Sie die Anzahl der einzugebenden Zahlen ein: (1-1000) ";
cin>>g;
if(g < 1 || g > 1000) return 1;
for(int i = 0; i < g; i++)
{
cout<<"Wert "<<i+1<<": ";
cin>>a[i];
}
sum_max = a[0];
for(int i = 0; i < g; i++)
{
sum = 0;
for(int j = i; j < g; j++)
{
sum += a[j];
if(sum > sum_max)
{
iu_max = i;
io_max = j;
sum_max = sum;
}
}
}
cout<<"Die maximale Summe ist "<<sum_max<<" von Index "<<iu_max<<" bis Index "<<io_max;
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