Question

In: Computer Science

"This C Programming " Write a program that accepts four (4) lines of input: • The...

"This C Programming "

Write a program 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

Write a program that accepts a phone number of the form +1(xxx)-xxx-xxxx

where x is a digit, and displays the sum of all digits in the phone number.

Solutions

Expert Solution

First Program:

#include<stdio.h>

int main(){
float a;
char b;
int c;
char d;
printf("Enter the float value in line 1, Character in the next line, integer in next line and Character in the 4th line: \n");
// Getting the inputs form different lines
scanf("%f",&a);
scanf(" %c",&b);
scanf("%d",&c);
scanf(" %c",&d);
printf("Output in single line\n");
//Displaying the output in single line
printf("%4.2f %c %d %c",a,b,c,d);
return 0;
}

Output:

Second Program:

#include<stdio.h>
int main(){
char phone[20] ;
int a;
int total = 0;
printf("Enter the phone number in the form +1(xxx)-xxx-xxxx \n");
//Getting the phone number and save it in the character array
gets(phone);
//for loop is to iterate over the character array to find the total
for(a = 2; a <= 20; a++){//initial a= 2 to ignore the '+1'
switch(phone[a]){
case '1':
total = total+1;
break;
case '2':
total = total+2;
break;
case '3':
total = total+3;
break;
case '4':
total = total+4;
break;
case '5':
total = total+5;
break;
case '6':
total = total+6;
break;
case '7':
total = total+7;
break;
case '8':
total = total+8;
break;
case '9':
total = total+9;
break;
default:
total= total+0;
break;
}
}
printf("Total of the digits of the phone number is %d", total);
return 0;
}

Output:


Related Solutions

C Programming: Write a program that accepts 2 arguments, an input file and an output file....
C Programming: Write a program that accepts 2 arguments, an input file and an output file. The program is to store in the output file the contents of the input file in reverse. If the input file looks like this: Hello World.\n This is Line 2\n This is the end.\n then the output file should look like this: \n .dne eht si sihT\n 2 eniL si sihT\n .dlroW olleH The main program should look like this: int main(int argc, char...
Write a short C++ program that takes all the lines input to standard input and writes...
Write a short C++ program that takes all the lines input to standard input and writes them to standard output in reverse order. That is, each line is output in the correct order, but the ordering of the lines is reversed. Please use vector datatype standaard library #include <vector> Thanks
2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
1. Specification Write a C program to implement a simple calculator that accepts input in the...
1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...
C++ language Write a program that accepts as input the base price and the finished area...
C++ language Write a program that accepts as input the base price and the finished area in square feet of the three models. The program outputs the model(s) with the least price per square foot in the following format: If the colonial model is the least price, output: The price per square foot of the colonial model is the least. If the split-entry model is the least price, output: The price per square foot of the split-entry model is the...
In C++, write a program that accepts a text file of ASCII words from standard input...
In C++, write a program that accepts a text file of ASCII words from standard input and store them and the amount of times the word appears in the file in a hash table using external chaining. Then print the words and their counts sorted based on alphabetical order and print them again in decreasing numerical order based on the amount of times the word appears in the file. Space, tab, and new line all count as space characters. The...
Use C language Write a program that reads in a series of lines of input character...
Use C language Write a program that reads in a series of lines of input character by character (using getchar()). The first line of the input contains an integer which specifies the number of remaining lines of input, each of which contains a floating point number. The integer value on the first line can be read with scanf(), but all of the following lines can only be read with getchar(). Each line after the first contains a single floating point...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions each represented as a numerator and denominator. Do not use classes or structures. Print your result (which is also represented as a numerator/denominator) to standard out. If you get done early, try to simplify your result with the least common denominator. The following equation can be used to add fractions: a/b + c/d = (a*d + b*c)/(b*d) Example: 1/2 + 1/4 = ( 1(4)...
Write a program in C++ (parking.cc) that reads a group of input lines. Each line contains...
Write a program in C++ (parking.cc) that reads a group of input lines. Each line contains an A for arrival or a D for departure, which is terminated by a :, and a license plate number, which is terminated by a :. The program should print a message each time a car arrives or departs. When a car arrives, the message should specify when the garage is full. If there is no room for a car, the car simply leaves....
Write a program that accepts a string and character as input, then counts and displays the...
Write a program that accepts a string and character as input, then counts and displays the number of times that character appears (in upper- or lowercase) in the string. Use C++ Enter a string: mallet Enter a character: a "A" appears 1 time(s) Enter a string: Racecar Enter a character: R "R" appears 2 time(s)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT