Home »
C solved programs »
C basic programs
C program to read name and marital status of a girl and print her name with Miss or Mrs
In this C program, we will read name and marital status of a girl and print her name Miss or Mrs based on given marital status.
Submitted by IncludeHelp, on March 27, 2018
Problem statement
Given name and marital status of a girl and print her name with Miss and Mrs based on given marital status in C.
Example
Input:
Enter the name of a girl : Radhika
Is the girl married (Y-Yes, N-No) : yes
Output:
Her full name is : Mrs. Radhika
Input:
Enter the name of a girl : Radhika
Is the girl married (Y-Yes, N-No) : no
Output:
Her full name is : Miss Radhika
In this program, to read strings we are using gets() function - we can also use fgets() function, which is safe.
Syntax:
fgets(string, size, stdin);
In the program, we are checking marital status with following values,
- If input value is "yes" or "y" then, "Mrs" Will be added before the name
- If input value is "no" or "n" then, "Miss" Will be added before the name
- Otherwise, program will print "Marital status is wrong"
Program to print name with Mrs or Miss based on input marital status in C
/*
C program to check the marital status
of a girl
*/
#include <stdio.h>
#include <string.h>
// main function
int main()
{
// Declare a char buffer to take input for name
char name[30]={0};
// Declare a char buffer to take input for answer
char YesNo[10]={0};
//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
Run 1 :
Enter the name of a girl : Radhika
Is the girl married (Y-Yes, N-No) : yes
Her full name is : Mrs. Radhika
Run 2 :
Enter the name of a girl : Shivika
Is the girl married (Y-Yes, N-No) : N
Her full name is : Miss Shivika
Run 3 :
Enter the name of a girl : Sania
Is the girl married (Y-Yes, N-No) : o
Marital status is wrong
C Basic Programs »