|
| 1 | +**Q1. Determine whether a year is a leap year or not** |
| 2 | + |
| 3 | +Steps: |
| 4 | + |
| 5 | +1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5. |
| 6 | +2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4. |
| 7 | +3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5. |
| 8 | +4. The year is a leap year (it has 366 days). |
| 9 | +5. The year is not a leap year (it has 365 days). |
| 10 | + |
| 11 | + |
| 12 | +**Q2. Find the length of the string (entered by the user) without using the built-in function.** |
| 13 | + |
| 14 | +Following is the example of output: |
| 15 | +``` |
| 16 | +Input string: javascript |
| 17 | +Output: Length of string: 10 |
| 18 | +``` |
| 19 | + |
| 20 | + |
| 21 | +**Q3. check whether a number (entered by the user) is a perfect number or not.** |
| 22 | + |
| 23 | +A perfect number, a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3. |
| 24 | + |
| 25 | + Input: 6 |
| 26 | + Proper divisors of 6 are: 1, 2 and 3 |
| 27 | + Sum of proper divisors = (1 + 2 + 3) which is equal to 6 (our input) |
| 28 | + Hence, 6 is perfect number |
| 29 | + |
| 30 | + |
| 31 | +**Q4. check whether the number entered by the user is a strong number or not.** |
| 32 | + |
| 33 | +Strong Numbers are the numbers whose sum of factorial of digits is equal to the original number. Given a number, check if it is a Strong Number or not. |
| 34 | + |
| 35 | + Input: 145 |
| 36 | + Output: Yes |
| 37 | + Sum of digit factorials = 1! + 4! + 5! |
| 38 | + = 1 + 24 + 120 |
| 39 | + = 145 |
| 40 | + |
| 41 | + |
| 42 | +**Q5. check whether the number entered by the user is a happy number or not. The user will enter 20 input number and program will check if it is a happy number or not.** |
| 43 | + |
| 44 | +A happy number is starting with any positive integer, replace the number by the sum of the squares of its digits in base-ten, and repeat the process until the number either equals 1 (where it will stay), or it loops endlessly in a cycle that does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers (or sad numbers) |
| 45 | + |
| 46 | +If a number is happy, then all members of its sequence are happy; if a number is unhappy, all members of the sequence are unhappy. |
| 47 | + |
| 48 | + Input: n = 19 |
| 49 | + Output: 19 is Happy Number, |
| 50 | + 1^2 + 9^2 = 82 |
| 51 | + 8^2 + 2^2 = 68 |
| 52 | + 6^2 + 8^2 = 100 |
| 53 | + 1^2 + 0^2 + 0^2 = 1 |
| 54 | + As we reached to 1, 19 is a Happy Number. |
| 55 | + |
| 56 | + |
| 57 | +**Q6. count all vowels in a sentence (entered by the user).** |
| 58 | + |
| 59 | +Following example shows the output of the program: |
| 60 | + |
| 61 | + Input: Hello C Programming |
| 62 | + Output: 5 (vowels) |
| 63 | + |
| 64 | +**Q7. check whether a number entered by the user is magic number or not. The user will enter 1729 input number and program will calculate and check if it is magic number or not and print on the console.** |
| 65 | + |
| 66 | + What is the magic number? |
| 67 | + Input: 1729 |
| 68 | + Sum of digits of the given number.(1 + 7 + 2 + 9 => 19) |
| 69 | + The reverse of 19 is 91 |
| 70 | + The product of digit sum and the reverse of digit sum.(19 X 91 = 1729) |
| 71 | + If the product value and the given input are same, |
| 72 | + then the given number is a magic number.(19 X 91 <=> 1729) |
| 73 | + |
| 74 | + Output: So, 1729 is a magic number. |
| 75 | + |
| 76 | + |
0 commit comments