Question

Write a program using Visual Studio 2017 that accepts four (4) lines of input: • The...

Write a program using Visual Studio 2017 that accepts four (4) lines of input:

• The first line contains a float value in 4.2f format • The second line contains a char value

• The third line contains a 4-digit int value

• The fourth line contains a char value and then displays all of the input on a single line

Phone Number

Write a program that accepts a phone number of the form +1(xxx)-xxxxxxx where x is a digit, and displays the sum of all digits (x's) in the phone number.

SUBMIT BOTH PIECES IN ONE FILE LAB2.C

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

Please find both the pieces in C program below:-

#include<stdio.h>

#include<conio.h>

void displaySum(char phone[]){

int n1 = phone[3] - '0';

int n2 = phone[4] - '0';

int n3 = phone[5] - '0';

int n4 = phone[8] - '0';

int n5 = phone[9] - '0';

int n6 = phone[10] - '0';

int n7 = phone[11] - '0';

int n8 = phone[12] - '0';

int n9 = phone[13] - '0';

int n10 = phone[14] - '0';

int sum = n1 + n2+n3+n4+n5+n6+n7+n8+n9+n10;

printf("sum of all digits (x's) in the phone number: %d\n", sum);

}

int main(int argc, char* argv[]){

system("cls");

char phone[20];

float f1 = 4.2f;

char c1 = 'A';

int i = 1234;

char c2 = 'Z';

printf("\n%.2f %c %d %c", f1, c1, i, c2);

printf("\nEnter Mobile Number in the format(+1(xxx)-xxxxxxx): ");

scanf("%s", &phone);

displaySum(phone);

system("PAUSE");

return 0;

}

The output is attached below:-

Please let me know in case of any clarifications required. Thanks!

Add a comment
Know the answer?
Add Answer to:
Write a program using Visual Studio 2017 that accepts four (4) lines of input: • The...
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
ADVERTISEMENT