Calculate the Nth term | HackerRank
Solution :
Develop by Samsus Salehin Sabbir
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
- //Complete the following function.
- int find_nth_term(int n, int a, int b, int c) {
- //Write your code here.
- int first =a;
- int seccond = b;
- int third = c;
- int i,sum =0;
- for(i=4;i<=n;i++){
- sum = third + seccond + first;
- first = seccond;
- seccond = third;
- third = sum;
- }
- return sum;
- }
- int main() {
- int n, a, b, c;
- scanf("%d %d %d %d", &n, &a, &b, &c);
- int ans = find_nth_term(n, a, b, c);
- printf("%d\n", ans);
- return 0;
- }
No comments