/*C語言 遞迴函數計算次方的應用*/
#include<stdio.h>
#include<stdlib.h>

int factorial(int,int);  /*宣告遞迴函數factorial()的原型*/

int main(void)
{
    printf("factorial(6,6)=%d\n", factorial(6,6));  

    /*呼叫遞迴函數factorial()*/

    system("pause");
    return 0;
}

int factorial(int i,int j)  /*自訂函數factorial(),計算i的j次方*/
{
    if (j ==0)
    {
        return 1;
    }
    else
    {
        return (i * factorial(i, j - 1));
    }
}

結果為:

image

 

arrow
arrow
    創作者介紹
    創作者 愛學習 的頭像
    愛學習

    愛學習

    愛學習 發表在 痞客邦 留言(0) 人氣()