Department of Computer Science and Engineering School of Engineering and Technology Lab Sheet. 1 & 2 Given Date: 6 th September, 2016 Subject: Advanced Concepts of C Programming Code: CSE-110 Program/Branch: B.Tech/CSE,ME Term/Sec: I/B,A Faculty: Pushpendra K Rajput Session: 2016-2017 Week-1: 6 th September, 2016-11 th September,2016 Note:- Students are supposed to make a separate notebook for Lab Record that S/He has to submit in End-Semester examination for the same Lab. All the programs should be written in your Lab Notebook in the format given in secttions How to solve?. No copied materials will be accepted. Problem-1: Do analyze the following segments of code on your notebook and write conclusion about it. 1.1 #inlclude<stdio,h> printf( Author Name: \n ); printf( B. Tech. 1 st Year\t Section: ); printf( \ndate: \n ); printf( C seems interesting if I practice daily ); printf( \n /n/n \n\n ); printf( 1234\r456789\r00 ); printf( \n\n/n/n/n ); Conclusion: Clearly mention the use of \n \t and \r 1.2 #inlclude<stdio,h> int a,b,c,d; float w,x,y,z; printf( Enter Four integer Values ); scanf( %d%d%d%d,&a,&b,&c,&d); printf( Enter Four floating point value ); scanf( %f%f%f%f,&w,&x,&y,&z); c = a/b; y = a/b;
c = w/x; y = w/x; c = a/x; y = w/b; c = d/3; y = d/3; c = d/3.0; y = d/3.0; c = z/3; y = z/3; c = z/3.0; y = z/3.0; Conclusion: Clearly mention the use of getch() and use of different type of value in an expression (How result is depending on these type) 1.3 #inlclude<stdio,h> int a,b,c,d; a = 7 % 2; b = 23 % -2; c = -53 % 5; d = -34 % -9; printf( a = %d\nb = %d\nc = %d\nd = %d,a,b,c,d); Conclusion: Clearly mention meaning of % operator and also write the sign of result depends on numerator or denominator. 1.4 #inlclude<stdio,h> int a=2, b=3,c=4,d=5,e; float m = 6.0,n = 7.5, p = 1.5,q; e = a / b + c * d;
printf( e = %d\n,e); e = a * b c % (d + a) / b; printf( e = %d\n,e); e = a + m / b c * d; printf( e = %d\n,e); q = a + m / (b c) * d; printf( q = %f\n,q); e = m * n / a c % d * p d; q = c * b / a a % b * p d; printf( e = %f\n,e); printf( q = %f\n,q); Conclusion: Define priority of arithmetic operators 1.5 Write a program in C to calculate average of three numbers. Expected Output: Average of, & is = Problem-2: Write following program in C. 2.1 This problem's challenge is to create each numeric value from 0 to 9 using only four fours!.you are supposed to write 9 different statements similar to following each for one digit printf( Zero is %d,4+4-4-4) Output will be:- Zero is 0 Expected Output: Zero is 0 One is 1 Two is 2 Three is 3 Four is 4 Five is 5 Six is 6 Seven is 7 Eight is 8 Nine is 9 2.2 Write a program that will multiply each digit by 2 of a 4 digit number and map it between 0 and 9 according to following mapping: Calculated Digit 0 2 4 6 8 10 12 14 16 18 Mapped Digit 0 2 4 6 8 0 2 4 6 8 Expected Output: Number after Mapping = Example: Input: 6489 Expected Output: Number after Mapping = 2868
How to solve a problem? Students are advised to follow following approach to complete any Lab problem: Step1: Read Problem statement carefully. Step2:Analyze your problem: (a) Think about Input Requirement: Type of Values, Possible Values, etc. (b) Think about Output Requirement: Type, Format, etc. (c) Think about Process Step3: Develop your Algorithms (Process steps) Step4: Implement your solution on computer. Step5: Compile and resolve errors if any. Step6: Execute your program and get output. Step7: Compare with desired output. Step8: Refine solution if required to get desired output. Step9: Write your Solution in your Lab Record (Flow Chart and C Program only). Exapmle: Problem: Write a program in C that will convert a given number of seconds into equivalent time in terms of Hours, Minutes and seconds. Expecteed Output: Duration = : : How to Write in Lab Notebook: Problem Statement: Write a program in C that will convert a given number of seconds into equivalent time in terms of Hours, Minutes and seconds. Solution: Input : Number of seconds Output: Hrs:Min:Seconds
Flow Chart: Start Input S Hrs = S / 3600 R = S % 3600 Mins = R / 60 Scnds = R % 60 Hrs:Mins:Scnds Stop C Program: /* Programmer Name:------------ Date:----------- Lab Sheet No.:------------- Problem No:--------------*/ #include<stdio.h> //Declare all required variables int Seconds, Hrs, Mins, Scnds, R; //Receive input from user printf( Enter Number of Seconds ); scanf( %d, &seconds); //calculate Hrs, Mins, and Seconds
Hrs = seconds / 36000//return quotient as integer division R = seconds % 3600; Mins = R / 60; Scnds = R % 60; Printf( Duration = %d:%d:%d,hrs,mins,scnds); OUTPUT: Enter Number of Seconds 40000 Duration = 11:6:40