In: Computer Science
Write a C program that performs the following: Asks the user to enter his full name as one entry. Asks the user to enter his older brothers’ names each at a time (the user should be instructed by the program to enter NULL if he does not have any older brother). Asks the user to enter his younger brothers’ names each at a time (the user should be instructed by the program to enter NULL if he does not have any younger brother). Displays the user’s full name on the screen. Displays on the screen the following statement: “You are the eldest son” if the user has no older brothers but still he has younger ones, or Displays on the screen the following statement: “You are the youngest son” if the user has no younger brothers but still he has older ones, or Displays on the screen the following statement: “You are the only son” if the user does not have any brothers. Instructions: You should add a comment at the beginning of the program that shows your full name and student ID. You should use nested if else statement in the code.
//This program is devoloped using Codeblocks IDE.
#include <stdio.h>
int main()
{
//Declaring variables to store user's name and his/her olser and
younger brothers' name
char uname[50],obroname[50],ybroname[50];
printf("Enter you full name: ");//Displaying message to enter
user's full name.
scanf("%s",&uname);// Input user's Full name
printf("\nEnter you older brothers' name (Enter NULL if you do
not have any older brother): ");
scanf("%s",&obroname); // Input older brothers' name
printf("\nEnter you younger brothers' name (Enter NULL if you do
not have any younger brother): ");
scanf("%s",&ybroname);//Input younger brothers' name
printf("Your Full name is %s\n",uname); //Displaying user's Full name
//Using nested if
if(strcmpi(obroname,"NULL")==0) //Check whether the user has any
younger brother
{
if(strcmpi(ybroname,"NULL")==0) //Check whether the user has any
younger brother
{
printf("You are the only son"); //Display this message if the user
has no older brother and no younger brother
}
if(strcmpi(ybroname,"NULL")!=0)
{
printf("You are the eldest son");
}
}
else
{
if(strcmpi(obroname,"NULL")!=0)
{
if(strcmpi(ybroname,"NULL")==0)
{
printf("You are the youngest son"); //Display this message if the
user has no older brother but has younger ones
}
}
}
return 0;
}//End of main().
/*
OUTPUTS :-
*/