Recursive method for calculating the age of a game person

Source: Internet
Author: User

There are n people sitting around asking how old is the nth man, he said he was 2 years older than the n-1, and asked the n-1 individual, who said he was 2 years older than the 3rd, and he said that he was 2 years older than the 2nd, and asked the 2nd man, who was 2 years older than 1th, that he was more than a man in his first year of N-2. The 1th man said he was 10 years old and asked the nth man how old he was.
Tips:

Recursive formula

#include <stdio.h>

int age (int n);

int age (int n)
{
	if (n = 1) return
		;
	else return Age
		(n-1) + 2;
}
int main ()
{
	int n,m;
	scanf ("%d", &n);
	M=age (n);
	printf ("The%dth person's age is%d\n", N, m);
	return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.