Was berechnet dieses Programm?
-
Hey Leute,
uns stellt sich folgendes Problem. Wir bekommen einfach nicht den Sinn des folgenden Quelltextes in unser Gehirn. Da wir jetzt schon seit 2 geschlagenen Stunden daran hoffnungslos sitzen, wollten wir ganz nett um Hilfe bitten.
Vielen Dank im Voraus!MfG.
camorra
Quelltext:
#include <iostream>
using namespace std;unsigned rev(int a[], unsigned la)
{
int h;unsigned w=1;
if(la<=1) return 1;
if(a[0] != a[la-1]) {
h = a[0];
a[0] = a[la-1];
a[la-1] = h;
w = 0;
}return rev(&a[1], la-2) *w;
} //revint main(int argc, char *argv[]) {
int x[] = {10,9,8,7,6,7,8,9,10};
cout << rev(x,9); //Ausgabe
for (int i =0; i<9; i++) cout << x[i]<<"";//Ausgabe
cout <<endl;cout << rev(&x[2],7); //Ausgabe
for (int i =0; i<9; i++) cout << x[i]<<"";//Ausgabe
cout <<endl;cout <<rev(x,4); //Ausgabe
for (int i =0; i<9; i++) cout << x[i]<<"";//Ausgabe
cout <<endl;system("pause");
}
-
Versteht ihr den Code oder die Rechnungen nicht?
-
Wir kommen auf fehlende Cpp-Tags nicht klar.
-
Was ist so schwer 2x auf den selben Knopf zu drücken damit das so aussieht?
Das hat mich nun so angestrengt dass ich die Frage nich beantworten will! :p#include <iostream> using namespace std; unsigned rev(int a[], unsigned la) { int h; unsigned w=1; if(la<=1) return 1; if(a[0] != a[la-1]) { h = a[0]; a[0] = a[la-1]; a[la-1] = h; w = 0; } return rev(&a[1], la-2) *w; } //rev int main(int argc, char *argv[]) { int x[] = {10,9,8,7,6,7,8,9,10}; cout << rev(x,9); //Ausgabe for (int i =0; i<9; i++) cout << x[i]<<"";//Ausgabe cout <<endl; cout << rev(&x[2],7); //Ausgabe for (int i =0; i<9; i++) cout << x[i]<<"";//Ausgabe cout <<endl; cout <<rev(x,4); //Ausgabe for (int i =0; i<9; i++) cout << x[i]<<"";//Ausgabe cout <<endl; system("pause"); }
-
Ausführen und schauen was das Programm macht
