Computer Science, asked by ma8222285, 5 months ago

Write a program that asks a user for their birth year encoded as two digits (like "62")
and for the current year, also encoded as two digits (like "99"). The program is to
correctly write out the users age in years.
Year of Birth:
62
Current year:
99
Your age: 37
----- another run of the program --------
Year of Birth:
62
Current year:
00
Your age: 38

Answers

Answered by shreyamishra8374
3

Input Format:

Input consists of 2 integers. The first integer corresponds to the last 2 digits of the birth year. The second integer corresponds to the last 2 digits of the current year.

Output Format:

Refer sample input and output for further formatting specifications.

Sample Input and Output:

[All text in bold corresponds to input and the rest corresponds to output]

Enter Year of Birth

62

Enter Current year

99

Your age is 37

The program will have to determine when a two digit value such as "62" corresponds to a year in the 20th century ("1962") or the 21st century. Here is another run of the program, where "00" is taken to mean the year 2000:

Enter Year of Birth

62

Enter Current year

00

Your age is 38

Assume that ages are not negative. Another run of the program:

Enter Year of Birth

27

Enter Current year

07

Your age is 80

In the following run, the age of the person could be 6 or 106 depending on the assumptions. Assume that the age will always be less than or equal to 100.

Enter Year of Birth

01

Enter Current year

07

Your age is 6

Enter Year of Birth

62

Enter Current year

99

Your age is 37

Code:

#include<stdio.h>

int main(){

signed int current, birth, a;

printf("Enter Year of Birth\n");

scanf("%d",&birth);

printf("Enter Current year\n");

scanf("%d",&current);

if(current<birth)

{

birth=100-birth;

a=birth+current;

printf("Your age is %d",a);

}

else

{

printf("Your age is %d",current-birth);

}

return 0;

}

Answered by manyasinghal100
0

Answer:

by ex need need my free g h my gmgj my team eh jhrjlhrhn

Similar questions