Crunching Part 2 Flashcards
Crunching (14 cards)
Cyclic Rotation (3mins)
Write a program that prompts the user to input a binary number then the direction of rotation and the number of steps. The program must then output each step of rotation. For invalid input, an error message must be displayed.
Input:
Enter a binary number: 10010
Direction (L/R): L
Steps: 2
Output:
Step 1: 00101
Step 2: 01010
A
Km/miles conversion (2mins)
Ask the user to input in either km or mi then output the corresponding conversion.
Input:
Enter length: 4mi
Output:
6.437km
A
Temperature Conversion (2mins)
Ask the user to input in either F or C then output the corresponding conversion.
Input:
Enter temperature: 100F
Output:
37.78C
A
BMI (2mins)
Write a program that calculates the Body Mass Index (BMI) from a given weight in pounds (lbs) and height in centimeters (cm). The BMI should be expressed to two decimal places.
Input:
Enter weight (lbs):
Enter height (cm):
Output:
BMI: 22.50
A
Cartesian (3mins)
Given the coordinates (x, y) of a point on a 2D plane, write a program that determines which quadrant the point lies in.
Input:
Enter coordinates x,y: 2.1,-3
Output:
Location: Quadrant IV
A
Grade Checker (3mins)
In a certain subject, the final grade is determined by both the student’s grade and their number of absences. If the student has more than 5 absences, the grade is reduced by one letter.
Sample Input1:
Enter the grade and number of absences, separated by a hyphen: 93-5
Output:
Letter Grade: A
Sample Input2:
Enter the grade and number of absences, separated by a hyphen: 93-6
Output:
Letter Grade: B
Sample Input3:
Enter the grade and number of absences, separated by a hyphen: 93,6
Output:
Invalid Input
A
Leap Year Checker (1min)
Write a program to check if a given year is a leap year or not.
Input:
Enter Year: 2020
Output:
Leap Year
A
Factorial Trailing Zeros (3mins)
Write a program that finds the number of trailing zeros in n! (factorial of n).
Input:
Enter a number: 10
Output:
2
Explanation: 10! = 3628800 has 2 trailing zeros.
A
Find the Missing Number (3mins)
Find the missing number on a list of numbers.
Input:
Enter number count: 5
Enter numbers: 1 2 3 5
Output:
4
A
Check Anagram (2mins)
Given two strings, check if they are anagrams (ignore spaces and case).
Input:
String 1: Listen
String 2: Silent
Output:
Anagrams
A
Find the Most Frequent Character (3mins)
Given a string, output the character that appears the most (ignore case and spaces). If multiple characters have the same max frequency, output the first one.
Input:
Enter string: Hello World
Output:
l-3
A
GCD (2mins)
Write a program to find the Greatest Common Divisor (GCD) of two integers using Euclid’s algorithm.
Input:
Enter Number 1: 54
Enter Number 2: 24
Output:
6
A
Check Perfect Number (2mins)
A number is perfect if the sum of its divisors (excluding itself) equals the number. Write a program to check if a number is perfect.
Input:
28
Output:
Perfect
Explanation:
Divisors (1,2,4,7,14) sum to 28.
A
Fibonacci Sequence Generator (2mins)
Generate the first n numbers of the Fibonacci sequence.
Input:
Enter number count: 7
Output:
0 1 1 2 3 5 8
A