Answer: Provided in the explanation section
Explanation:
The full questions says:
write a program that takes in a positive integer as input, and output a string of 1's and 0's representing the integer in binary. for an integer x; the algothm is as long as x is greater than 0 output x % (remainder is either 0 or 1 . x=x/2 in coral language. Note: The above algorithm outputs the 0's and 1's in reverse order.
Ex: If the input is:
6
the output is:
011
CODE:
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
while (n > 0) {
printf("%d", n % 2);
n /= 2;
}
printf("\n");
return 0;
}
2
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
while (n > 0) {
printf("%d", n % 2);
n /= 2;
}
return 0;
}
cheers i hope this helped !!
Write a script called checkLetter.sh Review Greeting.sh for an example. Use a read statement and ask user to "Enter A, B, or C: "
If user types A, echo "You entered A"
If user types B, echo " You entered B"
If user types C, echo " You entered C"
Use the case structure to test the user’s string.
If user types any letter from lower case ‘a through z’ or upper case ‘D through Z’, echo "You did not enter A, B, or C".
Answer:
The code is given as below: The input and output is as given for one case.
Explanation:
echo -e "Enter A, B or C : \c" #Printing the line on the screen
read -rN 1 test #read the character in the variable test
echo
case $test in #Setting up the case structure for variable test
[[:lower:]] ) #checking all lower case letters
echo You did not enter A, B or C;;
[D-Z] ) #checking upper case letters from D to Z
echo You did not enter A, B or C;;
A ) #Condition to check A
echo You entered A;;
B ) #Condition to check B
echo You entered B;;
C ) #Condition to check C
echo You entered C;;
esac #Exiting the case structure