Docsity

Perfect Numbers and Recursion in C Programming, Quizzes of Computer Science

Toggle sidebar
bg1
1. Write a C program to test if the number is a perfect number or not using
recursion.
2. Find the fourth term in the sequence.
{
b
(
1
)
=โˆ’7
b
(
n
)
=b
(
nโˆ’1
)
+12
3. Write a C program that contains a power method, ask the user for two
numbers (a base and an exponent) and then calculate the result of the base
raised to the power of the exponent using recursion.
4. Trace and answer
void decrease (int n){
if (n>0)
{
printf(โ€œ%dโ€,n);
decrease(n-1);
}
}
int main()
{
decrease(5);
return 0;
}
void decrease (int n){
while (n>0)
{
printf(โ€œ%dโ€,n);
n--;
}
}
int main()
{
decrease(5);
return 0;
}
1

Partial preview of the text

Download Perfect Numbers and Recursion in C Programming and more Quizzes Computer Science in PDF only on Docsity!

1. Write a C program to test if the number is a perfect number or not using

recursion.

2. Find the fourth term in the sequence.

b ( 1 )=โˆ’ 7

b

n

= b

n โˆ’ 1

3. Write a C program that contains a power method, ask the user for two

numbers (a base and an exponent) and then calculate the result of the base

raised to the power of the exponent using recursion.

4. Trace and answer

void decrease (int n){

if (n>0)

printf(โ€œ%dโ€,n);

decrease(n-1);

int main()

decrease(5);

return 0;

void decrease (int n){

while (n>0)

printf(โ€œ%dโ€,n);

n--;

int main()

decrease(5);

return 0;