Question

In: Computer Science

In C code format please! 4.16 LAB: Checker for integer string Forms often allow a user...

In C code format please!

4.16 LAB: Checker for integer string

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

Solutions

Expert Solution

#include<stdio.h>

int main()
{
   char userString[20];
   int isValid = 1, i;
   
   scanf("%s",userString);
  
   for(i = 0;userString[i]!='\0';i++){
      if(!(userString[i]>='0' && userString[i]<='9')){
         isValid = 0;
         break;
      }
   }
   
   if(isValid==1)
   {
      printf("yes\n");
   }
   else{
      printf("no\n");
   }

   return 0;
}

Related Solutions

Checker for integer string Forms often allow a user to enter an integer. Write a program...
Checker for integer string 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. 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 Character.isDigit() function. import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr...
Forms often allow a user to enter an integer. Write a program that takes in a...
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. Ex: If the input is: 1995 the output is: yes Ex: If the input is: 42,000 or any string with a non-integer character, the output is: no PYTHON 3
Forms often allow a user to enter an integer. Write a programthat takes in a...
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
C code please (1) Prompt the user to enter a string of their choosing. Store the...
C code please (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and...
This code needs to be in C++, please. Step 1: Add code to prompt the user...
This code needs to be in C++, please. Step 1: Add code to prompt the user to enter the name of the room that they are entering information for. Validate the input of the name of the room so that an error is shown if the user does not enter a name for the room. The user must be given an unlimited amount of attempts to enter a name for the room. Step 2: Add Input Validation to the code...
8.30 LAB*: Program: Authoring assistant. PYTHON PLEASE!! (1) Prompt the user to enter a string of...
8.30 LAB*: Program: Authoring assistant. PYTHON PLEASE!! (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be...
On Python a) Use format() method to print an integer value entered by the user and...
On Python a) Use format() method to print an integer value entered by the user and its cube root with two decimal places. b) Print the same values as part (a) using format() function with keyword arguments and labels number and cubeRoot as in: format(number=n,cubeRoot=cr) c) Switch the order of keyword arguments and show that this has no effect on the output.
Goal: in this lab, you will learn to configure sudo to allow a user mrussell to...
Goal: in this lab, you will learn to configure sudo to allow a user mrussell to change password for users. Please follow the steps and answer all the questions at the end of the lab instruction. In the Linux machine ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1. For this part you will need a 2nd normal user (non-root) account. If you don't have an account for "auser" with password “room1202” yet, you can create one by running (as room1202): $ sudo useradd -c "A User"...
C# PLEASE Lab7B: For this lab, you’re going to write a program that prompts the user...
C# PLEASE Lab7B: For this lab, you’re going to write a program that prompts the user for the number of GPAs to enter. The program should then prompt the user to enter the specified number of GPAs. Finally, the program should print out the graduation standing of the students based on their GPAs. Your program should behave like the sample output below. Sample #1: Enter the number of GPAs: 5 GPA #0: 3.97 GPA #1: 3.5 GPA #2: 3.499 GPA...
The question asks to allow the user to integer ranging from 1 to 999 using JOPtionpane...
The question asks to allow the user to integer ranging from 1 to 999 using JOPtionpane in JAVA; and display those integers in words. For example, if the user enters 13 the program should display " Thirteen" and loop to ask the user to enter another integers. If the user enters 0, the program should quit. If the user enters an integer greater than 999, the program should display an error message and ask the user to enter an integer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT