In: Computer Science
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
#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; }