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
saw5 [17]
3 years ago
6

Write a C program that reads a string containing text and nonnegative numbers from the user and prints out the numbers contained

in the string in separate lines. For example, if the input is: The year has 365 days and the day has 12 hours Then the output will be: 365 12
Computers and Technology
1 answer:
Alex_Xolod [135]3 years ago
6 0

Here is the code in C.

#include <stdio.h>

#include <string.h>

//main function

void main()

{

// character array to store the string

char str[1000];

int len,i,j;

char c,ch;

printf("Please Enter a string: ");

 // read the string

gets(str);

// find the length of input string

len = strlen(str);

for(i=0;i<len;i++)

 {

      c=str[i];

       // if any character of string is digit then it will check

       // until it finds the next non-digit character

     if(c>='0' && c<='9')

     {

         for(j=i;j<len;j++)

         {

             ch=str[j];

             if(ch>='0' && ch<='9')

              //print the number in the string

             printf("%c",str[j]);

             else

             {

                 printf(" ");

                 i=j;

                 break;

             }

         }

     }

 }

}

Explanation:

First it ask user to input a string and store that string into character array.Then travers the array and find first digit character.If a digit is found then print that digit.After that in the inner for loop, check next character is digit or not, if a digit meets then print that digit.Repeat this until the next non-digit character founds.When a non-digit character meets print a space and update the value of "i" and break the inner loop.It will again check the same from the ith index in the character array.

Output:

Please Enter a string: The year has 365 days and the day has 12 hours

365 12

You might be interested in
What is the point of having bullets points in a text box
Ludmilka [50]
You should have bullets in a text box in case you have a list of stuff. For example:

Computer Parts

.Tower

.Monitor

. Mouse

.Printer


3 0
4 years ago
Read the integer numbers in the text file "1000 Random Number from 0 to 100.txt" into a list
Marianna [84]

Answer:

random_number_file = open("1000 Random Number from 0 to 100.txt", 'r')

random_number_list = random_number_file.readlines()

print('random_number_list)

Explanation:

The name of the file containing the random integer text is ; "1000 Random Number from 0 to 100.txt"

The random_number_file variable stores the opened file ("1000 Random Number from 0 to 100.txt") using the open keyword and reads it ('r')

This file stored in the random_number_file variable is the read into a list by using the readlines() method on the random_number_file

6 0
3 years ago
The Internet and World Wide Web allow almost any business to be global. What are two important results of this process?
lubasha [3.4K]

Answer:

The two Important results of any business to be global is given below.

Explanation:

1.The Internet and World Wide Web allowing the easier and quicker way to getting started any business due to this we can sell the product online and make the business global.

2.The Internet and World Wide Web giving the quicker way to change the business if any changes are reflected in the business environment.

6 0
4 years ago
The school tie is made from a piece of fabric measuring 135cm long by 9cm wide. The fabric is supplied in a roll that is 90mm wi
yawa3891 [41]

Answer:

The cost to make one tie is approximately £4.79

Explanation:

The details of the dimensions of the fabric needed to make the school tie are;

The length of the required fabric = 135 cm

The width of the fabric for the tie = 9 cm

The width of a roll of fabric when sold = 90 mm = 9 cm

The cost of the fabric per meter = £3.55

The width of the roll of fabric = The width of the  fabric material required to make a tie

1 meter  = 100 cm

The cost of 1 m (100 cm) of fabric = £3.55

Therefore;

The cost of the 135 cm of the fabric required for the tie, <em>c</em>, is found as follows;

c = £3.55 × 135/100 = £4.7925

The cost of the fabric required to make one tie giving the answer to two decimal place, c ≈ £4.79

5 0
3 years ago
Assume that programs spend about 25% of their time waiting for I/O operations to complete. If there are FOUR programs loaded int
natima [27]

Answer:

0.9961

Explanation:

Given that:

Proportion of time waiting for I/O operation to complete = 25% = 0.25

Number of programs waiting in memory = 4

Using the CPU Utilization formula :

CPU Utilization = 1 - p^n

1 - 0.25^4

1 - 0.00390625

0.99609375

5 0
3 years ago
Other questions:
  • (True or False)
    8·2 answers
  • One of the network printers is producing copies where the toner is smeared on paper after printing. What component should be che
    11·1 answer
  • Universal Containers has a requirement to integrate Salesforce with an external system to control record access. What option sho
    11·1 answer
  • Describe each of the six steps of the selection process as illustrated in chapter 12
    13·1 answer
  • A program is a high-level one that has been converted to machine language
    15·1 answer
  • Question 6 (2 points)
    11·1 answer
  • Consider the class ScopeTest defined this way:
    15·1 answer
  • Rewrite the following using if else statement:
    14·1 answer
  • Study the original and changed passages.
    8·2 answers
  • A _________ attack is an attack on a computer system or network that causes a loss of service to users.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!