Program to print name with Mrs or Miss based on input marital status in C: To add marital status before the name of the girl.

How to print the name with Mrs or Miss based on input marital status?
First, we take the input name and marital status (yes/no) from the user. next, we check users’ marital status if yes then we print Mrs otherwise we miss.

Example: Take the input name and marital status from a user.
Name: Swati
Marital status (yes/ no) : no

We compare two strings using strcmp function in c programming.

To check marital status user enter (yes/no) we compare user input with yes or no string as follow
strcmp((YesNo,”yes”)) || (!strcmp(YesNo,”Y”)) if user entered yes or Y
Another condition for No input
(!strcmp(YesNo,”no”)) || (!strcmp(YesNo,”N”)) if user entered no or N
Output: Miss Swati

Algorithm to print name with Mrs or Miss

  1. Take input Name of the girl
  2. Take input marital status (yes/No)
  3. If strcmp((YesNo,”yes”)) || (!strcmp(YesNo,”Y”))
    Add Mrs before name of girl
  4. Else If (!strcmp(YesNo,”no”)) || (!strcmp(YesNo,”N”))
    Add Miss before name of girl
  5. Else
    Print wrong status

Program to print name with Mrs or Miss based on input marital status in C.

#include <stdio.h>

int main()
{
char name[30];
char YesNo[10];

//input name
printf("Enter the name of a girl : ");
gets(name);

//input marital status
printf("Is the girl married (Y-Yes, N-No) : ");
gets(YesNo);

if((!strcmp(YesNo,"yes")) || (!strcmp(YesNo,"Y")))
printf("Her full name is : Mrs. %s",name);
else if((!strcmp(YesNo,"no")) || (!strcmp(YesNo,"N")))
printf("Her full name is : Miss %s",name);
else
printf("Marital status is wrong");

return 0;
}

Output :

Program to print name with Mrs or Miss

Write A Comment