2014-03-27 4 views
0

반복 관계 T는 n> = 0에서 정의되며 기본 경우 T (0) = 1 인 경우 T (n) = T (n-1) + 2 * n으로 표시됩니다.반복 관계 계산

하나의 정수 k가 주어지며 T (k)를 알아 내기위한 프로그램을 작성해야합니다.

프로그램은 T()를 재귀 적으로 구현해야합니다.

다음
include<stdio.h> 
long long T(int input) 
{ 
if(input == 0) 
return 1; 

return 2*input + T(input-1); 
} 
int main() 
{ 
/*write your code here*/ 
int k; 
    scanf("%d",&k); 
printf("%lli",T(k)); 
return 0;  
} 

내가 어떻게 다음과 같은 기대 효과를 달성 할 수

Program:1:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token 
    Program:In function 'main': 
    Program:13:4: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration] 
    Program:13:4: warning: incompatible implicit declaration of built-in function 'scanf' [enabled by   default] 
    Program:14:4: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 
    Program:14:4: warning: incompatible implicit declaration of built-in function 'printf' [enabled by default] 
    Program:14:4: warning: implicit declaration of function 'T' [-Wimplicit-function-declaration] 
    Program:14:4: warning: format '%lli' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat] 

있어 오류는 다음과 같습니다

내 코드인가?

Sample Test Cases 

       Input Output 
Test Case 1  1   3 
Test Case 2  2   7 
Test Case 3  3   13 
+1

작성해야합니다 # include

+0

감사합니다. – user3454353

답변

0

오타가 있습니다. 당신은 상단에있는 include 뒤의 광장/해시/날카로운 # 기호 누락

#include <stdio.h> 
1

님의

include<stdio.h> 

변경합니다.

경고는 scanf이 정의되지 않았 음을 나타냅니다. 그것에 대한 정의는 포함하지 않은 stdio.h에 나와 있습니다.

그렇지 않으면 재귀 함수가 꽤 괜찮습니다.

+0

고맙습니다. – user3454353