What's new

Closed Help mga master recursion in C language

Status
Not open for further replies.

PHcShiroe

Honorary Poster
Joined
May 8, 2015
Posts
149
Reaction
198
Points
129
Need help about recursion po
Ano po Mali SA program ?
Always 1 po lumalabas na output.

#include <stdio.h>
double recursion(int n);
int main()
{
int n=190;
printf("The quotient of 190 to 181 is = %g",recursion(n));
return 0;
}
double recursion(int n)
{
if (n >=181)
return n/recursion(n-1);
else
return 1;
}
Need na output po : The quotient of 190 to 181 is 7.49
Thanks po SA help
 
Easy:

C:
#include <stdio.h>
#define SIZE 190

double multiplyNumbers(int n);
double temp=SIZE;

int main(void) {
    int n=SIZE;
    printf("\nThe FINAL quotient of 190 to 181 is: %0.30lg\n", multiplyNumbers(n));
    printf("                                      -----------------------------------\n");
    return 0;
}

double multiplyNumbers(int n) {
    if (n > 181) {
        temp /= --n;
        printf("Current iteration: %0.30lg\n", temp);
        multiplyNumbers(n);
        return temp;
    }
}
quotient2.png
 

Attachments

Last edited:
Easy:

C:
#include <stdio.h>
#define SIZE 190

double multiplyNumbers(int n);
double temp=SIZE;

int main(void) {
    int n=SIZE;
    printf("\nThe FINAL quotient of 190 to 181 is: %0.30lg\n", multiplyNumbers(n));
    printf("                                      -----------------------------------\n");
    return 0;
}

double multiplyNumbers(int n) {
    if (n > 181) {
        temp /= --n;
        printf("Current iteration: %0.30lg\n", temp);
        multiplyNumbers(n);
        return temp;
    }
}
View attachment 727435
Thank you paps
 
Easy:

C:
#include <stdio.h>
#define SIZE 190

double multiplyNumbers(int n);
double temp=SIZE;

int main(void) {
    int n=SIZE;
    printf("\nThe FINAL quotient of 190 to 181 is: %0.30lg\n", multiplyNumbers(n));
    printf("                                      -----------------------------------\n");
    return 0;
}

double multiplyNumbers(int n) {
    if (n > 181) {
        temp /= --n;
        printf("Current iteration: %0.30lg\n", temp);
        multiplyNumbers(n);
        return temp;
    }
}
View attachment 727435
Thank you paps nagets ko na po 😃
 
Status
Not open for further replies.

Similar threads

Back
Top