KIT-Kalaignarkarunanidhi Institute of Technology C Programming Past Paper PDF
Document Details
Uploaded by NobleSquirrel
KIT-Kalaignar Karunanidhi Institute of Technology
Tags
Summary
This document is a past paper for a C programming course at KIT-KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY. It contains instructions for laboratory classes, as well as the vision and mission statements of the school, along with programme outcomes for computer science and engineering students.
Full Transcript
KIT- KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY (AN AUTONOMOUS INSTITUTION) (Accredited by NAAC & NBA with ‘A’ Grade) Kannampalayam Post, Coimbatore -641 402 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B23CSI101 - C PROGRAMMING Nam...
KIT- KALAIGNAR KARUNANIDHI INSTITUTE OF TECHNOLOGY (AN AUTONOMOUS INSTITUTION) (Accredited by NAAC & NBA with ‘A’ Grade) Kannampalayam Post, Coimbatore -641 402 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B23CSI101 - C PROGRAMMING Name …………………………………………………………………………. Batch …………………….. Reg. No. ………………….…….… Branch ………………………. Year ………………………………. KIT-Kalaignarkarunanidhi Institute of Technology (An Autonomous Institution, Approved by AICTE & Affiliated to Anna University, Chennai) Coimbatore – 641 402 Department of ……………………………………………………………………………………………… Record Work of ….............................................................................................................................. Laboratory Certified that this record is the bona fide work done by Name:……………………………………………………………………………………………… Class:…………………………………….. Roll No:……………………………………… Branch……………………………………………………………………………………………….. Place: KIT, CBE Faculty In-Charge HOD Date: University Register No…………………………………………… Submitted for the University Practical Examination held on ………………………………………………… Internal Examiner External Examiner Instructions for Laboratory Classes 1. Enter the lab with record workbook & necessary things. 2. Enter the lab without bags and footwear. 3. Footwear should be kept in the outside shoe rack neatly. 4. Maintain silence during the Lab Hours. 5. Read and follow the work instructions inside the laboratory. 6. Handle the computer systems with care. 7. Shutdown the Computer properly and arrange chairs in order before leaving thelab. 8. The program should be written on the left side pages of the record work book. 9. The record workbook should be completed in all aspects and submitted in the nextclass itself. 10. Experiment number with date should be written at the top left-hand corner of the record work book page. 11. Strictly follow the uniform dress code for Laboratory classes. 12. Maintain punctuality for lab classes. 13. Avoid eatables inside and maintain the cleanliness of the lab. VISION To transform learners into competent industry ready innovative computer science professionals with managerial people skills and social values to contribute to the society. MISSION To induce and develop student ability to compete globally through excellence in education. To impart technical knowledge through innovative teaching, research, and consultancy. To create healthy environment for developing innovative ideas. To facilitate students’ development through academic-industry interaction. To enhance quality professionals for development of the socio-economic structure. PROGRAMME OUTCOMES (POs) After the successful completion of the U.G. programme in Computer Science and Engineering, Graduates will be able to: PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an engineering specialization to the solution of complex engineering problems. PO2: Problem analysis: Identify, formulate, review research literature, and analyze complex engineering problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and engineering sciences. PO3: Design/development of solutions: Design solutions for complex engineering problems and design system components or processes that meet the specified needs with appropriate consideration for the public health and safety, and the cultural, societal, and environmental considerations. PO4: Conduct investigations of complex problems: Use research-based knowledge and research methods including design of experiments, analysis and interpretation of data, and synthesis of the information to provide valid conclusions. PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT tools including prediction and modeling to complex engineering activities with an understanding of the limitations. PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice. PO7: Environment and sustainability: Understand the impact of the professional engineering solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable development. PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering practice. PO9: Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams, and in multidisciplinary settings. PO10: Communication: Communicate effectively on complex engineering activities with the engineering community and with society at large, such as, being able to comprehend and write effective reports and design documentation, make effective presentations, and give and receive clear instructions. PO11: Project management and finance: Demonstrate knowledge and understanding of the engineering and management principles and apply these to one’s own work, as a member and leader in a team, to manage projects and in multidisciplinary environments. PO12: Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent and life-long learning in the broadest context of technological change. PROGRAM EDUCATIONAL OBJECTIVES (PEOs) PEO1: Graduate will be successful in their profession by taking part actively in the field of software and technology. PEO2: Graduate will be proficient in analyzing and facing the challenge in computer science and engineering. PEO3: Graduate will engage in lifelong learning activities by adapting to the advanced software technologies for continuous professional development. PROGRAM SPECIFIC OUTCOME (PSOs) After the successful completion of the U.G. programme in Computer Science and Engineering, Graduates will be able to: PSO1: Categorize the basic engineering knowledge to solve the problems in Computer Science and Engineering according to the environmental needs PSO2: Apply the modern tools to design and develop the software system ethically to the industrial needs COURSE OUTCOMES At the end of this course, the student will be able to: Course Outcomes Knowledge Level CO1: Demonstrate knowledge on C programming constructs K2 CO2: Construct C programs using decision making and control statements. K3 CO3: Experiment with programs in C using an array K3 CO4: Build programs in C using strings, pointers, functions K3 K3 CO5: Model the applications in C using Structures, Union and File Operations CO-PO Mapping Table PO6 PO7 PO8 PO11 PSO1 PSO2 PO1 PO2 PO3 PO4 PO5 PO9 PO10 PO12 (K3 (K3 CO/PO & PSO (K3) (K2) (K3) (K3) A3) A3) (K3) (K4) (K5) (K5) (K6) (A3) (A3) (A3) (A3) (A3) (A3) (A3) CO1 K2 3 2 1 - 1 - - - 1 - - 1 2 1 CO2 K3 3 2 1 - 1 - - - 1 - - 1 2 1 CO3 K3 3 2 1 - 1 - - - 1 - - 1 2 1 CO4 K3 3 2 1 - 1 - - - 1 - - 1 2 1 CO5 K3 3 2 1 - 1 - - - 1 - - 1 2 1 Weighted 3 2 1 - 1 - - - 1 - - 1 2 1 average 3-Strong 2- Moderate 1- Weak SYLLABUS LIST OF EXPRIMENTS 1. Experiment with I/O statements, operators, expressions 2. Develop C programs for Decision Making Construct. a) if-else b) switch-case c) goto, break-continue 3. Develop a Cprograms for Loop Control statements. a) for b) Nested for c) while and do-while 4. Develop a C programs for Array a) One Dimensional – Sorting and Searching b)Two Dimensional – Matrix Operations c) Traversal 5. Develop a C program to perform the pointers Linear Search b) Binary Search c) Pointer Operation 6. Build a C programs for the recursive function 7. Implement a C programs for string operations String operations using build in methods 8. Develop a C program to experiment with Pass by value and Pass by Reference 9. Develop a c program for structure and union a) Payroll using structure and union b) Student records using structure and union. 10. Develop a C program to perform file operations Total Instructional hours: (45+15) = 60 CONTENT S. No Title of the Experiment Page No 1(a) C program for formatted and unformatted input and output statements 1(b) C program to perform operations on operators and expressions. C program to check whether the given number is positive number or negative 2(a) number using if-else statement. C program to design a menu-based calculator to perform various basic arithmetic 2(b) operations like addition, subtraction, multiplication, division and modulo. 2(c) C program for decision making using goto, break and continue statement 3(a) C program to input a number and calculate its factorial using while loop 3( 3(b) C program to input a number and calculate sum of digits using do-while loop. C program to input a number and check whether the number is prime number or not 3(c) using for loop. 3(d) C program to find the prime numbers from 2 to 50 using nested for loop. 4 (a)(i) C program to input elements in array and sort array elements in ascending order 4(a)(ii) C program to input elements in array and search whether an element exists in array ornot. 4(b)(i) C program to implement matrix addition 4(b)(ii) C program to implement matrix subtraction 4(b)(iii) C program to implement matrix multiplication 4(c) C program to read square matrix of order n, transpose it using user defined function. 5 (a) C program to search(linear) an element from an array using pointers 5 (b) C program to perform binary search using pointers 5 (c) C program to read two numbers from user and add them using pointers. 6 C program to find the factorial of a given number using recursion 7 (a) C program to find the length of the string using strlen() function. 7 (b) C program to perform the string copy using strcpy() function. 7 (c) C Program to compare two strings using strcmp() Function. 7 (d) C Program to concatenate two strings using strcat() function 8 (a) C program to swap two numbers using call by value. 8 (b) C Program to Sort the list of numbers using pass by reference. 9 (a) C Program to maintain students records using structure. 9 (b) C Program to create payroll processing using union. 10 (a) C program to display the contents of a file. 10 (b) C program to copy the contents of one file to another S. Experi Prerequisites Learning Objectives No ment 1. To know the basics of problem-solving techniques. 2. To provide exposure to problem-solving through programming. For All Basics of computer 3. To develop C programming language with 1 Experiments programming conditional statements and loops 4. To develop modular applications in C using functions pointers and structures 5. To do input/output and file handling in C Ex. No. Date Name of the Experiment Page Number Aim & Algorithm (20marks) Program (25marks) Practical Record Book Index Page Output & Interface (10 marks) Viva Voce (20 marks) Total (75 marks) Signature of the Faculty Member Ex. No. Date Name of the Experiment Page Number Aim & Algorithm (20marks) Program (25marks) Output & Interface (10 marks) Viva Voce (20 marks) Total (75 marks) Signature of the Faculty Member Ex. No. Date Model Exam Marks (25): Total (100): Name of the Experiment Page Number Aim & Algorithm (20marks) Program (25marks) Output & Interface (10 marks) Viva Voce (20 marks) Total Signature of the Faculty Member (75 marks) Signature of the Faculty Member B23CSI101 C PROGRAMMING Ex. No. 1(a) Date EXPERIMENT WITH I/O STATEMENTS AIM: To write a C program for formatted and unformatted input and output statements. ALGORITHM: STEP 1: Start the program. STEP 2: Declare all the required variables. STEP 3: Get input values from the user output using formatted and unformatted input statement. STEP 4: Display the output using formatted and unformatted output statement. STEP 5: Stop the program. 14 B23CSI101 C PROGRAMMING PROGRAM: #include #include int main() { int num1; float num2; char ch; char str[]="Hello World"; printf("Enter an integer: "); scanf("%d", &num1); printf("Enter a float: "); scanf("%f", &num2); printf("Enter a character: "); scanf("%c", &ch); printf("Formatted Input and Output:\n"); printf("Integer: %d\n", num1); printf("Float: %f\n", num2); printf("Character: %c\n", ch); printf("Unformatted Input and Output:\n"); printf("Enter a string: "); gets(str); puts(str); return 0; } 15 B23CSI101 C PROGRAMMING OUTPUT: Enter an integer: 45 Enter a float: 56.9 Enter a character: g Formatted Input and Output: Integer: 45 Float: 56.900002 Character: g Unformatted Input and Output: Enter a string: Welcome Welcome 16 B23CSI101 C PROGRAMMING Ex. No. 1(b) Date EXPERIMENT WITH OPERATORS AND EXPRESSIONS AIM: To write a C program to perform operations on operators and expressions. ALGORITHM: STEP 1: Start the program STEP 2: Declare all required variables and initialize them. STEP 3: Calculate the expression using operators. STEP 4: Display the Output. STEP 5: Stop the program. 17 B23CSI101 C PROGRAMMING PROGRAM: #include #include int main() { // Arithmetic Operators int num1 = 10,num2 = 5; int sum = num1 + num2; int difference = num1 - num2; int product = num1 * num2; int quotient = num1 / num2; int remainder = num1 % num2; printf("Arithmetic Operators:\n"); printf("Sum: %d\n", sum); printf("Difference: %d\n", difference); printf("Product: %d\n", product); printf("Quotient: %d\n", quotient); printf("Remainder: %d\n", remainder); // Relational Operators int a=5,b=8; printf("\nRelational Operators:\n"); printf("%d is equal to %d: %d\n", a,b,a==b); printf("%d is not equal to %d: %d\n",a,b,a!=b); printf("%d is greater than %d: %d\n", a, b, a > b); printf("%d is less than %d: %d\n", a, b, a < b); printf("%d is greater than or equal to %d: %d\n", a, b, a >= b); printf("%d is less than or equal to %d: %d\n", a, b, a num2) ? num1 : num2; printf("The maximum number is: %d\n", max); return 0; } 19 B23CSI101 C PROGRAMMING OUTPUT: Arithmetic Operators: Sum: 15 Difference: 5 Product: 50 Quotient: 2 Remainder: 0 Relational Operators: 5 is equal to 8: 0 5 is not equal to 8: 1 5 is greater than 8: 0 5 is less than 8: 1 5 is greater than or equal to 8: 0 5 is less than or equal to 8: 1 Logical Operators: 1 AND 0: 0 1 OR 0: 1 NOT 1: 0 NOT 0: 1 Assignment Operators: c += 2: 5 c *= 4: 20 Bitwise AND: 1 Bitwise OR: 7 Bitwise XOR: 6 Bitwise NOT of a: 4294967290 The maximum number is: 10 20 B23CSI101 C PROGRAMMING INFERENCE: VIVA QUESTIONS: 1. Explain the difference between = = and = = = in C language. 2. How does the ternary operator differ from an if-else statement? 3. What happens if an integer number is divided by zero? 4. What is the associativity of operators? 5. What is the precedence of operators? RESULT: 21 B23CSI101 C PROGRAMMING Ex. No. 2(a) C PROGRAM FOR DECISION MAKING USING IF-ELSE Date STATEMENT AIM: To write a C program to check whether the given number is positive number or negative number using if-else statement. ALGORITHM: STEP 1: Start the program. STEP 2: Declare all required variables. STEP 3: Get an input from the user and store it in a variable. STEP 4: Check the input value whether it is a positive number or negative number. STEP 5: If the number is less than ZERO, then print the result as “NEGATIVE”. Otherwise display the result as “POSITIVE”. STEP 6: Stop the program. 22 B23CSI101 C PROGRAMMING PROGRAM: #include #include int main() { int number; printf("Enter a number: "); scanf("%d", &number); if (number > 0) { printf("%d is a positive number.\n", number); } else { printf("%d is a negative number.\n", number); } return 0; } 23 B23CSI101 C PROGRAMMING OUTPUT: Enter a number: -9 -9 is a negative number. 24 B23CSI101 C PROGRAMMING Ex. No. 2(b) C PROGRAM FOR DECISION MAKING USING SWITCH - CASE Date STATEMENT AIM: To write a C program to design a menu-based calculator to perform various basic arithmetic operations like addition, subtraction, multiplication, division and modulo. ALGORITHM: STEP 1: Start the program. STEP 2: Declare all required variables STEP 3: Get two inputs from the user using scanf() function and store them in “a” and “b” respectively STEP 4: Get the user option and based on the user options, perform the corresponding arithmetic operations on the user data. STEP 5: Store the result in a variable called “c” and display the value of “c” using printf() STEP 6: Stop the program 25 B23CSI101 C PROGRAMMING PROGRAM: #include #include int main() { int choice; double num1, num2, result; // Display the menu printf("Menu:\n"); printf("1. Addition\n"); printf("2. Subtraction\n"); printf("3. Multiplication\n"); printf("4. Division\n"); printf("Enter your choice (1-4): "); scanf("%d", &choice); // Prompt the user to enter two numbers printf("Enter two numbers: "); scanf("%lf %lf", &num1, &num2); // Perform the calculation based on user choice switch (choice) { case 1: result = num1 + num2; printf("Result: %.2lf\n", result); break; case 2: result = num1 - num2; printf("Result: %.2lf\n", result); break; case 3: result = num1 * num2; printf("Result: %.2lf\n", result); break; case 4: // Check for division by zero if (num2 != 0) { result = num1 / num2; printf("Result: %.2lf\n", result); } else { printf("Error: Division by zero is not allowed.\n"); } break; default: printf("Invalid choice! Please enter a number between 1 and 4.\n"); } return 0; } 26 B23CSI101 C PROGRAMMING OUTPUT: Menu: 1. Addition 2. Subtraction 3. Multiplication 4. Division Enter your choice (1-4): 3 Enter two numbers: 2 3 Result: 6.00 27 B23CSI101 C PROGRAMMING Ex. No. 2(c) C PROGRAM FOR DECISION MAKING USING GOTO, BREAK AND Date CONTINUE STATEMENT AIM To write a C program for decision making using goto, break and continue statement. ALGORITHM STEP 1: Start the program STEP 2: Declare and intialize the necessary variables. STEP3: Goto: The for loop and a goto statement is used to skip printing the number 2. The label skip is used as the target of the goto statement. STEP 4: Break: The for loop and the break statement is used to exit the loop when i becomes 3. STEP 5: Continue: The for loop and the continue statement is used to skip printing the number 2 and continue with the next iteration. STEP 6: Display the output STEP 7: Stop the program. 28 B23CSI101 C PROGRAMMING PROGRAM: #include int main() { int i; // Example of using goto printf("Example of using goto:\n"); for (i = 0; i < 5; ++i) { if (i == 2) { goto skip; // Jump to the 'skip' label } printf("%d ", i); skip:; // Label 'skip' } printf("\n"); // Example of using break printf("\nExample of using break:\n"); for (i = 0; i < 5; ++i) { if (i == 3) { break; // Exit the loop when i is 3 } printf("%d ", i); } printf("\n"); // Example of using continue printf("\nExample of using continue:\n"); for (i = 0; i < 5; ++i) { if (i == 2) { continue; // Skip the rest of the loop body when i is 2 } printf("%d ", i); } printf("\n"); return 0; } 29 B23CSI101 C PROGRAMMING OUTPUT: Example of using goto: 0134 Example of using break: 012 Example of using continues: 0134 30 B23CSI101 C PROGRAMMING INFERENCE VIVA QUESTIONS 1. What is the purpose of the goto statement in C? 2. What is the significance of labels when using the goto statement? 3. What are case labels in a switch statement? 4. How does the continue statement influence the flow of a loop? 5. What would happen if the continue statement is not used in a loop? RESULT 31 B23CSI101 C PROGRAMMING Ex. No. 3(a) C PROGRAM BY USING WHILE, DO-WHILE AND FOR LOOPS. Date AIM: To Write a C program to input a number and calculate its factorial using while loop. ALGORITHM: STEP 1: Start the program STEP 2: Declare a variable (int fact) and initialize it with 1. STEP 3: Read a number whose factorial is to be found. Store it in a variable (int num). STEP 4: Set the while loop to the condition (i