Problem: C program for "If the ages of Ram, Shyam and Ajay are input through the keyboard. Write a program to determine the youngest of the three."
Logic used :
- Take input of ages of all three
- check if the Ram's age is less than Shyam and Ajay both using && relational operator
- if it returns true then print Ram is youngest.
- else check if Shyam's age is less than Ajay's age
- if it returns true then print Shyam is youngest
- else print Ajay is youngest
Demo :
if(ram<ajay && ram<shyam){
printf("Ram is youngest. Age : %d",ram);
}else if(shyam<ajay){
printf("Shyam is youngest. Age : %d",shyam);
}else{
printf("Ajay is youngest. Age : %d",ajay);
}
C program :
// Program by Shyam Sunder Kanth#include<stdio.h>int main(){int ram,shyam,ajay;printf("Enter age of ram :");scanf("%d",&ram);printf("Enter age of shyam :");scanf("%d",­am);printf("Enter age of ajay :");scanf("%d",&ajay);if(ram<ajay && ram<shyam){printf("Ram is youngest. Age : %d",ram);}else if(shyam<ajay){printf("Shyam is youngest. Age : %d",shyam);}else{printf("Ajay is youngest. Age : %d",ajay);}return 0;}
Codes used :
- #include<stdio.h> : Header file for input output
- int : Integer data type
- ram, shyam, ajay : Variable used
- printf : Function for displaying message
- scanf : Function for taking input
- if-else : Conditional statement
Do comments, if any doubt
Know about me : Shyam Kanth
No comments:
Post a Comment