In: Computer Science
Write a c program that will return 1 if the argument passed is a digit and zero otherwise.
Use the following function int isNumber(char *c) to do that.
Do not use && or || logical operator.
Write a full c program that has the header required and will accept the user entry.
CODE :
#include <stdio.h> //standard header
//isNumber function that return 1 if character is digit otherwise
it will return 0
int isNumber(char *c)
{
int n=0;
if(*c>='0') //if it is greater or equal to
0
{
if(*c<='9') //if it
is less than or equal 9
{
n=1; //digit
}
else //if not
digit
{
n=0;
}
}
return n;
}
int main()
{
char ch;
printf("Enter input:");
scanf("%c",&ch); //reading character from the
user
printf("%d",isNumber(&ch)); //calling function
isNumber
}
CODE SCREENSHOT:
OUTPUT:
RUN-1
RUN-2
RUN-3
RUN-4
RUN-5