DSA - Lab1 Basic Concepts in C
DSA - Lab1 Basic Concepts in C
DSA - Lab1 Basic Concepts in C
Lab Manual 01
CS201L: Data Structure and Algorithms
Class: BSCS-2k22
Lab 1: Basic concepts in C++
Instructors:
Mr. Awais Mehmood
awais.mehmood@uettaxila.edu.pk
&
Mr. M. Faheem Saleem
muhammad.faheem@uettaxila.edu.pk
Lab Manual 1
Introduction
This lab is about the basic concepts of C++.
Objectives
This lab will revise the old concepts of the students, taught in the previous semesters and some
more during the first week of the course.
Tools/Software Requirement
Dev C++
Goals for today’s lab:
Task 1:
Write a program that takes a year (e.g. 2018 or 1998) as input and checks if the year is a leap
year.
Hint: A year is a leap year if it is divisible by 4, but not divisible by 100. For example, 1992 and
2008 are divisible by 4, but not by 100. A year that is divisible by 100 is a leap year if it is also
divisible by 400. For example, 1600 and 2000 are divisible by 400. However, 1800 is not a leap
year because 1800 is not divisible by 400.
Sample output 1:
Please enter year: 1996
Year is leap year
Sample output 2:
Please enter year: 2000
Year is not a leap year
Task 2:
Write a program that takes a number as input and prints the digits of number in reverse order and
with a separator.
Hint: Use while loop to check if the number is still greater than 10 and find remainder with
required number.
Sampleoutput 1:
Please enter a number: 156
The number with separators is: 6 | 5 | 1
Sample output 2:
Please enter a six digit number: 42389
The number with separators is: 9 | 8 | 3 | 2 | 4
Task 3:
Write a program that takes number of seconds elapsed as input e.g. (87792) and outputs the time
in hours: minutes: seconds format as hh: mm: ss. See the sample output
Sample output 1:
Please enter number of seconds: 87792
The time in required format is: 24:23:12
Sample output 2:
Please enter number of seconds: 43834
The time in required format is: 12:10:34
Task 4:
This problem is typical Number classification system. In the simplest form when the program
starts it prompts the user to enter some numbers. The User enters space separated numbers. The
program then responds by printing number of even, odd and zeros in the list entered by user.
Sample output:
Please enter 10 number: 23 23 12 0 43 23 3 2 43 56
There are 3 even 7 odd and 1 zeros in the list