Jump to content


Photo

c++


  • Please log in to reply
1 reply to this topic

#1 hubert9393

hubert9393
  • Użytkownicy
  • 6 posts

Posted 07 June 2012 - 22:57

chce zrobic pseudoprogram do obliczania silni. mam probelm z poleceniem RETURN otóż:

#include <iostream>

using namespace std;
int f(int liczba);
int main(int argc, char **argv)
{
cout<<"wynik to...."<<f(5);
return 0;
}
int f (int liczba)
{
static int krok;
static int suma=1;
int b;
for(b=1;b<=liczba;b++)
{
krok++;
suma =suma*krok;

cout<<suma<<"....\n";
if(b>liczba)
{
return suma;
}
}

}

Petla działa dobrze. Poniewaz pokazuje
1....
2....
6....
24....
120....
wynik to....0

Jednak funkcja zwraca 0. Dlaczego nie zwraca 120 ??
  • 0


#2 hubert9393

hubert9393
  • Użytkownicy
  • 6 posts

Posted 08 June 2012 - 00:40

przepraszam bardzo. Był to bład w instrukcji IF. Temat zamkniety
  • 0


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users