Sei sulla pagina 1di 2

CP-II

Assignment 1

Note: main()
{
int marks;
printf(\n Deadline for the submission : Before your 2nd Sessional Examination);
printf(For the following condition consider your first sessional CP-II marks);
if(marks >=25 )
printf(\n You have to Solve Question 1 to Question 5);
else
printf(\n You have to Solve Question 6 to Question 10);
}
1) Create a Time zone convertor application. As an input take Indian time (in hr:min:sec format)
and based on the user choice convert that time in the timezone of one of the following country.
USA/Pakistan/Srilanka/Dubai/Nepal
i)
India is 10 hours and 30 minutes ahead of Washington, DC, USA
ii)
India is 30 minutes ahead of Pakistan
iii)
There is no time difference between India and Sri Lanka
iv)
India is 1 hour and 30 minutes ahead of Dubai - United Arab Emirates
v)
Nepal is 15 minutes ahead of India.
(Optional question: Interested student can take time in following format dd:mm:yy:hh:mm:ss
and also change date appropriately if required.)
2) Write C program to add two distances using function. Where distance entered by user is in
following format km:m:cm:mm.(Recall that :1km = 1000m, 1m = 100cm, 1cm = 10mm ).
3) Given a time, calculate the angle between the hour and minute hands clockwise.Example
Answers to verify your solution:

3:27 58.5 degree

7:35 17.5 degree

4) Self-descriptive number: In mathematics, a self-descriptive number is an integer m that in a


given base b is b digits long in which each digit d at position n (the most significant digit being at
position 0 and the least significant at position b - 1) counts how many instances of digit n are
in m.
5) Write a program to determine the number of bits required to convert integer A to integer B
(example Input: 31 14 Output: 2)

CP-II
Assignment 1
6) Develop a program to take input username and password from user and validate it for following
requirement:
Usernames may contain letters (a-z), numbers (0-9), dashes (-), underscores (_),
apostrophes ('}, and periods (.), and may not contain an equal sign (=) or brackets (<,>).
They can't contain more than one period in a row.
Passwords may contain any combination of ASCII characters, but a minimum of 8
characters is required. Password must contain one upper case letter, one lower case
letter, a number and a symbol.
7) Write a program to swap odd and even bits in an integer and print resultant integer.
(e.g , Input=22(10110) output=25(11001). bit 0 and bit 1 are swapped, bit 2 and bit 3 are
swapped, etc.)
8) Take input number and decide if the sum of its digit is same as multiplication of its digit:
( i.e. 123, 1+2+3 is 6. Same way 1*2*3 is also 6.)
9) W.A.P. to solve following series using user define function.
1 x3/3! + x5/5! + x7/7! - . + n terms sum. (where x and n entered by the user)
10) Write a C Program to check if entered number is armstorng number or not.
A number is armstrong if the sum of cubes of individual digits of a number is equal to the
number itself. For example 371 is an armstrong number as 33 + 73 + 13 = 371

Potrebbero piacerti anche