Assignment 2
Assignment 2
Instructions
1. Write a C program to read and print your name and address (Concept to learn: Getting
familiar with C Programming IDE, User input and output).
2. Write a C program to check whether a given number is divisible by 7 or not.
3. Write a C program to read a month number and print corresponding month name.
Sample output:
Enter Month Number: 1
January
4. Write a C program to input angles of a triangle and check whether triangle is valid or not.
5. Write a C program to check whether a person is eligible to vote or not.
6. Write a C program to Generate and print a Random Number.
7. Write a C program to Convert Celsius to Fahrenheit.
8. Write a C program to make a Simple Calculator.
Page 1
9. Write a C program to print the sum of first 10 numbers.
10. Write a C program to input 3 numbers from user and print the maximum among them.
(with conditional operator)
11. Write a program to find the sum of odd numbers and even numbers from 1 to N, N entered
by the user.
12. Create a converter that will convert a distance in meters to feet and inches.
Enter length in meters: 1
1.00m = 3 feet and 3.37 inches
Conversion formula:
1 feet = meters * 3.281
1 Feet = 12 inch
13. Write a program to read a character from the user and check whether it is a vowel (aeiou)
or consonant.
14. Write a program to check whether a character is uppercase or lowercase alphabet.
15. Write a program to accept two numbers and one mathematical operator. Using given
mathematical operator, calculate and display appropriate answer as shown below:
Sample output:
Enter first number : 5
Enter mathematical operator : +
Enter second number : 6
5 + 6 = 11
16. Write a program to enter a number from the user and display the sum of all the digits in the
number.
17. Accept a year from the user and check whether it is leap year or not.
The normal year contains 365 days but the leap year contains 366 days. This extra day is added to the
February month, that’s why we get February 29. All the years that are perfectly divisible by 4 are called as
Leap years except the century years. Century year’s means they end with 00 such as 1200, 1300, 2400, 2500
etc (Obviously they are divisible by 100). For these century years we have to calculate further to check the
Leap year.
- If the century year is divisible by 400 then that year is a Leap year
- If the century year is not divisible by 400 then that year is a Leap year
18. Write a program called ExtractDigits to extract each digit from an int in the reverse order. For
example, if the int is 12345, the output shall be "5 4 3 2 1", with a space separating the digits.
Page 2
19. Accept a number N from the user and print the first N elements of the Fibonacci series.
Hint: The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21
Fibonacci series is defined as a sequence of numbers in which the first two numbers are 1 and 1, or 0
and 1, depending on the selected beginning point of the sequence, and each subsequent number is
the sum of the previous two. So, in this series, the nth term is the sum of (n-1)th term and (n-2)th term.
Mathematically, the nth term of the Fibonacci series can be represented as:
tn = tn-1 + tn-2
20. Calculate the area of triangle given its three sides. The formula or algorithm used is:
Area = sqrt(s(s – a)(s – b)(s – c)), where s = (a + b + c) / 2 or perimeter / 2 and a, b & c are
the sides of triangle.
21. Write a program that take input of 3 subjects marks out of 150. Count the percentage. Print
the Grade/Class based on following conditions:
For 70% or more than 70% display DISTINCTION.
For percentage between 60 and 69 display FIRST CLASS.
For percentage between 50 and 59 display SECOND CLASS.
For percentage between 40 and 49 display PASS CLASS.
For percentage less than 40 display FAIL.
22. Considering three numbers provided by the user as length of sides of a triangle, first check, if
the values are valid for representing the sides of a triangle (i.e. whether a triangle can be
drawn using the given values). If the lengths of sides are valid, print the type of the triangle.
Hint: The sum of lengths of any two sides of a triangle is always greater than the length of
the third side. A triangle with all three sides having same length is known as an “Equilateral”
triangle. A triangle is called an “Isosceles” triangle if only two sides have equal lengths. If all
the sides of a triangle have different lengths, then it is called a “Scalene” triangle.
23. Write a C program to print following series using looping concept (use while or for loop).
i. 1, 2, 3, 4 ........ 100
ii. 100, 99, 98.......1
Page 3
iii. 1, 3, 5, 7........99
iv. 2, 4, 8, 16, 32, 64
24. Write a program to print following patterns. (hint: nested for loop)
*****
Page 5