0% found this document useful (0 votes)
48 views3 pages

Assignment-2 (Introduction To C Programming and Decision Statement)

The document provides examples for 7 programming assignments for a C programming lab. The assignments include: 1) swapping variables with and without a third variable, 2) getting input of a number and its number of digits, 3) calculating age based on date of birth input, 4) determining parity of a binary number, 5) printing a calendar for a 31 day month, 6) checking if a year is a leap year, and 7) checking if 3 points fall on a straight line. It also provides 3 additional problems: determining character type from ASCII value, checking triangle type based on side lengths, and evaluating pass/fail/retake status of a student based on marks in 2 subjects.

Uploaded by

shivam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views3 pages

Assignment-2 (Introduction To C Programming and Decision Statement)

The document provides examples for 7 programming assignments for a C programming lab. The assignments include: 1) swapping variables with and without a third variable, 2) getting input of a number and its number of digits, 3) calculating age based on date of birth input, 4) determining parity of a binary number, 5) printing a calendar for a 31 day month, 6) checking if a year is a leap year, and 7) checking if 3 points fall on a straight line. It also provides 3 additional problems: determining character type from ASCII value, checking triangle type based on side lengths, and evaluating pass/fail/retake status of a student based on marks in 2 subjects.

Uploaded by

shivam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Computer Programming Lab (CSI102) Session: Winter 2019-20

II Common Section C Date: 09.01.2020

Assignment-2 (Introduction to C programming and decision statement)

1. Write a C program to do the following:


a. Swap two variables using third variable.
b. Swap two variables without using third variable.

Sample Input:

Sample Output:

2. Take a number as an input, print the number and number of digits in the number using
only “printf()” statement(s).

Sample Input:
Enter the number:

Sample Output:
Number is: and the numbers of digits are:

3. Write a C program that takes the date of birth of the person as input in
and calculate the present age of the person. You should print the age in the format of
formate.

Sample Input:
Enter the date of birth:

Sample Output:
The present age is:

4. Parity of a number is used to define if the total number of set-bits(1-bit in binary


representation) in a number is even or odd. If the total number of set-bits in the binary
representation of a number is even then the number is said to have even parity,
otherwise, it will have odd parity. Write a C program that takes a number n as input and
prints that whether the number is odd parity or even parity.

Sample Input:
Enter

Sample Output:
Odd parity
5. Write a C program to print the calendar of a month of 31 days. The program would ask
for the day on which the first date of the month occurs.

Sample Input:
Enter the day of the 1st date of month: Wednesday

Sample Output

Mon Tue Wed Thu Fri Sat Sun

1 2 3 4 5

6 7 8 9 10 11 12

13 14 15 16 17 18 19

20 21 22 23 24 25 26

27 28 29 30 31

6. Write a program that takes the year as input and determines whether it’s a leap year or
not.

Sample Input:
Enter year: 2020

Sample Output:
It’s a leap year!!!

7. Given three points and , write a program to check if all the


three points fall on one straight line.
Sample Input:
Enter the points: (1, 1), (2,4), (1,5)
Sample Output:
They don’t fall on one straight line
Additional Problems
1. Any character is entered through the keyboard; write a C program to determine whether
the character entered is a capital letter, a small case letter, a digit or a special symbol.
The following table shows the range of ASCII values for various characters.

Character ASCII Values


A-Z 65-90
a-z 97-122
0-9 48-57
Special symbols 0-47, 58-64, 91-96, 123-127

Sample Input:
Enter the character: A

Sample Output:
It’s a capital letter.

2. If the three sides of a triangle are entered through the keyboard, write a program to check
whether the triangle is isosceles, equilateral, scalene or right angled triangle.

Sample Input:
Enter the sides: 3, 4, 5

Sample Output:
It’s a right angled triangle.

3. A university has the following rules for a student to qualify for a degree with A as the
main subject and B as the subsidiary subject:

(a) He should get or more in A and or more in B.


(b) If he gets less than in A then he should get or more in B. However, he
should get at least in A.
(c) If he gets less than in B and or more in A, he is allowed to reappear in an
examination in B to qualify.
(d) In all other cases he is declared to have failed.

Write a program to receive marks in A and B and Output whether the student has passed,
failed or is allowed to reappear in B.

Sample Input:
A = 68, B = 40
Sample Output:
Student can reappear for the exam

You might also like