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]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
Free wifi is typically offered on an <br> a) unencrypted<br> b) encrypted<br> c) open<br> d) private
aliya0001 [1]

c) open

I think this because when you're in an open space (such as starbucks) it's public for anyone to enter. I think.

7 0
3 years ago
Read 2 more answers
What is a program that, when installed on a computer, records every keystroke and mouse click?
Mrac [35]
"Key logger" This could be software or hardware that does this.
6 0
3 years ago
What is the difference between technology and science?
Anna007 [38]

Answer:

The difference between science and technology can be summarized in the following manner:

Science is more or less a study of a particular branch namely, physics, chemistry or biology. ...

Science involves observation and experimentation whereas technology involves invention and production.

Science is all about analysis whereas technology is more concerned about the synthesis of design.

Explanation:

cool

3 0
2 years ago
What are the uses of computer in educational setting?
Arada [10]

Answer:

Quick Communication & Correspondence

Explanation:

Another main advantage of using computers in the education field is the improvement in the quality of teaching-learning process and communication between students & teachers. For this, they use Microsoft PowerPoint to prepare electronic presentations about their lectures.

8 0
3 years ago
Read 2 more answers
Don't click on this I am testing
Andrew [12]

Don't click on this I am testing... I want the points so.

3 0
2 years ago
Read 2 more answers
Other questions:
  • Mia is attending a team meeting to discuss how to prevent accidents. One of her teammates suggests pushing all the desks against
    15·2 answers
  • Effective character encoding requires:
    8·1 answer
  • 4.17 LAB: Varied amount of input data ( C++)
    5·1 answer
  • Write the proghrams for the following:
    13·1 answer
  • Assume that the int variables i and j have been declared, and that n has been declared and initialized.
    10·1 answer
  • Remember partially filled arrays where the number of elements stored in the array can be less than its capacity (the maximum num
    14·1 answer
  • If you created a variable called name, what data type would that value be? Group of answer choices a float a string a Boolean an
    5·2 answers
  • Witch icon allows you to see paragraph formatting feature
    6·1 answer
  • Question 1
    8·1 answer
  • Text,Audio and graphic is entered into the computer using
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!