Ee-262 Programming With C Language: Group Assignment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

[EE-262 PROGRAMMING WITH C LANGUAGE]

Instructions:

Group Assignment

1) The assignment needs to be completed in a group of four [04] only. Collaboration between the members and sharing of ideas is highly recommended. 2) The theme of the assignment is DIY (Do It Yourselves), however you can take help from books, internet, discussion forums etc on one condition; 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 or any other point 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 ***Idea taken form Muhammad Ahmed, TE (Electronic), Section A, Roll No.: EL-133 4) The assignment needs to be submitted by email. Make all programs on compiler and then save them in a single word file. One group should submit only one word file comprising of solutions to all questions. The name of the word file should be given in the following way: Section#_Members_###_###_###_###.doc If students bearing roll numbers EE-122, EE-89, EE-80, EE-100 are submitting the assignment from section B then the filename would be: SectionB_Members_122_89_80_100.doc. 5) Submit assignments directly at [email protected] on or before midnight of 24-10-2012. If any assignment is submitted over the yahoo group, 5 marks shall be deducted from each members sessional marks. 6) The word file must carry the following information: Member Name Roll No. 1. -------EE-## 2. ------------------ EE-### 3. -----------EE-## 4. --------------EE-## Questions Attempted 7) 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 with the respective answers. 8) Answers should be attempted in order of the question numbers. Writing the question is not mandatory but recommended. 9) Sessional marks for the test are 14 equally divided among all questions. Challenge Questions are separately counted resulting in bonus marks. 10) If you are using any technique/function/library not covered in the course to solve the problems, provide brief documentation and reference for them. 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.

[EE-262 PROGRAMMING WITH C LANGUAGE]


Section A: General Algorithms Question 1:

Group Assignment

Write a program that asks the user to enter an integer and performs the following operations on it: 1) Counts the number of digits in it. 2) Calculate the sum of all digits. 3) Tell how many times a number is present. 4) Reverses the integer digits in another integer variable. [see challenge section for the same problem] Sample Run: Enter an integer: 12454 [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

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. Question 3: The LCM of two integers A and B is the smallest positive integer that is completely divisible by both A and B. Mathematically, LCM(A,B)=C And an important property being:

[EE-262 PROGRAMMING WITH C LANGUAGE]


LCM(A,0)=0

Group Assignment

Write a program that calculates the LCM of three (3) positive integers entered by the user. Question 4: The Newton Raphson method of calculating square roots can be extended to calculate the [a/b]th power of any number N N(a/b) = (N(1/b))a where a and b are integers.

That is first calculate the bth root of N and then raise the answer to power a. Write a program that asks the user to enter the number N and its power a/b and calculates the answer Na/b. Sample Run: Enter a number: 12.67 [ENTER] Enter the power: 4/3 [ENTER] [use scanf(%d/%d,&a,&b); to get input in this form; if you write anything inside the quotes of scanf the user has to reciprocate in the same way] 12.67 raised to 4/3 is = 1.333334 The catch here is in the Newton Raphson equation which is going to calculate the bth root: X2 =X1 f(X1)/d/dx(f(X1)) f(X1) is the function generally written as: f(X1) = (root*root*root*root*.root)b-N derivative of f(X1) is generally written as: d/dx*f(X1)+ = b*(root*root*root*root*.root)(b-1) Values of f(X1) and d/dx[f(X1)] can be calculated inside loops written inside the main loop. Question 5: Three dice are rolled together. The first one is cubical with six faces numbered 1 to 6. The second and third are both dodecahedral with twelve faces numbered 1 to 12. Write a program that calculates the probability of all events in which the sum of numbers from the three dice is 20. Question 6:

[EE-262 PROGRAMMING WITH C LANGUAGE]

Group Assignment

The factorial of an integer n, written n!, is the product of all the integers from 1 to n inclusive. The factorial quickly becomes very large; 13! is too large to store as an integer on most computers, and 35! is too large for a floating-point variable. Your task is to write a program to find the rightmost non-zero digit of n!. For example, 5! = 1 * 2 * 3 * 4 * 5 = 120, so the rightmost non-zero digit of 5! is 2. Also, 7! = 1 * 2 * 3 * 4 * 5 * 6 * 7 = 5040, so the rightmost non-zero digit of 7! is 4. Section B: Functions Question 7: Write a function that takes a character and the dimension of a square as input and plots the square on the screen filled with those characters with the specified dimensions. The function prototype is : int squareplot(char ch, int dimension); The returned integer is zero for no errors in dimension and -1 for dimension<0. The function might use the gotoxy() function within itself. When used in the main program, the function should produce the following results. Sample Run Enter the character: + [ENTER] Enter the dimensions of square: 5 [ENTER] +++++ +++++ +++++ +++++ +++++ [both values passed to squareplot()]

Question 8: Write a recursive function that calculates the GCD of two positive integers and handling all possible wrong inputs. Apart from the program also specify the base case and inductive steps. Question 9: Write a recursive function that calculates and returns the power of a base raised to an exponent. The two inputs to the function are base and exponent which are integers. Apart from the program also specify the base case and inductive steps.

[EE-262 PROGRAMMING WITH C LANGUAGE]


Section C: Arrays Question 10:

Group Assignment

Write a program that asks the user to enter numbers into a float array and then find the mean, median and mode of that data set. The number of elements in the array is unspecified meaning you need a while loop to enter elements. The program must take care of multiple modes and display them all. Question 11: Write a function that takes an MxN 2D array from the main program and returns its inverse back to main. The function should find ad-joint matrix and transpose in an automatic manner using loops. The function should return 1 if the given matrix is invertible and -1 if not. Section D: Challenge Question 12: bonus=2 Reversing the digits of an integer requires calculating the number of digits in it. Write a program that reverses the digits of one integer saving the reversed form in another without finding the number of digits. The program should be simpler that the previous one. Question 13: bonus=6 Write a recursive function that performs sorting on an array using the quick sort algorithm.

You might also like