Question

Please Answer with C code including C function. Will rate! Thanks Write a C function that...

Please Answer with C code including C function. Will rate! Thanks

Write a C function that takes as parameter a character and uses the switch statement to return
the same character if it is 'a', 'b' or 'c', otherwise the character 'z'. Write a C program that reads
a character, calls the function, and displays the return value.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:

#include <stdio.h>

//function declaration

char callFunction(char ch);

int main()

{

//Declaring variables

char ch,ret;

//Getting the input entered by the user

printf("Enter a Character :");

scanf(" %c",&ch);

  

//calling the function

ret=callFunction(ch);

  

//Displaying the returned value

printf("Returned Character :%c\n",ret);

  

return 0;

}

/* This function takes the character as input and

* returned a character based on the input character

*/

char callFunction(char ch)

{

char ret;

switch(ch)

{

case 'a':

case 'b':

case 'c':{

ret=ch;

break;

}

default:{

ret='z';

break;

}

}

return ret;

}

Add a comment
Know the answer?
Add Answer to:
Please Answer with C code including C function. Will rate! Thanks Write a C function that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT