ADVERTISEMENT
ADVERTISEMENT

C - Print Title Miss or Mr Based on Gender with Name using C Program.


IncludeHelp 14 August 2016

In this code snippet we will learn how to print title like Mr or Miss with entered name; title will be recognised through entered value of gender.

If you enter gender (M or m) name will be printed with Mr and if you enter gender (F or f) name will be printed with Miss.

If you enter gender except of M,m,F,f name will be printed with N/A title.

C Code Snippet - Print Title (Miss or Mr) based on Gender with Name

/*C - Print Title Miss or Mr Based on 
Gender with Name using C Program.*/

#include <stdio.h>

int main(){
	char name[40];
	char gender;
	
	printf("Enter name: ");
	gets(name);
	printf("Enter gender (M/F): ");
	scanf("%c",&gender);
	
	if(gender=='m'||gender=='M')
		printf("Hello Mr. %s.\n",name);
	else if(gender=='f'||gender=='F')
		printf("Hello Miss %s.\n",name);
	else
		printf("Hello N/A %s.\n",name);
	
	return 0;	
}
    First Run:
    Enter name: Mike
    Enter gender (M/F): M
    Hello Mr. Mike.

    Second Run:
    Enter name: Angel Princy
    Enter gender (M/F): F
    Hello Miss Angel Princy.

    Third Run:
    Enter name: Princem
    Enter gender (M/F): U
    Hello N/A Princem.

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.