반복 관계 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
작성해야합니다 # include –
감사합니다. – user3454353