Question

In: Computer Science

(In C)Set hasDigit to true if the 3-character passCode contains a digit.

 

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;

}

Solutions

Expert Solution

#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 = 0i < 3i++) // 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;

}

Related Solutions

(C++)Set hasDigit to true if the 3-character passCode contains a digit.
C++. Set hasDigit to true if the 3-character passCode contains a digit. #include #include #include using namespace std; int main() {bool hasDigit;string passCode; hasDigit = false;cin >> passCode; /* Your solution goes here */ if (hasDigit) {cout
(JAVA)Set hasDigit to true if the 3-character passCode contains a digit.
JAVE 3.10.1: String with digit. Set hasDigit to true if the 3-character passcode contains a digit. MUST USE THIS TEMPLATE: public class CheckingPasscodes {public static void main (String [] args) {boolean hasDigit;String passCode; hasDigit = false;passCode = "abc"; /* Your solution goes here */ if (hasDigit) {System.out.println("Has a digit.");}else {System.out.println("Has no digit.");}}}
Set hasDigit to true if the 3-character passCode contains a digit. public class CheckingPasscodes { public...
Set hasDigit to true if the 3-character passCode contains a digit. public class CheckingPasscodes { public static void main (String [] args) { boolean hasDigit = false; String passCode = ""; int valid = 0; passCode = "abc"; /* Your solution goes here */ if (hasDigit) { System.out.println("Has a digit."); } else { System.out.println("Has no digit."); } return; } }
(In JAVA)Write code to print the location of any alphabetic character in the 2-character string passCode.
Java Language Write code to print the location of any alphabetic character in the 2-character string passCode. Each alphabetic character detected should print a separate statement followed by a newline. Ex: If passCode is "9a", output is: Alphabetic at 1 import java.util.Scanner;   public class FindAlpha {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       String passCode;              passCode = scnr.next();     ...
Passwords of length 10 are formed using the character set S = {a, b, c, …,...
Passwords of length 10 are formed using the character set S = {a, b, c, …, z, A, B, …, Z, 0, 1, 2, .., 9}. Thus the set S consists of 62 different characters. For each part below, you must include a few words that describe your counting strategy. (a) How many passwords of length 10 use the character Q exactly two times? (b) How many passwords of length 10 use at most one of the “upper case” letters...
a. How many 3-digit numbers can you make using the digits from the set of (3,...
a. How many 3-digit numbers can you make using the digits from the set of (3, 4, 5, 6, 8, 2, 7) without repetitions? b. How many numbers can be made with the digits from the set of (0, 3, 5, 7, 8, 4, 9), which are greater than 0 and less than a thousand (repetitions are allowed)?
3) Which of the following statements is true or false a) Character displacement occurs when two...
3) Which of the following statements is true or false a) Character displacement occurs when two species using the same resource overlap in their distributions and become more similar to each other than they are where they don’t overlap. b) If you wanted to know if an organism which expresses a dominant phenotype is homozygous or heterozygous for a trait (e.g., round pea shape, R_), you could do a “test cross” between the unknown individual (R_) and an individual which...
Question 4: Set P to the largest digit in your 5 digit number. For example, if...
Question 4: Set P to the largest digit in your 5 digit number. For example, if your 5 digit number is 88412, then P should be set to 8. Calculate and print the value of (P+1) multiplied by itself (P+3) times. As an example, if your 5 digit number is 88412, you should print the result of multiplying 9 with itself 12 times -- this is also known as 9 to the power of 12. HINT: you are free to...
a. Write a c++ function called IsPalindrome that receives a 3-digit number and returns whether it...
a. Write a c++ function called IsPalindrome that receives a 3-digit number and returns whether it is palindrome or not. [2.5 marks] b. Write a c++ function, called GCD that receives two parameters n, d, and prints their greatest common divisor [2.5 marks] Now after you created the two functions, you have to write a main function that can call the above functions according to user choice. Write a menu that allows the user to select from the following options...
In C++, The following program reads one character from the keyboard and will display the character...
In C++, The following program reads one character from the keyboard and will display the character in uppercase if it is lowercase and does the opposite when the character is in uppercase. If the character is a digit, it displays a message with the digit. Modify the program below such that if one of the whitespaces is entered, it displays a message and tells what the character was. // This program reads one character from the keyboard and will //...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT