Hello. How to write a C program to check and display president party
like if i type in the console "biden" and hit enter the output shoud be : "biden is democrat" and if i type "trump" and hit enter the output shoud be: "trump is republican"



Hello. How to write a C program to check and display president party like if i type in the console ..

Answer / Rahul Goel

Here's a simple C program that accomplishes this. The program uses an array of structs to store names and parties. It then compares the input with the stored names and outputs the respective party.nn```cn#include <stdio.h>nnstruct president {n char name[20];n char party[10];n};nnstruct president presidents[] = {n {"biden", "democrat"},n {"trump", "republican"}n};nnvoid check_president(char input[]) {n int i;nn for (i = 0; i < 2; ++i) {n if (strcmp(input, presidents[i].name) == 0) {n printf("%s is %s
", input, presidents[i].party);n }n }n}nnint main() {n char input[20];n printf("Enter a president's name: ");n scanf("%s", &input);n check_president(input);n return 0;n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What are variables c?

1 Answers  


int main() { unsigned char a = 0; do { printf("%d=%c\n",a,a); a++; }while(a!=0); return 0; } can anyone please explain me output????

1 Answers  


What is the output for the following program #include<stdio.h> main() { char a[5][5],flag; a[0][0]='A'; flag=((a==*a)&&(*a==a[0])); printf("%d\n",flag); }

5 Answers   ADITI, Wipro,


main() { float a=3.2e40; printf("%d",a); }

9 Answers   Satyam,


write a program without using main function?

2 Answers   TCS,


What is file in c language?

1 Answers  


i have to apply for the rbi for the post of officers. i need to know abt the entrance questions whether it may be aps or techinical....

1 Answers   RBI,


How to write the code of the program to swap two numbers with in one statement?

2 Answers  


where does it flourished?

0 Answers   Microsoft,


whats the use of header file in c?

2 Answers  


A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none

1 Answers  


Is sizeof a keyword in c?

1 Answers  


Categories