Hallo zusammen...hab mal wieder ein Problem...das hier ist der Programmtext!!
#include <iostream>
using namespace std;
int sg(int f[], unsigned l)
{
if(!l) return 0;
return (f[0]%2?0:f[0]) +sg(&f[1],l-1);
}
int main(int argc, char* argv[])
{
int a[9] = {15,8,22,7,9,6,4,1,10};
int b[5] = {3,1,7,9,11};
unsigned l1 = 9;
unsigned l2 = 5;
cout<<"\n"<<sg(a,l1)<<endl; //Ausgabe
cout<<"\n"<<sg(b,l2)<<endl; //Ausgabe
system("pause");
}
Die Ausgaben sind ja hier 50 und 0...
Nun soll das Programm die selben Ausgaben rausgeben aber mit dem letztem Element beginnen also bei int a[9] sozusagen mit der 10 dann die 1 und so weiter!!!
Also ich hab nun folgendes gemacht...
#include <iostream>
using namespace std;
int sg(int f[], unsigned l)
{
unsigned i=l-1;
if(!l) return 0;
return (f[i]%2?0:f[i]) +sg(&f[1],l-1);
}
int main(int argc, char* argv[])
{
int a[9] = {15,8,22,7,9,6,4,1,10};
int b[5] = {3,1,7,9,11};
unsigned l1 = 9;
unsigned l2 = 5;
cout<<"\n"<<sg(a,l1)<<endl; //Ausgabe
cout<<"\n"<<sg(b,l2)<<endl; //Ausgabe
system("pause");
}
Nun gibt er 90 und 0 aus!? Das Problem denke ich liegt daran das er bei &f[1] ja nicht runter zählt sonder hoch...wie kann ich das ändern??
Danke schon mal für eure Antworten!!