In: Computer Science
Set hasDigit to true if the 3-character passCode contains a digit. (in C)
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
int main(void) {
bool hasDigit;
char passCode[50];
hasDigit = false;
scanf("%s", passCode);
/* Your solution goes here */
if (hasDigit) {
printf("Has a digit.\n");
}
else {
printf("Has no digit.\n");
}
return 0;
}
#include
#include
#include
#include
int main(void) {
bool hasDigit;
char passCode[50];
hasDigit = false;
scanf("%s", passCode);
/* Your solution goes here */
// FOR LOOP TO CHECK IF A DIGIT IS PRESENT OR NOT
for(int i = 0; i < 3; i++) // 3 character passcode
{
if(passCode[i] >= '0' && passCode[i] <= '9')
{
hasDigit = true;
break;
}
}
if (hasDigit) {
printf("Has a digit.\n");
}
else {
printf("Has no digit.\n");
}
return 0;
}