#include <iostream>
using namespace std;
int sum(int n, bool o)
{
if (n == 0 && o)
return 0;
if (n == 1)
return 1;
if (o)
return sum(n - 1, 1) + n;
else
return sum(n - 1, 0) * n;
}
int main()
int n;
cin >> n;
cout << sum(n, 1) << "\n"
<< sum(n, 0);
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
using namespace std;
int sum(int n, bool o)
{
if (n == 0 && o)
return 0;
if (n == 1)
return 1;
if (o)
return sum(n - 1, 1) + n;
else
return sum(n - 1, 0) * n;
}
int main()
{
int n;
cin >> n;
cout << sum(n, 1) << "\n"
<< sum(n, 0);
}
Begin
readln(n);
p:=1;
For n:=n Downto 1 Do
Begin
s := s+n;
p := p*n;
End;
writeln(s);
write(p);
End.