Answer to Question #302746 in C for Viki Sowmi

Question #302746

Write an algorithm to make an automated system which will help the builder to find the exact area for building the apartment




1
Expert's answer
2022-02-26T05:52:36-0500
#include <stdio.h>

int count_ways(int n) {
	if (n == 1) { return 4; }
    int result;
	int b=1, s=1, prev_b, prev_s;

	for (int i = 2; i <= n; i++)
	{
		prev_b = b;
		prev_s = s;
		s = prev_b + prev_s;
		b = prev_s;
	}
	result = s + b;
	return result * result;
}

int main()
{
	int n = 3;
    scanf("%d", &n);
    printf("Count of wats for %d sections is %d", n, count_ways(n));
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS