Task Description
Summing Digits
請你撰寫一遞迴函式f,將n的每一位數不停地相加直到只剩下個位數。
例如,當n=47,則答案為2,因為:
4+7=11
1+1=2
Hint
f.h
打上 function header 以及相關的設定。int f(int n);
f.c
撰寫程式碼後對應上傳。#include "f.h"int f(int n) { / add your code /}
main.c
這個檔案無法更改也無須上傳。1234567891011 #include <stdio.h>#include "f.h" int main(){ int n; scanf("%d", &n); printf("%d\n", f(n)); return 0; }
Input Format
測試資料為一正整數n。
Output Format
請撰寫一遞迴函式輸出題目的要求。
Sample Input
1 47
Sample Output
1 2