ADVERTISEMENT
ADVERTISEMENT

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

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"
ADVERTISEMENT

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.