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
Juan wrote a loop to print all the prime numbers between 1 and 100. But instead of stopping at 100, it continues on and on forev
aniked [119]

Answer:

oh im cool

Explanation:

6 0
2 years ago
What is the output? answer = "Hi mom print(answer.lower()) I​
DerKrebs [107]
As you have included a syntax error inside your question, I will make assumptions on the code. I will assume your code is {
answer = “Hi mom”
print(answer.lower())
}

In this case the output would be “hi mom”. Please make sure to double check your questions before posting.
3 0
3 years ago
Where can elicitation techniques be used?
Nikitich [7]

Answer:

An elicitation technique is any of a number of data collection techniques used in anthropology, cognitive science, counseling, education, knowledge engineering, linguistics, management, philosophy, psychology, or other fields to gather knowledge or information from people.

Explanation:

3 0
2 years ago
Question 16 of 40
neonofarm [45]

Answer:

D hjjhhhhhhhhhhhhhhh

Explanation:

cuz

6 0
3 years ago
Read 2 more answers
A smartphone user notices that their phone gets very hot, and their battery is draining quickly. Even when the phone is in their
nika2105 [10]

Answer:

The problem would be the battery

Explanation:

The reason is becuse the battery might be bad or have a shortage in it hope this helps :) and good luck!

6 0
2 years ago
Other questions:
  • Exposing employee and customer personal data to an untrusted environment is an example of:
    9·1 answer
  • In Alphatech Systems, email software screens incoming messages by organizing them into mailboxes and identifying junk mail. As a
    13·1 answer
  • Which of the following is a popular open source intrusion detection system that runs on SmoothWall?? Synchronous Dynamic Random
    6·1 answer
  • Provide the instruction type, assembly language instruction, and binary representation of instruction described by the following
    7·1 answer
  • __________ are the first line of defense against unsafe drivers.
    5·1 answer
  • Rachel typed two paragraphs and then realized she was in the wrong document. What steps should Rachel follow to quickly move the
    15·2 answers
  • What is one pass of a coding sequence called?​
    13·2 answers
  • You received an email message stating that your mother's bank account is going to be forfeited if you do not respond to the emai
    6·1 answer
  • Write the definition of a function that evaluates three double numbers and returns true if the floor of the product of the first
    8·1 answer
  • Which of the following is ture?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!