Answer to Question #277362 in C for Shrinidhi A S

Question #277362

an ecommerce website wishes to find the lucky customer who will be eligible for full value cashback. for this purpose, a number n is fed to the system. it will return another number that is calculated by an algorithm. in an algorithm, a sequence is generated, in which each number is the sum of the two preceding numbers. initially, the sequence will have two 1's in it. the system will return the nth number from the generated sequence which is treated as the order id. the lucky customer will be the one who has placed that order. write an algorithm to help the website find the lucky customer.


1
Expert's answer
2021-12-08T19:03:22-0500
#include <stdio.h>
int lucky(int n){
	if (n <= 2)
		return 1;
	int currentNumber = 1;
	int previousNumber = 1;
	int x = 2;
	while (n > x){
			currentNumber = currentNumber + previousNumber;
			 previousNumber =  currentNumber;
		x += 1;
	
		
	}
	
	
	
	return currentNumber;
}




int main()
{
    int n;
    scanf("%d",&n);
    
    printf("order id :%d",lucky(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