Crunching Part 1 Flashcards
Crunching (13 cards)
Swapping Numbers (2mins)
Ask the user to enter two numbers. Set the first number as x and second number as y. You should be able to swap the values of x and y by only using the x and y variables. No extra variables allowed.
Input:
Enter value of x: 10
Enter value of y: 5
Output:
x: 5
y: 10
A
Single Digit Sum (3mins)
Given a number, repeatedly add its digits until the result is a single digit. 987 → 9 + 8 + 7 = 24 → 2 + 4 = 6
Input:
987
Output:
6
A
Frequency Count (3mins)
Ask the user for a string. Print the frequency of each character (ignore spaces, case-insensitive).
Input:
hello world
Output:
h: 1
e: 1
l: 3
o: 2
w: 1
r: 1
d: 1
A
Binary Even Places (3mins)
Ask the user for a Binary input then print the even places in the binary
Input:
Enter a binary: 0100010010101
Output:
Binary: 101000
A
Morse to Binary (2mins)
Ask the user to enter Morse code in . and -, and a space separator between letters. Convert the Morse code into binary (0s and 1s).
Input:
.- -…
Output:
01 1000
A
Readable Time (2mins)
Prompt the user to enter a time duration in seconds and output the equivalent time in the format h:m:s
Input:
Enter time in seconds: 5130
Output:
1:25:30
A
Binary Bits (2mins)
Prompt the user to input number of bits ‘n’ and display all possible n-bit combinations.
Input:
Enter a number of bits: 4
Output:
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
Number of combinations: 16
A
Ascending/Descending (3mins)
Print the numbers in ascending and descending order.
Input:
Enter two numbers: 1,4,6,7,2,3,5,6
Output:
Ascending: 1,2,3,4,5,6,6,7
Descending: 7,6,6,5,4,3,2,1
A
Second Largest Number (2mins)
Ask the user for a list of numbers and print the second largest value.
Input:
Enter two numbers: 3,1,4,4,2
Output:
3
A
Palindrome Checker (2mins)
Check whether the input string is a palindrome or not (ignore case and spaces).
Input:
Enter word: A man a plan a canal Panama
Output:
Palindrome
A
Binary to Decimal Converter (3mins)
Print the binary representation from 0000 to 1111 and their corresponding decimal values.
Output:
0000 – 0
0001 – 1
0010 – 2
…
1111 – 15
A
Prime Numbers (2mins)
Print the prime numbers from 1 to 100.
Output:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97
A
Armstrong Number (3mins)
Check if a number is an Armstrong number (sum of digits raised to the power of number of digits equals the number).
Input:
153
Output:
Armstrong
A