Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9. You may assume that the string does not contain spaces and will always contain less than 50 characters.Ex: If the input is:1995the output is:yesEx: If the input is:42,000or1995!the output is:noHint: Use a loop and the isdigit() function (don't forget to include the ctype library).please use c programming language

Question
Asked Feb 14, 2020
127 views

Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9. You may assume that the string does not contain spaces and will always contain less than 50 characters.

Ex: If the input is:

1995

the output is:

yes

Ex: If the input is:

42,000

or

1995!

the output is:

no

Hint: Use a loop and the isdigit() function (don't forget to include the ctype library).

please use c programming language

check_circle

Expert Answer

Program Instructions:
  • Declare an array of chars and prompt the user for input.
  • Take the input from the user and store it in the array.
  • Call the isNumber() function on the string and print “Yes”, if the function returns true, otherwise, print “NO”.
  • In function isNumber(), use a loop to traverse each character, and check whether the character is a digit or not using the isdigit() function.
Program:

#include <stdio.h>

#include<string.h>

#include<ctype.h>

using namespace std;

 

bool isNumber(char s[])

{

     // loop till the end of array exclude the last null character

     for (int i = 0; i < strlen(s)-1; i++) {

          // use isdigit() function to check whethet the character is a string or not

          if (isdigit(s[i]) == false)

              return false;

     }

     return true;

}

 

int main()

{

     // define char of array

   &n...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Write a top-down design for the following: Calculating the average of ten test scores Calculating t...

A: Approach for TOP-DOWN design to calculate the average of test scoresInitialize the value to the vari...

question_answer

Q: Code isn't running, how do i get it to print to a txt file          public class WeightedAvgDataAnal...

A: A Java program for the given criteria is as follows,//Import necessary packagesimport java.io.File;i...

question_answer

Q: Question attached. **expression in the paranthesis should be evaluated first

A: A logic circuit is generally a circuit which presents and execute logical actions or operations on t...

question_answer

Q: Q7:- Choose the correct statement:- Prints the database_information connection = getDbConnection()...

A: Note: In the question, the numbering given for the statement is wrong. The same number “1” is given ...

question_answer

Q: Use propositional logic to prove the argument valid: (P∨(Q∧R))∧(R'∨S)∧(S→T')→(T→P)

A: An argument is valid if and only if the result in the tautology becomes 1 after solving the given Bo...

question_answer

Q: 1. WEP was the first protection algorithm used for wireless transmission. It had to be replaced beca...

A: Note: Multiple questions and multiple sub parts are there in the given question. The answer is provi...

question_answer

Q: A new language, Houston, with a block structured syntax similar to Algol 60uses either pass-by-refer...

A: Test program: begin    integer n;    procedure p(k: integer);        begin        n := n+1;        k...

question_answer

Q: For C++ In binary tree how would you find the number of nodes divible by 3? NumOfNodesDivisbleby3()

A: This C++ program counts the number of nodes divisible by 3.In main() function, user insert the nodes...

question_answer

Q: ET-580 Object-Oriented Progzanning. 5. rowbridge 2020 b) Create a function that returns the count of...

A: In the main method – Declare a variable to input the number. Take a number as an input. Call the me...