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]
2 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]2 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
the front desk of the Nocete's Hotel will comlute the total room sales (TRS) of Room 101.The room was occupied three times and t
Rus_ich [418]

Answer:

Php. 1050

Explanation:

Total Room sales for Room 101:

Rate = 350

Number of times occupied = 3

Total sales per room : (number of times room was occupied * rate of the room.)

Hence, total sales for room 101:

Php. 350 * 3

= Php. 1050

4 0
2 years ago
One of the most common uses of spreadsheet are
otez555 [7]

I think it is Index Match?

6 0
2 years ago
Which line of code will print I can code on the screen?
KIM [24]

Answer: print("I can code")

Explanation:

luckily im a coder

5 0
3 years ago
Write a program to find all integer solutions to the equation 4x + 3y -9z = 5 for values of x, y, and z between 0 to 100.
rjkz [21]

Answer:

Following are the code to the given question:

#include <iostream>//header file

using namespace std;

int main()//main method

{

  int c= 0;//defining integer variable to count number of solutions

  int x,y,z;//defining integer variable which is used in the loop

  for (x = 0; x <= 100; x++)//defining for loop to x value

     for (y = 0; y <= 100; y++)//defining for loop to y value

        for (z = 0; z <= 100; z++)//defining for loop to z value

           if (4 * x + 3 * y - 9 * z == 5)//use if to check given condition

           {

              c++;//increment count value

              cout << "(" << x << "," << y << "," << z << ")";//print solutions  

              cout << (c % 11? " " : "\n");//use for add file solution in a row

           }

  cout << "\n\nThere are " << c << " solution(s)\n";//print solution couts

  return 0;

}

Output:

Please find the attached file.

Explanation:

In the above-given code four integer variable "x,y,z, and c" is declared, in which "x,y, and z" is used in the for loop with the if conditional statement that checks the given condition and prints the solution and the "c" variable is used to counts the number of solution, and at the last, it uses the print method to print its values.  

8 0
3 years ago
(25 POINTS)Which statement best reflects the importance of following safety guidelines?
jeyben [28]

Answer:

I think, Every year, thousands of people die as a result of workplace injuries.

6 0
3 years ago
Read 2 more answers
Other questions:
  • What is the output of the following Python program? try: fin = open('answer.txt') fin.write('Yes') except: print('No') print('Ma
    9·1 answer
  • Reggie has hired you to design a home network. The home network will share a printer but will mainly be used to stream movies to
    7·1 answer
  • MICR is an input or output devices
    5·1 answer
  • Chapter 8 discusses five principles for making a graphic clear and understandable. One principle is that the graphic should have
    11·1 answer
  • What are candid shots? what are posed shots?
    13·1 answer
  • Whenever you press a key, click the mouse or start an application, you're sending instructions tow
    9·1 answer
  • Write a program asks the user for an integer N and then adds up the first N odd integers. For example, if the user asks the sum
    11·1 answer
  • Suppose you are working as an administrative assistant at a small law firm. Your boss has asked you to send an invitation out to
    5·1 answer
  • When a derived class method has the same name as a base class method, it is often said that the derived class method ________ th
    13·1 answer
  • Question 9
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!