1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tiny-mole [99]
3 years ago
12

Part 1: 1) Write a C program getPhoneNumber.c that accepts a phone number from the user in the form XXX-XXX-XXXX, and then displ

ays it in the form (XXX)XXX-XXXX: Enter a date (XXX-XXX-XXXX): 011-123-4567 You entered (011)123-4567
Computers and Technology
1 answer:
Allushta [10]3 years ago
8 0

Answer:

Following are the program, which can be below:

#include <stdio.h> //defining header file

#include <string.h>//defining header file

int main() //defining main method

{  

int x=0,y=0,l=0; //defining integer variable

char phone_number[32] = {'\0'}; //defining char array

printf("Enter a date(xxx-xxx-xxxx): \n "); //print message

printf("Example: 000-000-0000 \n :"); //print message

scanf("%s",phone_number); // taking input from user

printf("%s\n",phone_number); //print number

for(x=0; phone_number[x]; x++) // check character by character

{

if(x==0) // put ( on first character

{

l = strlen(phone_number); //calculate length  

phone_number[l] = '\0'; //check number  

for(y=l; y>=1; y--) //loop to calculate a value

{

phone_number[y] = phone_number[y-1]; //holding value in array

}

phone_number[y] = '('; //assigning bracket

}

if(phone_number[x] == '-') // put ) at first -

{

phone_number[x] = ')'; //assigning bracket

break;

}

}

printf("You entered %s\n",phone_number); //print all value with brackets

}

Output:

Enter a date(xxx-xxx-xxxx):  

Example: 000-000-0000  

:011-123-4567

011-123-4567

You entered (011)123-4567

Explanation:

The description of the above program can be defined as follows:

  • In the above program three integer variable "x, y, and l" and a character array "phone_number" is declared.
  • In the char, variable user input the value and print its value by using the print function.
  • In the next line, a for loop is declare, that checks user input value character by character and counts its length by using the strlen() method, inside the loop a conditional statement is used.
  • In the condition statement check, the values are not equal to null and provide brackets in the inserted value.
You might be interested in
Which heading size fits for the word headings​
hjlf
The first one h4 is yhat
3 0
3 years ago
Read 2 more answers
La sentencia de ASIGNAR es una sentencia de entrada de datos, verdadero o falso ?
Akimi4 [234]

Answer:

sorry can´t understand langues

Explanation:

cant

7 0
3 years ago
Name the tools in plant propagation.<br>Q<br>18.<br>16.<br>17.<br>19.<br>20.<br>please po asap​
Agata [3.3K]
16. Branch or tree cutter
17.paint tape
18. Knife
19. Pots
20. Waterer
6 0
3 years ago
A termination condition in a loop is analogous to________in a recursive method.
Varvara68 [4.7K]

Answer:

b) iteration.

Explanation:

There are various algorithms which are used in computer programming. Iteration is also a type of algorithm which is used to create loops. The instructions are inserted once and then these instructions are repeated to create a loop function.

8 0
3 years ago
When formatting numbers with the Comma Number Format tool, the numbers are formatted with _________.
irina [24]

Answer:

2 decimal places

Explanation:

5 0
3 years ago
Other questions:
  • Send a document as a PDF when A. you want the recipient to make changes to the file. B. it needs to be printed. C. it contains m
    10·1 answer
  • How many people watch Anime in the world?
    15·2 answers
  • What type of lights are necessary for silhouettes?
    12·2 answers
  • What kind of energy transformation occurs in a gasoline-powered car?
    14·1 answer
  • You want to use a terminal program to terminal into a cisco router. what protocol should i use
    8·1 answer
  • 25 Points Asap <br> Write a Java program named Light.java that displays a light bulb shown below:
    14·1 answer
  • How to transfer bookmarks to new computer
    15·1 answer
  • What is the result of the following code?<br><br> x=7//2+10%2**4<br><br> print(x)
    15·1 answer
  • What are the methods of gilding<br><br>nonsense will be immediately reported. ​
    7·1 answer
  • Which tools can help you gather information about the processes running on a windows operating system?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!