Pages

Saturday

Program to Check Whether the Person is in Teen Age or Not in C | C Program

Here's a C program to check whether the person is in teen age or not with output and proper explanation. Here we find out whether a person is a teenager or not by using an if-else condition and C logical operators.


# include <stdio.h> 
# include <conio.h> 
void main() 
{ 
 int age ; 
 clrscr() ; 
 printf("Enter the age : ") ; 
 scanf("%d", &age) ; 
 if(age >= 13 && age <= 19) 
  printf("\nThe person is in teen age.") ; 
 else 
  printf("\nThe person is not in teen age.") ; 
 getch() ; 
} 
 
Output of above program is

Enter the age : 18
The person is in teen age.


Explanation of above program

Here first user enters a number specifying an age. Then in the If part of If-else condition we check whether the previously entered age is between the range of 13-19 i.e. the teen age. If the age that user entered is indeed between 13 and 19 then the If block gets executed otherwise the else part will be executed.

Note: In the If condition here, if you notice you'll see that we are using logical AND (&&) operator for the conjunction of two conditions i.e. age >= 13 and age <= 19. That means the if part will only gets executed when both the conditions are true.

3 comments:

  1. Hello,


    Great post. Well though out. This piece reminds me when I was starting out C Programming Tutorial after graduating from college.


    I need to check how many numbers in strings of 16 numbers is less than for an example 6.

    I only need a main routine..

    Excellent tutorials - very easy to understand with all the details. I hope you will continue to provide more such tutorials.


    Cheers,
    Franda

    ReplyDelete