Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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].
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.