Sei sulla pagina 1di 4

[EE-262 PROGRAMMING WITH C LANGUAGE]

Instructions:
1) The assignment needs to be completed individually. Collaboration with other
students is not allowed however sharing of ideas is acceptable here ideas
strictly mean ideas and not codes. You also need to provide reference of person
with whom you have shared ideas.
2) The theme of this assignment is DIY (Do It Yourselves), however you can take help
from books, internet, discussion forums etc on one condition only; provide
complete and proper reference at every point where you have used these
resources.
3) Method of referencing:
Put an asterisk [ * ] at the point of reference in the program and at the foot of the
same page provide the reference starting with the asterisk [ * ]. For a second or
third reference use two or three asterisks respectively [ ** , *** ].
The reference at the foot should be complete like:
*www.cprogramming.com/steve_summit/q%27_35%20.htm
**Introduction to C Programming by Paul Wolfowitz, Page 39-40
***Idea taken form Muhammad Ahmed, TE(Electronic), Section A, Roll No.: EL-133
4) The assignment needs to be submitted online. Method of submission is to put all
your c/cpp files inside a folder finally compressing it as .zip or .rar which needs to
be sent. This zip/rar folder should be named in exactly the following way:
rollNo_name_section.zip/rar
Examples : EE112_zubair_B,
characters are allowed].

EE4_ahmed_C [Note: No spaces or special

Non-compliance in following this method shall lead to rejection of your


assignment. The email should be sent to your respective theory teachers Mr. Iqbal
Azeem (iqbal.azeem@neduet.edu.pk) and Mr. Muhammad Hassan ul Haq
(muhammad_hassanulhaq@yahoo.com).
5) Programs made for each question should be tested on the compiler. If any of them
are not running satisfactorily by the end of deadline, do mention it in comments.
6) Answers should be saved in files with proper names like question1.cpp,
question2.cpp etc.
7) Sessional marks for this assignment are 07equally divided among all questions.
8) If you are using any technique/function/library not covered in the course to solve
the problems, provide brief documentation and reference for them in comments.
9) Non-compliance with any of these instructions shall lead to deduction of marks.
10) Assignment submission deadline: 18-09-2014
REMEMBER: Assignments shall be compared for similarities and checked for
plagiarism. Remember the rule of prudence: Copying is a Crime punishable by
deduction of marks.
Question 1:
Write a program that asks user to enter an integer and performs the following operations
on it:
1)
2)
3)
4)

Counts the number of digits in it.


Calculate the sum of all digits.
Tell how many times a digit is present.
Reverses the integer digits and stores in another integer variable.

[EE-262 PROGRAMMING WITH C LANGUAGE]


Note: You can use only one loop in this program with multiple decision making
statements in it.

Sample Run:
Enter an integer: 12454 [user presses ENTER]
No. of digits: 5
Sum of digits: 16
1 is present 1 time(s)
2 is present 1 time(s)
4 is present 2 time(s)
5 is present 1 time(s)
Reversed value: 45421
Program End

Question 2:
Write source code in C to convert a decimal integer taken from user into its binary
equivalent. The binary equivalent should be stored in an integer variable.
A problem might arise in this program: the binary equivalent would overflow the range
of int variable even for a small decimal number. Make your program defensive against
the situation of overflow by stopping the conversion for those decimal numbers that
might cause it. You can use sizeof() function to calculate the bytes of integer variable
used for conversion and decide what maximum value you would allow for conversion.
Note: First write the basic conversion then solve the mentioned problem.
Question 3:
The LCM of two integers A and B is the smallest positive integer that is a multiple of both
A and B.
Mathematically,
LCM(A,B)=C
And an important property being:
LCM(A,0)=0
Write a program that calculates the LCM of two (2) positive integers entered by the user.
Note: Take help from math resources (books, internet etc) to clarify your LCM concept
first and write the program later.

[EE-262 PROGRAMMING WITH C LANGUAGE]


Question 4:
Write a program that continuously takes a character from user and if it is a small letter
converts it into capital letter and prints it on the console screen. If the character is
neither a small letter nor a special character, it gets printed unchanged.
Note: Use character counting program made in while() loop class to start solving this
problem and take help of the ASCII chart.
Question 5:
Pythagorean triples are any group of three numbers for which the following property
holds:
x2 + y2 = z2
where x,y and z are all integers.
Write a program that prints all possible Pythagorean triples between 0 and 1000.
Note: This is a problem of nested loop.
Question 6:
Write a program to print the following pattern on console screen.
*
*
**
**
***
***
**** ****
***** *****
************
Note: Nested loops are required to solve this problem. The outer loop controls the rows,
and three inner loops print asterisks, spaces and asterisks respectively.
Question 7:
A computer geek goes to a departmental store for shopping and buys commodities worth
Rs. 740. As he goes to the cash counter for payment and draws his wallet from pocket,
he is horrified to know that his credit card is left at home and he is only carrying paper
money; 10 hundred Rupee notes, 7 fifty Rupee notes and 20 ten Rupee notes. As he is a
geek and has never used paper money he is unable to calculate the right number of
notes of different denominations he needs to pay.
The geek has a latest smart phone with him which has a portable C compiler installed.
Help him in writing a C program that takes these inputs: Total amount to be paid and the
number of currency notes of different denominations present with him. The program then
works out one combination of different notes that he can give to the cashier.
Note: Nested loops are required here, one for each currency denomination. Consider only
three currency denominations; hundred, fifty and twenty. You are required to break out of
the whole nested structure simultaneously when the desired condition is met.

[EE-262 PROGRAMMING WITH C LANGUAGE]

Potrebbero piacerti anche