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
Which input and output pair is correct for a bicycle?
mrs_skeptik [129]

Answer:

I'm pretty sure its B.

Explanation:

Input: Force is applied to the pedals by the rider's feet then..

Process: the chain and gear system convert the energy to cause...

Output: the rear wheels to turn and make the bike go foward

6 0
3 years ago
Complete the statement below with the correct term.
g100num [7]

Answer:

boot disk

Explanation:

This disk contains files required by the boot sequence as well as the operating system, which is loaded at the end of the startup process.

8 0
3 years ago
Write a Java program that reads an 8-bit binary number from the keyboard as a string and then converts it into decimal. For exam
cestrela7 [59]

Answer:

public class Brainly

{

 public static void main(String[] args)

 {

   BinaryConverter conv = new BinaryConverter();

   String binStr = "01001101";

   System.out.print(binStr + " in decimal is "+conv.BinToDec(binStr));

 }

}

public class BinaryConverter

{

 public int BinToDec(String binStr)

 {

   int d = 0;

   while(binStr.length() > 0)

   {

     d = (d << 1) + ((binStr.charAt(0) == '1') ? 1: 0);

     binStr = binStr.substring(1);

   }

   return d;

 }

}

Explanation:

The program "eats" the string from left to right, and builds up the integer representation in variable "d" on the go. While there are digits left, it shifts the previous result to the left and sets the least signficant bit to 1 only if the corresponding string character is a 1.

5 0
3 years ago
HURRRYYYY PLZZ!!
vivado [14]

Answer: A. How much is this vehicle's resale value?

6 0
3 years ago
Read 2 more answers
This type of brake fade is caused by the brake fluid becoming so hot that it boils:a. Fluid fade b. Hydraulic fade c. Heat fade
PolarNik [594]
Its is B)hydraulic fade
5 0
3 years ago
Other questions:
  • Your desktop computer monitor is not displaying a picture. What would you do to troubleshoot the problem?
    7·2 answers
  • Why is the answer A?
    6·1 answer
  • A strategy to solve a logic problem is to break it into steps. Using the drop-down menu, complete these sentences about solving
    15·2 answers
  • Assume you previously entered these lines of code.
    14·2 answers
  • Do you think I could create a working animatronic like the one from five nights at freddys
    12·2 answers
  • Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (a
    14·1 answer
  • What can the tab key do
    10·1 answer
  • Explain the bad effect and good effect of mobile phone and internet.<br>​
    15·2 answers
  • This is science I just couldn’t find it
    15·1 answer
  • Complete the following sentence by choosing the best answer from the options listed below.
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!