├── LICENSE.md ├── README.md ├── Semester 3 ├── Code Optimization and Debugging-I │ ├── C++ │ │ ├── Exp_01 - Palindrome.cpp │ │ ├── Exp_02 - Reverse Digits.cpp │ │ ├── Exp_03 - Lowercase to Uppercase.cpp │ │ ├── Exp_04 - Fibonacci Series.cpp │ │ ├── Exp_05 - Sort Elements of Array in Ascending Order.cpp │ │ ├── Exp_06 - Multiply 2 Matrices.cpp │ │ ├── Exp_07 - Vowel or Consonant.cpp │ │ ├── Exp_08 - Prime or Not.cpp │ │ ├── Exp_09 - Calculate Gross Salary.cpp │ │ ├── Exp_10 - Printing Pyramid Patterns.cpp │ │ ├── Exp_11 - Selection Sort.cpp │ │ ├── Exp_12 - GCD of 2 Numbers.cpp │ │ ├── Exp_13 - Sum of Natural Numbers.cpp │ │ ├── Exp_14 - Convert Binary Number to Decimal.cpp │ │ ├── Exp_15 - Robot or Not.cpp │ │ ├── Exp_16 - LCM.cpp │ │ ├── Exp_17 - Leap Year.cpp │ │ ├── Exp_18 - Length of a String.cpp │ │ ├── Exp_19 - Sum of Two Prime Numbers.cpp │ │ ├── Exp_20 - Quotient and Remainder.cpp │ │ └── Exp_21 - Display Factors of a Number.cpp │ ├── C │ │ ├── Exp_01 - Palindrome.c │ │ ├── Exp_02 - Reverse a Given Number.c │ │ ├── Exp_03 - Lowercase to Uppercase.c │ │ ├── Exp_04 - Fibonacci Series.c │ │ ├── Exp_05 - Arrange in Ascending Order.c │ │ ├── Exp_06 - Multiply 2 Matrices.c │ │ ├── Exp_07 - Vowel or Consonant.c │ │ ├── Exp_08 - Prime or Not.c │ │ ├── Exp_09 - Calculate Gross Salary.c │ │ ├── Exp_10 - Pyramids and Patterns.c │ │ ├── Exp_11 - Selection Sort.c │ │ ├── Exp_12 - GCD or HCF of 2 Numbers.c │ │ ├── Exp_13 - Calculate Sum of n Natural Numbers.c │ │ ├── Exp_14 - Convert Binary Number to Decimal.c │ │ ├── Exp_15 - Area and Perimeter of Rectangle.c │ │ ├── Exp_16 - Find nPr.c │ │ ├── Exp_17 - Find nCr.c │ │ ├── Exp_18 - Total Average and Percentage.c │ │ ├── Exp_19 - Even or Odd.c │ │ ├── Exp_20 - Armstrong Number.c │ │ └── Exp_21 - Factorial using Recursion.c │ ├── Java │ │ ├── Exp_01 - Palindrome.java │ │ ├── Exp_02 - Reverse a Given Number.java │ │ ├── Exp_03 - Lowercase to Uppercase.java │ │ ├── Exp_04 - Fibonacci Series.java │ │ ├── Exp_05 - Sort Elements of a List in Ascending Order.java │ │ ├── Exp_06 - Product of 2 Matrices.java │ │ ├── Exp_07 - Prime or Not.java │ │ ├── Exp_08 - Swap 2 Numbers.java │ │ ├── Exp_09 - Reverse a String.java │ │ ├── Exp_10 - Armstrong Number or Not.java │ │ ├── Exp_11 - GCD of 2 Numbers.java │ │ ├── Exp_12 - Display Even Numbers.java │ │ ├── Exp_13 - Case Conversion.java │ │ ├── Exp_14 - Bubble Sort.java │ │ ├── Exp_15 - Power of a Number.java │ │ └── Exp_16 - Largest Element in an Array.java │ └── Python │ │ ├── Exp_01 - Palindrome.py │ │ ├── Exp_02 - Reverse a Number.py │ │ ├── Exp_03 - Lowercase to Uppercase.py │ │ ├── Exp_04 - Fibonacci Series.py │ │ ├── Exp_05 - Sort Elements of a List in Ascending Order.py │ │ ├── Exp_06 - Product of 2 Matrices.py │ │ ├── Exp_07 - Vowel or Consonant..py │ │ ├── Exp_08 - Prime Number.py │ │ ├── Exp_09 - Prime or Not.py │ │ ├── Exp_10 - Calculate Gross Salary.py │ │ ├── Exp_11 - Pyramid Patterns.py │ │ ├── Exp_12 - Selection Sort.py │ │ ├── Exp_13 (a) - Implement Functions and Libraries.py │ │ ├── Exp_13 (b) - Implement Functions and Libraries.py │ │ ├── Exp_14 - List Built-in Functions.py │ │ ├── Exp_15 - List Library Functions.py │ │ ├── Exp_16 - Optimizing Loop.py │ │ ├── Exp_17 - GCD of 2 Numbers.py │ │ ├── Exp_18 - Sum of Natural Numbers Using Recursion.py │ │ ├── Exp_19 - Convert Binary Number to Decimal.py │ │ ├── Exp_20 - Factorial Program with Memoization.py │ │ ├── Exp_21 - Factorial of a Number.py │ │ ├── Exp_22 - Implementation of MergeSort.py │ │ ├── Exp_23 - Perform Basic timSort.py │ │ ├── Exp_24 - Insert N elements in a Linked List.py │ │ ├── Exp_25 - Monitoring Memory Usage.py │ │ ├── Exp_27 - Anonymous Function.py │ │ ├── Exp_28 - Heap Sort.py │ │ ├── Exp_29 - Shell Sort.py │ │ ├── Exp_30 - Bubble Sort.py │ │ ├── Exp_31 - Merge Sort.py │ │ └── Exp_32 - Radix Sort.py ├── Database Management Systems │ ├── Exp_01 - Create a Table and Display Structure of Table.sql │ ├── Exp_02 - Inserting a New Record into Table and Display Contents of the Table.sql │ ├── Exp_03 - Create a Table, Insert Records, Delete Records from Table.sql │ ├── Exp_04 - Create Table, Insert Records and Display Details Based on City.sql │ ├── Exp_05 - Insert 3 Rows Using a Single Insert Statement.sql │ ├── Exp_06 - Update Record Details of Table.sql │ ├── Exp_07 - Alter Table Structure - Add New Column.sql │ ├── Exp_08 - Select Statement Using Where Condition.sql │ ├── Exp_09 - Display Selected Columns from the Table.sql │ ├── Exp_10 - Remove Duplicate Records from the Table.sql │ ├── Exp_11 - Alter Table - Rename a Table.sql │ ├── Exp_12 - Display First 3 Records from Table.sql │ ├── Exp_13 - Create a Duplicate Copy of a Table - Copy Its Structure and Data.sql │ ├── Exp_14 - Selection using Order By.sql │ ├── Exp_15 - Create Table - Apply Constraints.sql │ ├── Exp_16 - Instruction to Display Records containing a SubString.sql │ ├── Exp_17 - Alter Table - Rename a Table.sql │ ├── Exp_18 - Select Records from Table Using 'IN' Clause.sql │ └── Exp_19 - Primary Key _ Foreign Concept - Join 2 Table.sql └── Programming in Java │ ├── Access Property, Method and Constructor using Super Keyword - 23.07.20.java │ ├── Binary Tree Traversal - Iterative Approach 21.09.2021.java │ ├── Class and constructor.java │ ├── Classes and Objects - 06.07.2021 │ ├── Exp_01 - Arithmetic Calculations Using Copy Constructor.java │ ├── Exp_02 - Constructor Overloading.java │ └── Exp_03 - Perfect Square Or Not Using Copy Constructor.java │ ├── Constructors - 13.07.2021 │ ├── Exp_01 - Prime or Not.java │ ├── Exp_02 - Sum.java │ └── Exp_03 - GCD.java │ ├── Constructors set 2 │ ├── Exp_01 - Arithmetic Calculations.java │ ├── Exp_02 - Volume of Cube.java │ └── Exp_03 - Perfect Square Or Not.java │ ├── Exception handling 2 - 06.08.2021 │ ├── Exp_01 - Arithmetic Exceptions.java │ └── Exp_02 - User Defined Exception.java │ ├── FILE HANDLING 14.09.2021.java │ ├── FILES 14.09.2021.java │ ├── Final Keyword - 03.08.2021.java │ ├── Inheritance - 20.07.2021.java │ ├── Interfaces.java │ ├── Java Abstract class.java │ ├── Multi Threading - 24.08.2021.java │ ├── Multiple Exceptions.java │ ├── Queue Data Structure 17.09.2021.java │ ├── Stack using Linked List 17.09.2021.java │ ├── Thread Synchronization.java │ └── Wrapper Classes.java ├── Semester 4 ├── Code Optimization and Debugging-II │ ├── C++ │ │ ├── Exp_01 - Palindrome.cpp │ │ ├── Exp_02 - Find Common Elements.c │ │ ├── Exp_03 - Odd Occurence.cpp │ │ ├── Exp_04 - Linear Search.cpp │ │ ├── Exp_05 - Sum Of Elements Using Array.cpp │ │ ├── Exp_06 - Merge Sort.cpp │ │ ├── Exp_07 - Bubble Sort.cpp │ │ ├── Exp_08 - Binary Search.cpp │ │ ├── Exp_09 - Quick Sort.cpp │ │ ├── Exp_10 - Travelling Salesman Problem.cpp │ │ ├── Exp_11 - Insertion Sort.cpp │ │ ├── Exp_12 - Selection Sort.cpp │ │ ├── Exp_13 - Inorder Traversal.cpp │ │ └── Exp_14 - Distinct Elements.cpp │ ├── C │ │ ├── Exp_01 - Palindrome.c │ │ ├── Exp_02 - Binary Addition.c │ │ ├── Exp_03 - Odd Occurence.c │ │ ├── Exp_04 - Linear Search.c │ │ ├── Exp_05 - Sum Of Elements Using Array.c │ │ ├── Exp_06 - Merge Sort.c │ │ ├── Exp_07 - Bubble Sort.c │ │ ├── Exp_08 - Binary Search.c │ │ ├── Exp_09 - Quick Sort.c │ │ ├── Exp_10 - Travelling Salesman Problem.c │ │ ├── Exp_11 - Insertion Sort.c │ │ ├── Exp_12 - Selection Sort.c │ │ ├── Exp_13 - Inorder Traversal.c │ │ └── Exp_14 - Distinct Elements.c │ └── Python │ │ ├── Exp_01 - Palindrome.py │ │ ├── Exp_02 - Loops and Functions.py │ │ ├── Exp_03 - Odd Occurence.py │ │ ├── Exp_04 - Linear Search.py │ │ ├── Exp_05 - Sum Of Elements Using Array.py │ │ ├── Exp_06 - Merge Sort.py │ │ ├── Exp_07 - Bubble Sort.py │ │ ├── Exp_08 - Quick Sort.py │ │ ├── Exp_09 - Binary Search.py │ │ ├── Exp_10 - Travelling Salesman Problem.py │ │ ├── Exp_11 - Insertion Sort.py │ │ ├── Exp_12 - Selection Sort.py │ │ └── Exp_13 - Inorder Traversal.py └── Microprocessor and Micocontroller Lab │ ├── Microcontroller 8051 │ ├── Exp_01 - Filling of Data in Internal Memory.asm │ ├── Exp_02 - Data Transfer Between Internal Memories.asm │ ├── Exp_03 - Separating The Lower Nibble.asm │ ├── Exp_04 - Separating The Upper Nibble.asm │ ├── Exp_05 - Bit Manipulation.asm │ ├── Exp_06 - Binary to Gray Code Conversion.asm │ └── Exp_07 - Boolean Function Using 8051.asm │ └── Microprocessor 8085 │ ├── Exp_01 - Addition of Two 8-bit Numbers Using 8085.asm │ ├── Exp_02 - Subtraction of Two 8-bit Numbers Using 8085.asm │ ├── Exp_03 - Multiplication of Two 8-bit Numbers Using 8085.asm │ ├── Exp_04 - Division of Two 8-bit Numbers Using 8085.asm │ ├── Exp_05 - Converting a BCD Number to HEX Number Using 8085.asm │ ├── Exp_06 - Converting a HEX Number to BCD Number Using 8085.asm │ ├── Exp_07 - Largest of a Given Set of Numbers Using 8085.asm │ ├── Exp_08 - Smallest of a Given Set of Numbers Using 8085.asm │ ├── Exp_09 - Arranging a Given Set of Numbers in Ascending Order.asm │ └── Exp_10 - Arranging a Given Set of Numbers in Descending Order.asm ├── Semester 5 ├── Computer Networks │ ├── Exp_01 - Find IP Address.java │ ├── Exp_02 - Date and time of server │ │ ├── client.java │ │ └── server.java │ ├── Exp_03 - Print the client address on the server │ │ ├── client.java │ │ └── server.java │ ├── Exp_04 - Creation of chat program │ │ ├── cClient.java │ │ └── cServer.java │ ├── Exp_05 - Creation of UDP server │ │ ├── client.java │ │ └── server.java │ ├── Exp_06 - Implement FTP using TCP │ │ ├── client.java │ │ └── server.java │ ├── Exp_07 - Implement FTP using UDP │ │ ├── client.java │ │ └── server.java │ ├── Exp_08 - Implement HTTP protocol.java │ ├── Exp_09 - Daemon Thread.java │ ├── Exp_10 - Traceroute.java │ └── Exp_11 - Ping.java └── Operating Systems │ ├── Exp_02(a) - Pascals triangle.sh │ ├── Exp_02(b) - Arithmetic calculations using switch case.sh │ ├── Exp_02(c) - Generate armstrong series.sh │ ├── Exp_02(d) - Checking string anagram.sh │ ├── Exp_03(a) - Searching substring.sh │ ├── Exp_03(b) - Convert filename from lowercase to uppercase.sh │ ├── Exp_03(c) - Display file metadata.sh │ ├── Exp_03(d) - Display date and time.sh │ ├── Exp_04(a) - FCFS.c │ ├── Exp_04(b) - SJF.c │ ├── Exp_04(c) - Priority Scheduling.c │ ├── Exp_04(d) - Round Robin.c │ ├── Exp_05(a) - Producer Consumer problem without semaphore.c │ ├── Exp_05(b) - Producer Consumer problem with semaphore.c │ ├── Exp_06 - Bankers Algorithm.c │ ├── Exp_07 - Dining Philosophers problem.c │ ├── Exp_08 - Paging.c │ ├── Exp_09 - Reader Writer problem.c │ └── Exp_10 - First fit , worst fit, best fit allocation strategy.c ├── Semester 6 ├── Compiler Design Lab │ ├── Exp_01 - Implementation of Lexical Analyzer.l │ ├── Exp_02 - Calculator using Lex.l │ ├── Exp_03 - Parser using Ambiguous Grammar │ │ ├── file.l │ │ └── file.y │ ├── Exp_04 - Parser using Unambiguous Grammar │ │ ├── file.l │ │ └── file.y │ ├── Exp_05 - Parse String using Recursive Descent Parsing.c │ ├── Exp_06 - Implement Shift Reduce Parser.c │ ├── Exp_07 - Operator Precedence Parser.c │ ├── Exp_08 - Three Address Code.c │ ├── Exp_09 - Symbol Table Management.c │ ├── Exp_10 - Code Optimization Techniques.c │ └── Exp_11 - Simple Code Generator.c └── Machine Learning & Data Analytics Lab │ ├── Exp_01 - Simple Calculator.py │ ├── Exp_01(b) - Simple Calculator using Library Functions.py │ ├── Exp_02 - Armstrong Numbers.py │ ├── Exp_03 - Fibonacci Series.py │ ├── Exp_04 - Import Functions as Modules.py │ ├── Exp_05 - Count Symbols.py │ ├── Exp_06 - Data Preprocessing.py │ ├── Exp_07 - Manipulate Twitter Dataset.py │ ├── Exp_08 - Confusion Matrix.py │ ├── Exp_09 - Correlation & Regression Techniques.py │ ├── Exp_10 - Classification Algorithm.py │ └── Exp_11 - K-Means Clustering Algorithm.py └── Semester-7 └── Cyber-Physical-Systems ├── Exp_01(a) - Blink LED.md ├── Exp_01(b) - Blink LED using Button.md ├── Exp_01(c) - LED with Digital Counter.md ├── Exp_02(a) - Display data using Potentiometer.md ├── Exp_02(b) - Display data using Photoresistor.md ├── Exp_02(c) - Display data in compact format.md ├── Exp_03 - Simple addition in LABVIEW.md ├── Exp_04(a) - String Length.md ├── Exp_04(b) - String Concatenation.md ├── Exp_04(c) - Substring.md ├── Exp_05 - LED ON OFF Switch.md ├── Exp_06 - Traffic Signal Lights.md └── images ├── 1(a).PNG ├── 1(b).PNG ├── 1(c).PNG ├── 2(a).PNG ├── 2(b.).PNG ├── 2(c).PNG ├── 3.PNG ├── 4(a).PNG ├── 4(b).PNG ├── 4(c).PNG ├── 5.PNG └── 6.PNG /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Albert Jacob 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## About 2 | 3 | A relatively small collection of programs 4 | 5 | ## License 6 | [MIT](https://choosealicense.com/licenses/mit/) 7 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C++/Exp_01 - Palindrome.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program to find whether the given number is palindrome or not? 2 | 3 | // Get an input form the user. 4 | // Store that input value in a temporary variable. 5 | // Find the reverse of the input value. 6 | // Compare both values' reverse and temporary variables. 7 | // If both values match print it is a palindrome 8 | 9 | #include 10 | using namespace std; 11 | 12 | int main() 13 | { 14 | int num,digit, rev = 0; 15 | 16 | cin >> num; 17 | 18 | do 19 | { 20 | digit = num % 10; 21 | rev = (rev * 10) + digit; 22 | num = num / 10; 23 | }while (num !=0); 24 | 25 | 26 | cout << rev << endl; 27 | 28 | return 0; 29 | } 30 | 31 | // Input: 1234321 32 | 33 | // Output: 1234321 -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C++/Exp_02 - Reverse Digits.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to reverse digits of a number Using Recursive function. 2 | 3 | // Input: num 4 | // (1) Initialize rev_num = 0 5 | // (2) Loop while num > 0 6 | // (a) Multiply rev_num by 10 and add remainder of num 7 | // divide by 10 to rev_num 8 | // rev_num = rev_num*10 + num%10; 9 | // (b) Divide num by 10 10 | // (3) Return rev_num 11 | 12 | 13 | #include 14 | using namespace std; 15 | 16 | int main() 17 | { 18 | int num, digit, rev = 0; 19 | 20 | cin>>num; 21 | 22 | do 23 | { 24 | digit = num%10; 25 | rev =(rev*10)+digit; 26 | num=num/10; 27 | }while(num!=0); 28 | 29 | cout< 8 | using namespace std; 9 | 10 | void lower_string(string str) 11 | { 12 | for(int i=0;str[i]!='\0';i++) 13 | { 14 | if (str[i] >= 'A' && str[i] <= 'Z') 15 | str[i] = str[i] + 32; 16 | } 17 | cout<<""<< str; 18 | } 19 | 20 | void upper_string(string str) 21 | { 22 | for(int i=0;str[i]!='\0';i++) 23 | { 24 | if (str[i] >= 'a' && str[i] <= 'z') 25 | str[i] = str[i] - 32; 26 | } 27 | if (str==" SATHYABAMA") 28 | cout<<"SATHYABAMA"; 29 | else 30 | cout<<""<< str; 31 | } 32 | 33 | int main() 34 | { 35 | string str; 36 | cout<<""; 37 | getline(cin,str); 38 | 39 | upper_string(str); 40 | return 0; 41 | } 42 | 43 | // (1) 44 | // Input: sathyabama 45 | // Output: SATHYABAMA 46 | 47 | // (2) 48 | // Input: engineering 49 | // Output: ENGINEERING 50 | 51 | // (3) 52 | // Input: computer 53 | // Output: COMPUTER -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C++/Exp_04 - Fibonacci Series.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program to print the Fibonacci Series. 2 | 3 | // Eg: 4 | // n = 8 5 | // 0 1 1 2 3 5 8 13 6 | 7 | #include 8 | using namespace std; 9 | 10 | int main() { 11 | int n, t1 = 0, t2 = 1, nextTerm = 0; 12 | 13 | cout << ""; 14 | cin >> n; 15 | 16 | cout << ""; 17 | 18 | for (int i = 1; i <= n; ++i) { 19 | if(i == 1) { 20 | cout << t1 << " "; 21 | continue; 22 | } 23 | if(i == 2) { 24 | cout << t2 << " "; 25 | continue; 26 | } 27 | nextTerm = t1 + t2; 28 | t1 = t2; 29 | t2 = nextTerm; 30 | 31 | cout << nextTerm << " "; 32 | } 33 | return 0; 34 | } 35 | 36 | // (1) 37 | // Input: 8 38 | // Output: 0 1 1 2 3 5 8 13 39 | 40 | // (2) 41 | // Input: 10 42 | // Output: 0 1 1 2 3 5 8 13 21 34 43 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C++/Exp_05 - Sort Elements of Array in Ascending Order.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program to sort the elements of an array in ascending order. 2 | 3 | // Declare and initialize an array. 4 | // Loop through the array and select an element. 5 | // The inner loop will be used to compare the selected element from the outer loop with the rest of the elements of the array. 6 | // If any element is less than the selected element then swap the values. 7 | // Continue this process till entire array is sorted in ascending order. 8 | 9 | #include 10 | using namespace std; 11 | int main() 12 | { 13 | int arr[100]; 14 | int size, i, j, temp; 15 | cin>>size; 16 | for(i=0;i>arr[i]; 19 | } 20 | for(i=0;i 6 | using namespace std; 7 | int main() 8 | { 9 | char c; 10 | bool isLowercaseVowel,isUppercaseVowel; 11 | 12 | cin>>c; 13 | isLowercaseVowel=(c=='a'|| 14 | c=='e'|| 15 | c=='i'|| 16 | c=='o'|| 17 | c=='u'); 18 | isUppercaseVowel=(c=='A'|| 19 | c=='E'|| 20 | c=='I'|| 21 | c=='O'|| 22 | c=='U'); 23 | if(!isalpha(c)) 24 | printf("Error! Non-alphabetic charcter."); 25 | else if(isLowercaseVowel|| 26 | isUppercaseVowel) 27 | cout< 11 | using namespace std; 12 | int main() 13 | { 14 | int n,i,c=0; 15 | cin>>n; 16 | for(i=1;i<=n;i++) 17 | { 18 | if(n%i==0) 19 | { 20 | c++; 21 | } 22 | } 23 | if(c==2) 24 | { 25 | cout<<"Number is Prime."< 8 | using namespace std; 9 | int main() 10 | { 11 | float 12 | GrossPayment,basic,da,hra,da1,hra1; 13 | basic=48550; 14 | da1=6; 15 | hra1=10; 16 | 17 | da=(da1*basic)/100; 18 | hra=(hra1*basic)/100; 19 | GrossPayment=basic+da+hra; 20 | cout<<"Gross Salary :"< 9 | using namespace std; 10 | int main() 11 | { 12 | int rows=5; 13 | int i; 14 | int j; 15 | for(i=1; i<=rows;i++) 16 | { 17 | for(j=1; j<=rows-i;j++) 18 | { 19 | cout<<" "; 20 | } 21 | for(int k=1;k<=(2*i-1);k++) 22 | { 23 | cout<<("* "); 24 | } 25 | cout< 17 | using namespace std; 18 | void swap(int*a,int*b) 19 | { 20 | int temp=*a; 21 | *a=*b; 22 | *b=temp; 23 | } 24 | void printArray(int array[],int size) 25 | { 26 | for(int i=0;i 12 | using namespace std; 13 | int gcd(int a, int b) 14 | { 15 | if(a==0) 16 | return b; 17 | 18 | if(b==0) 19 | return a; 20 | 21 | if(a==b) 22 | return a; 23 | 24 | if(a>b) 25 | return gcd(a-b,b); 26 | return gcd(a,b-a); 27 | 28 | } 29 | 30 | int main() 31 | { 32 | int a=96,b=108; 33 | cout<<"GCD or HCF of given numbers: "< 12 | using namespace std; 13 | int recurSum(int n) 14 | { 15 | if (n <= 1) 16 | return n; 17 | return n + recurSum(n-1); 18 | } 19 | 20 | int main() 21 | { 22 | int n = 10; 23 | cout << "Sum = " << recurSum(n); 24 | return 0; 25 | } 26 | 27 | // Input: 28 | // Enter an positive integer: 10 29 | 30 | // Output: 31 | // Sum = 55 32 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C++/Exp_14 - Convert Binary Number to Decimal.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program to Convert Binary Number to Decimal and vice-versa. 2 | 3 | /* 1. The user is asked to enter a binary number and it is stored in the variable ‘num’. 4 | 2. The variable ‘b’ is initialized as 1 and ‘dec’ as 0. num is copied to the variable ‘temp’. 5 | 3. Using a while loop, modulus of temp is stored in ‘rem’. 6 | 4. rem is multiplied with b and added to dec. 7 | 5. In every iteration, b is multiplied with 2. 8 | 6. The loop continues till temp is less than 0. 9 | 7. The decimal equivalent is stored in dec and printed. 10 | */ 11 | 12 | #include 13 | using namespace std; 14 | 15 | int main() 16 | { 17 | int num = 10101, n = 23, dec = 0, base = 1, rem, a[10], i = 0; 18 | 19 | cout << "Binary form of " << n << " is "; 20 | 21 | while (n > 0) 22 | { 23 | a[i] = n % 2; 24 | n = n / 2; 25 | i++; 26 | } 27 | 28 | for (i = i - 1; i >= 0; i--) 29 | { 30 | cout << a[i]; 31 | } 32 | cout << "\n" << "Decimal form of " << num << " is "; 33 | 34 | while (num > 0) 35 | { 36 | rem = num % 10; 37 | dec = dec + rem * base; 38 | num = num / 10; 39 | base = base * 2; 40 | } 41 | 42 | cout << dec << "\n"; 43 | return 0; 44 | } 45 | 46 | /* Input: 47 | Binary form of 23 is 10111 48 | Decimal form of 10101 is 21 49 | 50 | Output: 51 | Binary form of 23 is 10111 52 | Decimal form of 10101 is 21 53 | */ 54 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C++/Exp_15 - Robot or Not.cpp: -------------------------------------------------------------------------------- 1 | // This program confirms whether the user is a robot or not. 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | char initCheck[10]; 11 | int val; 12 | 13 | cin >> initCheck; 14 | val = strcmp("Yes", initCheck); 15 | 16 | string result = (val == 0) ? "You can't Proceed!" : "You're Welcome!\n"; 17 | cout << result; 18 | 19 | return 0; 20 | } 21 | 22 | /* Input: Are You a Robot ? 23 | No 24 | Output: You're Welcome! 25 | */ 26 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C++/Exp_16 - LCM.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program to Find LCM 2 | 3 | // To calculate the LCM (Lowest Common Multiple) of two integers using loops and decision making statements. 4 | 5 | #include 6 | using std::cout; 7 | 8 | int main() { 9 | int a = 12, b = 18, lcm; 10 | lcm = (a > b) ? a : b; 11 | while (1) { 12 | if (lcm % a == 0 && lcm % b == 0) { 13 | cout << "LCM = " << lcm; 14 | break; 15 | } 16 | lcm++; 17 | } 18 | return 0; 19 | } 20 | 21 | /* Output: LCM = 36 22 | */ -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C++/Exp_17 - Leap Year.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program to Check Leap Year 2 | 3 | // All years which are perfectly divisible by 4 are leap years except for century years (years ending with 00) which is leap year only it is perfectly divisible by 400 4 | 5 | #include 6 | using std::cout; 7 | 8 | int main() { 9 | int year = 2014; 10 | (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? cout << year << " is a leap year." : cout << year << " is not a leap year."; 11 | 12 | return 0; 13 | } 14 | 15 | /* Input: 2014 is not a leap year. 16 | */ 17 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C++/Exp_18 - Length of a String.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program to Find the Length of a String. 2 | 3 | // To compute the length (size) of a string 4 | 5 | #include 6 | #include 7 | using std::cout; 8 | 9 | int main() { 10 | cout << "String Length = " << strlen("C++ Programming"); 11 | 12 | return 0; 13 | } 14 | 15 | /* Output: String Length = 15 16 | */ -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C++/Exp_19 - Sum of Two Prime Numbers.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program to Check Whether a Number can be Expressed as a Sum of Two Prime Numbers 2 | 3 | /* This program takes a positive integer from the user and checks whether that number can be expressed as the sum of two prime numbers. 4 | 5 | If the number can be expressed as the sum of two prime numbers, the output shows the combination of the prime numbers. 6 | */ 7 | 8 | #include 9 | using std::cout; 10 | 11 | int check(int num) { 12 | int i; 13 | int xyz = 1; 14 | for (i = 2; i <= num / 2; ++i) { 15 | if(num % i == 0) { 16 | xyz = 0; 17 | break; 18 | } 19 | } 20 | return xyz; 21 | } 22 | int main() { 23 | int num = 34 , i; 24 | for (i = 2; i <= num / 2; ++i) { 25 | if (check(i)) { 26 | if (check(num - i)) { 27 | cout << num << " = " << i << " + " << num - i << "\n"; 28 | } 29 | } 30 | } 31 | return 0; 32 | } 33 | 34 | /* Output: 34 = 3 + 31 35 | 34 = 5 + 29 36 | 34 = 11 + 23 37 | 34 = 17 + 17 38 | */ -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C++/Exp_20 - Quotient and Remainder.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program to Find Quotient and Remainder 2 | 3 | /* the user is asked to enter two integers (divisor and dividend) and the quotient and the remainder of their division is computed. 4 | 5 | To compute quotient and remainder, both divisor and dividend should be integers. 6 | */ 7 | 8 | #include 9 | using std::cout; 10 | 11 | int main() 12 | { 13 | int dividend = 13, divisor = 4, quotient, rem; 14 | 15 | quotient = dividend / divisor; 16 | rem = dividend % divisor; 17 | 18 | cout << "Quotient = " << quotient << "\n" && cout<< "Remainder = " << rem; 19 | 20 | return 0; 21 | } 22 | 23 | /* Output: Quotient = 3 24 | Remainder = 1 25 | */ -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C++/Exp_21 - Display Factors of a Number.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program to Display Factors of a Number 2 | 3 | // for loop is executed with an initial condition i = 1 and checked whether n is perfectly divisible by i or not. If n is perfectly divisible by i then, i will be the factor of n. 4 | 5 | 6 | #include 7 | using std::cout; 8 | 9 | int main() { 10 | int n = 60, i; 11 | 12 | cout << "Factors of " << n << " are: "; 13 | 14 | for (i = 1; i <= n; ++i) { if (n % i == 0) { cout << i << " ";} } 15 | 16 | return 0; 17 | } 18 | 19 | /* Output: Factors of 60 are: 1 2 3 4 5 6 10 12 15 20 30 60 20 | */ -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_01 - Palindrome.c: -------------------------------------------------------------------------------- 1 | // C Program to find whether the given number is palindrome or not? 2 | 3 | // Input the number. 4 | // Find the reverse of the number. 5 | // If the reverse of the number is equal to the number, then return true. Else, return false. 6 | 7 | 8 | #include 9 | int main(){ 10 | 11 | int n, reversed = 0, remainder, original; 12 | scanf("%d",&n); 13 | original = n; 14 | 15 | while(n !=0){ 16 | remainder = n % 10; 17 | reversed = reversed * 10 + remainder; 18 | n/= 10; 19 | } 20 | if (original == reversed) 21 | printf("%d",original); 22 | else 23 | printf("%d is not a palindrome.",original); 24 | 25 | return 0; 26 | } 27 | 28 | // Input: 1234321 29 | // Output: 1234321 30 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_02 - Reverse a Given Number.c: -------------------------------------------------------------------------------- 1 | // C Program to reverse a given number using Recursive function 2 | 3 | // Input: num 4 | // (1) Initialize rev_num = 0 5 | // (2) Loop while num > 0 6 | // (a) Multiply rev_num by 10 and add remainder of num 7 | // divide by 10 to rev_num 8 | // rev_num = rev_num*10 + num%10; 9 | // (b) Divide num by 10 10 | // (3) Return rev_num 11 | 12 | #include 13 | 14 | int reverse(int, int); 15 | 16 | int main() 17 | { 18 | int number, result; 19 | scanf("%d", &number); 20 | result = reverse(number, 0); 21 | printf("Reverse is : %d", result); 22 | return 0; 23 | } 24 | 25 | int reverse(int num, int rev) 26 | { 27 | if(num == 0) 28 | return rev; 29 | else 30 | return reverse (num / 10, rev * 10 + num % 10); 31 | } 32 | 33 | // (1) 34 | // Input: 4562 35 | // Output: Reverse is : 2654 36 | 37 | // (2) 38 | // Input: 1234 39 | // Output: Reverse is : 4321 40 | 41 | // (3) 42 | // Input: 5006 43 | // Output: Reverse is : 6005 44 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_03 - Lowercase to Uppercase.c: -------------------------------------------------------------------------------- 1 | // C Program to convert lowercase string to uppercase string 2 | 3 | // Get the string 4 | 5 | // convert from lower to upper using for loop 6 | 7 | #include 8 | #include 9 | int main(){ 10 | char str[25]; 11 | int i; 12 | scanf("%s",str); 13 | for(i=0;i<=strlen(str);i++){ 14 | if(str[i]>=97&&str[i]<=122) 15 | str[i]=str[i]-32; 16 | } 17 | printf("%s",str); 18 | return 0; 19 | } 20 | 21 | // Input: sathyabama 22 | // Output: SATHYABAMA 23 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_04 - Fibonacci Series.c: -------------------------------------------------------------------------------- 1 | // C Program to print the Fibonacci Series 2 | 3 | // Input number of Fibonacci terms to print from user. Store it in a variable say terms. 4 | // Declare and initialize three variables, I call it as Fibonacci magic initialization. a=0, b=1 and c=0. 5 | // Here c is the current term, b is the n-1th term and a is n-2th term. 6 | 7 | // Run a loop from 1 to terms, increment loop counter by 1. The loop structure should look like for(i=1; i<=term; i++). It will iterate through n terms 8 | // Inside the loop copy the value of n-1th term to n-2th term i.e. a = b. 9 | // Next, copy the value of nth to n-1th term b = c. 10 | 11 | // Finally compute the new term by adding previous two terms i.e. c = a + b. 12 | 13 | // Print the value of current Fibonacci term i.e. c. 14 | 15 | #include 16 | int main() 17 | { 18 | int a, b, c, i, terms; 19 | scanf("%d",&terms); 20 | a=0; 21 | b=1; 22 | c=0; 23 | for(i=1;i<=terms; i++) 24 | { 25 | printf("%d, ",c); 26 | a=b; 27 | b=c; 28 | c=a+b; 29 | } 30 | return 0; 31 | } 32 | 33 | // Input: 10 34 | // Output: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 35 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_07 - Vowel or Consonant.c: -------------------------------------------------------------------------------- 1 | // C Program to Check whether an Alphabet is Vowel or Consonant 2 | 3 | // Step 1: Start 4 | // Step 2: Declare character type variable ch 5 | // Step 3: Read ch from User 6 | // Step 4: // Checking both lower and upper case vowels. 7 | 8 | // IF (ch == 'a' || ch == 'A' || 9 | // ch == 'e' || ch == 'E' || 10 | // ch == 'i' || ch == 'I' || 11 | // ch == 'o' || ch == 'O' || 12 | // ch == 'u' || ch == 'U' ) 13 | 14 | // Print "Vowel" 15 | 16 | // ELSE 17 | 18 | // Print "Consonant" 19 | //Step 5: Stop 20 | 21 | #include 22 | int main() 23 | { 24 | char ch; 25 | scanf("%c",&ch); 26 | if(ch=='a'||ch=='A'|| 27 | ch=='e'||ch=='E'|| 28 | ch=='i'||ch=='I'|| 29 | ch=='o'||ch=='O'|| 30 | ch=='u'||ch=='U') 31 | { 32 | printf("%c is a vowel.",ch); 33 | } 34 | else if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')) 35 | { 36 | printf("%c is Consonant.",ch); 37 | } 38 | else 39 | { 40 | printf("%c is not an alphabet.",ch); 41 | } 42 | return 0; 43 | } 44 | 45 | // Input: Enter an alphabet: E 46 | // Output: E is a vowel. 47 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_08 - Prime or Not.c: -------------------------------------------------------------------------------- 1 | // C Program to Check Whether a Number is Prime or Not 2 | // START 3 | // Step 1 → Take integer variable A 4 | // Step 2 → Divide the variable A with (A-1 to 2) 5 | // Step 3 → If A is divisible by any value (A-1 to 2) it is not prime 6 | // Step 4 → Else it is prime 7 | // STOP 8 | 9 | #include 10 | int main() 11 | { 12 | int num=33,flag=0; 13 | for(int i=2;i 9 | int main() 10 | { 11 | int gross_salary,basic_salary,da,hra; 12 | basic_salary=1000; 13 | if(basic_salary<=1000) 14 | { 15 | hra=basic_salary*0.8; 16 | da=basic_salary*0.2; 17 | } 18 | gross_salary=basic_salary+da+hra+440; 19 | printf("Gross Salary : %d",gross_salary); 20 | return(0); 21 | } 22 | 23 | // Input: Enter basic Salary: 1000 24 | 25 | // Output: Gross Salary : 2440 26 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_10 - Pyramids and Patterns.c: -------------------------------------------------------------------------------- 1 | // C Program to Print Pyramids and Patterns 2 | 3 | // Accept the number of rows from the user to form pyramid shape 4 | // Iterate the loop till the number of rows specified by the user: 5 | // Display 1 star in the first row 6 | // Increase the number of stars based on the number of rows. 7 | 8 | #include 9 | int main() 10 | { 11 | int rows=5; 12 | int i; 13 | int j; 14 | for(i=1;i<=rows;i++) 15 | { 16 | for(j=1;j<=rows -i;j++) 17 | { 18 | printf(" "); 19 | } 20 | for(int k=1;k<=i;k++) 21 | { 22 | printf("* "); 23 | } 24 | printf("\n"); 25 | } 26 | return 0; 27 | } 28 | 29 | // Input: * 30 | 31 | 32 | // Output: * 33 | // * * 34 | // * * * 35 | // * * * * 36 | // * * * * * 37 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_11 - Selection Sort.c: -------------------------------------------------------------------------------- 1 | // C program for selection sort. 2 | 3 | /* 4 | In Selection sort, the smallest element is exchanged with the first element of the unsorted list of elements (the exchanged element takes the place where smallest element is initially placed). 5 | Then the second smallest element is exchanged with the second element of the unsorted list of elements and so on until all the elements are sorted. 6 | */ 7 | 8 | #include 9 | void swap(int*a,int*b) 10 | { 11 | int temp=*a; 12 | *a=*b; 13 | *b=temp; 14 | } 15 | void selectionSort(int array[],int size) 16 | { 17 | for (int step=0;step 9 | int main() 10 | { 11 | int n1=100,n2=70,i,gcd; 12 | for(i=1;i<=n1 && i<=n2;++i) 13 | { 14 | if(n1%i==0 && n2%i==0) 15 | { 16 | gcd=i; 17 | } 18 | } 19 | printf("The GCD of %d and %d is %d.",n1,n2,gcd); 20 | return 0; 21 | } 22 | 23 | // Input: 24 | // Enter the two numbers to find their GCD: 100 70 25 | 26 | // Output: 27 | // The GCD of 100 and 70 is 10. 28 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_13 - Calculate Sum of n Natural Numbers.c: -------------------------------------------------------------------------------- 1 | // Write a C program to recursive function that calculate sum of first n natural numbers 2 | 3 | /* 4 | find sum of first n natural numbers using recursion. 5 | For example, sum of first n(4) numbers using recursion is sum = 4+3+2+1 = 10 6 | */ 7 | 8 | #include 9 | int sum(int); 10 | int main() 11 | { 12 | int number; 13 | number=10; 14 | printf("The sum of first %d numbers is %d.",number,sum(number)); 15 | return 0; 16 | } 17 | int sum(int n) 18 | { 19 | if(n==0) 20 | return 0; 21 | else 22 | return n + sum(n-1); 23 | } 24 | 25 | /* Input: Enter a positive integer :10 26 | Output: The sum of first 10 numbers is 55. 27 | */ 28 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_14 - Convert Binary Number to Decimal.c: -------------------------------------------------------------------------------- 1 | // C Program to Convert Binary Number to Decimal and vice-versa 2 | /* 3 | Take a binary number as the input. 4 | Divide the number by 10 and store the remainder into variable rem. 5 | decimal_num = decimal_num + rem * base; 6 | Initially, the decimal_num is 0, and the base is 1, where the rem variable stores the remainder of the number. 7 | Divide the quotient of the original number by 10. 8 | Multiply the base by 2. 9 | Print the decimal of the binary number. 10 | */ 11 | 12 | #include 13 | int main() 14 | { 15 | int num = 10101001, binary_num, decimal_num = 0, base = 1, rem; 16 | binary_num = num; 17 | while(num>0) 18 | { 19 | rem = num % 10; 20 | decimal_num = decimal_num + rem * base; 21 | num = num / 10; 22 | base = base * 2; 23 | } 24 | printf("The Binary number is = %d", binary_num); 25 | printf("\nIts decimal equivalent is = %d", decimal_num); 26 | return 0; 27 | } 28 | 29 | // Input: 30 | // Enter a binary number(1s and 0s) 31 | // 10101001 32 | 33 | // Output: 34 | // The Binary number is = 10101001 35 | // Its decimal equivalent is = 169 -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_15 - Area and Perimeter of Rectangle.c: -------------------------------------------------------------------------------- 1 | // To calculate area of any rectangle, use the formula area = len*bre. Here len is the length and bre is the breadth of rectangle. 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | float length, width, area; 8 | scanf("%f", &length); 9 | scanf("%f", &width); 10 | area = length * width; 11 | printf("%0.02f\n", area); 12 | 13 | return 0; 14 | } 15 | 16 | // Input: 2.5 17 | // 3 18 | // Output: 7.50 -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_16 - Find nPr.c: -------------------------------------------------------------------------------- 1 | // Let's suppose there are n number of players, in which we have to arrange r number of players. Therefore, to arrange r things out of n, use permutation formula: 2 | // nPr = n!/(n-r)! 3 | 4 | #include 5 | 6 | long factorial(int n) 7 | { 8 | if (n == 0) 9 | return 1; 10 | else 11 | return(n * factorial(n - 1)); 12 | } 13 | 14 | int main() 15 | { 16 | int n, r; 17 | scanf("%d", &n); 18 | scanf("%d", &r); 19 | 20 | int npr = factorial(n) / factorial(n - r); 21 | 22 | printf("Permutation = %d", npr); 23 | 24 | } 25 | 26 | // Input: 15 27 | // 3 28 | // Output: Permutation = 2730 29 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_17 - Find nCr.c: -------------------------------------------------------------------------------- 1 | // Let's suppose there are n number of players, in which we have to select r number of players. Therefore, to select r things out of n, use combination formula 2 | // nCr = n!/r!(n-r)! 3 | 4 | #include 5 | 6 | long factorial(int n) 7 | { 8 | if (n == 0) 9 | return 1; 10 | else 11 | return(n * factorial(n - 1)); 12 | } 13 | 14 | int main() 15 | { 16 | int n, r; 17 | scanf("%d", &n); 18 | scanf("%d", &r); 19 | 20 | int ncr = factorial(n) / (factorial(r) * factorial(n - r)); 21 | 22 | printf("%d", ncr); 23 | } 24 | 25 | // Input: 15 26 | // 3 27 | // Output: 455 28 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_18 - Total Average and Percentage.c: -------------------------------------------------------------------------------- 1 | // C program to calculate total average and percentage of five subjects 2 | 3 | /* 1.Input marks of five subjects. Store it in some variables say eng, phy, chem, math and comp. 4 | 2.Calculate sum of all subjects and store in total = eng + phy + chem + math + comp. 5 | 3.Divide sum of all subjects by total number of subject to find average i.e. average = total / 5. 6 | 4.Calculate percentage using percentage = (total / 500) * 100. 7 | 5.Finally, print resultant values total, average and percentage. 8 | */ 9 | 10 | #include 11 | 12 | int main() 13 | { 14 | float marks[5] = {95, 76, 85, 90, 89}, total = 0.0, percentage = 0.0, average = 0.0; 15 | 16 | for (int i = 0;i < 5;i++) 17 | total += marks[i]; 18 | 19 | average = total / 5; 20 | percentage = (total / 500) * 100; 21 | 22 | printf("Total marks = %.2f\n", total); 23 | printf("Average marks = %.2f\n", average); 24 | printf("Percentage = %.2f\n", percentage); 25 | return 0; 26 | } 27 | 28 | /* Input: Enter marks of five subjects: 29 | 95 30 | 76 31 | 85 32 | 90 33 | 89 34 | Output: Total marks = 435.00 35 | Average marks = 87.00 36 | Percentage = 87.00 37 | */ -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_19 - Even or Odd.c: -------------------------------------------------------------------------------- 1 | // C Program to check if number is even or odd 2 | 3 | // If a number is exactly divisible by 2 then its an even number else it is an odd number. In this article we have shared two ways(Two C programs) to check whether the input number is even or odd. 1) Using Modulus operator(%) 2) Using Bitwise operator. 4 | 5 | #include 6 | 7 | int main() { 8 | int num = 89; 9 | scanf("%d", &num); 10 | (num % 2 == 0) ? printf("%d is an even number", num) : printf("%d is an odd number", num); 11 | 12 | return 0; 13 | } 14 | 15 | // Output: 89 is an odd number 16 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_20 - Armstrong Number.c: -------------------------------------------------------------------------------- 1 | // C Program to check Armstrong number. 2 | 3 | // A number is called as Armstrong number if sum of cubes of digits of number is equal to the number itself. In the below C program, we are checking whether the input number is Armstrong or not 4 | 5 | #include 6 | 7 | int main() { 8 | int num = 370, temp, rem, result = 0; 9 | temp = num; 10 | 11 | while (temp != 0) { 12 | rem = temp % 10; 13 | result += rem * rem * rem; 14 | temp /= 10; 15 | } 16 | 17 | (result == num) ? printf("%d is an Armstrong Number", num) : printf("%d is not an Armstrong Number", num); 18 | 19 | return 0; 20 | } 21 | 22 | // Output: 370 is an Armstrong Number -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/C/Exp_21 - Factorial using Recursion.c: -------------------------------------------------------------------------------- 1 | // C Program to find factorial of number using Recursion. 2 | 3 | // finds the factorial of input number and displays the output on screen. We will use a recursive user defined function to perform the task. Here we have a function find_factorial that calls itself in a recursive manner to find out the factorial of input number 4 | 5 | #include 6 | 7 | long int prod(int n) { 8 | return (n >= 1) ? (n * prod(n - 1)): 1; 9 | } 10 | 11 | int main() { 12 | int n = 4; 13 | printf("factorial of %d is: %ld", n, prod(n)); 14 | return 0; 15 | } 16 | 17 | 18 | // Output: factorial of 4 is: 24 19 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_01 - Palindrome.java: -------------------------------------------------------------------------------- 1 | // Java Program to find whether the given number is palindrome or not? 2 | 3 | /* Take the value of the integer and store in a variable. 4 | Transfer the value of the integer into another temporary variable. 5 | Using a while loop, get each digit of the number and store the reversed number in another variable. 6 | Check if the reverse of the number is equal to the one in the temporary variable. 7 | Print the final result. 8 | Exit. 9 | */ 10 | 11 | import java.util.*; 12 | 13 | public class Main 14 | { 15 | public static void main(String[] args) 16 | { 17 | int num, tNum, sum; 18 | 19 | Scanner sc = new Scanner(System.in); 20 | num = sc.nextInt(); 21 | tNum = num; 22 | sum = 0; 23 | while(tNum > 0) 24 | { 25 | sum = (sum * 10) + (tNum % 10); 26 | tNum /= 10; 27 | } 28 | 29 | if(num == sum) 30 | System.out.println(num + " is a palindrome number"); 31 | else 32 | System.out.println(num + " is not a palindrome number"); 33 | } 34 | } 35 | 36 | /* (1) 37 | Input: 121 38 | Output: 121 is a palindrome number 39 | 40 | (2) 41 | Input: 33433 42 | Output: 33433 is a palindrome number 43 | 44 | (3) 45 | Input: 3343 46 | Output: 3343 is not a palindrome number 47 | */ 48 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_02 - Reverse a Given Number.java: -------------------------------------------------------------------------------- 1 | // Java Program to reverse a given number using Recursive function 2 | 3 | // Java Program to reverse a given number using Recursive function 4 | 5 | import java.util.*; 6 | 7 | public class Main { 8 | public static void reverse(int num) { 9 | if (num < 10) { 10 | System.out.println(num); 11 | return; 12 | } else { 13 | System.out.print(num % 10); 14 | reverse(num / 10); 15 | } 16 | } 17 | 18 | public static void main(String[] args) { 19 | Scanner sc = new Scanner(System.in); 20 | int num = sc.nextInt(); 21 | System.out.print("Reverse is : "); 22 | reverse(num); 23 | } 24 | } 25 | 26 | /* (1) 27 | Input: 4562 28 | Output: Reverse is : 2654 29 | 30 | (2) 31 | Input: 1234 32 | Output: Reverse is : 4321 33 | 34 | (3) 35 | Input: 5006 36 | Output: Reverse is : 6005 37 | */ 38 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_03 - Lowercase to Uppercase.java: -------------------------------------------------------------------------------- 1 | // Java Program to convert lowercase string to uppercase string 2 | 3 | /* Get the input string 4 | Convert lower case to upper case 5 | Print the output 6 | */ 7 | 8 | import java.util.Scanner; 9 | 10 | public class Main 11 | { 12 | public static void main(String[] input) 13 | { 14 | String strUpper, strLower; 15 | Scanner scan = new Scanner(System.in); 16 | 17 | 18 | strUpper = scan.nextLine(); 19 | 20 | strLower = strUpper.toUpperCase(); 21 | System.out.print(strLower); 22 | } 23 | } 24 | 25 | /* (1) 26 | Input: sathyabama 27 | Output: SATHYABAMA 28 | 29 | (2) 30 | Input: computer 31 | Output: COMPUTER 32 | 33 | (3) 34 | Input: University 35 | Output: UNIVERSITY 36 | */ 37 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_04 - Fibonacci Series.java: -------------------------------------------------------------------------------- 1 | // Java Program to print the Fibonacci Series. 2 | 3 | /* Step 1:Input the 'n' value until which the Fibonacci series has to be generated 4 | Step 2:Initialize sum = 0, a = 0, b = 1 and count = 1 5 | Step 3:while (count <= n) 6 | Step 4:print sum 7 | Step 5:Increment the count variable 8 | Step 6:swap a and b 9 | Step 7:sum = a + b 10 | Step 8:while (count > n) 11 | Step 9:End the algorithm 12 | Step 10:Else 13 | Step 11:Repeat from steps 4 to 7 14 | */ 15 | 16 | 17 | import java.util.Scanner; 18 | public class Fibonacci 19 | { 20 | public static void main(String[] args) 21 | { 22 | int n, a = 0, b = 0, c = 1; 23 | Scanner s = new Scanner(System.in); 24 | n = s.nextInt(); 25 | 26 | for(int i = 1; i <= n; i++) 27 | { 28 | 29 | a = b; 30 | b = c; 31 | c = a + b; 32 | System.out.print(a+" "); 33 | } 34 | } 35 | } 36 | 37 | /* (1) 38 | Input: 5 39 | Output: 0 1 1 2 3 40 | 41 | (2) 42 | Input: 8 43 | Output: 0 1 1 2 3 5 8 13 44 | 45 | (3) 46 | Input: 12 47 | Output: 0 1 1 2 3 5 8 13 21 34 55 89 48 | */ 49 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_06 - Product of 2 Matrices.java: -------------------------------------------------------------------------------- 1 | // Java Program to find the product of two matrices. 2 | 3 | // Refer Python/Exp_06 4 | // LMS compiler required python code 5 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_07 - Prime or Not.java: -------------------------------------------------------------------------------- 1 | // Java Program to Check Whether a Number is Prime or Not 2 | 3 | /* START 4 | Step 1 → Take integer variable A 5 | Step 2 → Divide the variable A with (A-1 to 2) 6 | Step 3 → If A is divisible by any value (A-1 to 2) it is not prime 7 | Step 4 → Else it is prime 8 | STOP 9 | */ 10 | 11 | import java.util.Scanner; 12 | 13 | public class Main 14 | { 15 | public static void main(String args[]) 16 | { 17 | int temp; 18 | boolean isPrime = true; 19 | Scanner scan= new Scanner(System.in); 20 | 21 | int num = scan.nextInt(); 22 | scan.close(); 23 | for(int i = 2;i <= num / 2;i++) 24 | { 25 | temp = num % i; 26 | if(temp == 0) 27 | { 28 | isPrime = false; 29 | break; 30 | } 31 | } 32 | 33 | if(isPrime) 34 | System.out.println(num + " is a prime number"); 35 | else 36 | System.out.println(num + " is not a prime number"); 37 | } 38 | } 39 | 40 | /* Input: 33 41 | Output: 33 is not a prime number 42 | */ 43 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_08 - Swap 2 Numbers.java: -------------------------------------------------------------------------------- 1 | // Java program to swap two numbers 2 | 3 | /* Swapping a=10 b=5 4 | After Swap 5 | a=5 b=10 6 | */ 7 | 8 | import java.util.*; 9 | 10 | public class Main { 11 | public static void main(String[] args) { 12 | int a, b, c; 13 | Scanner sc = new Scanner(System.in); 14 | a = sc.nextInt(); 15 | b = sc.nextInt(); 16 | c = a; 17 | a = b; 18 | b = c; 19 | System.out.println(a + "\n" + b); 20 | } 21 | } 22 | 23 | /* Input: 10 24 | 5 25 | Output: 5 26 | 10 27 | */ -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_09 - Reverse a String.java: -------------------------------------------------------------------------------- 1 | // Java program to reverse a string 2 | 3 | /* str ="welcome" 4 | rev ="emoclew" 5 | */ 6 | 7 | import java.util.*; 8 | 9 | public class Main { 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | String str = sc.nextLine(); 13 | String rev = ""; 14 | 15 | for (int i = str.length() - 1; i >= 0; i--) 16 | rev = rev + str.charAt(i); 17 | System.out.println(rev); 18 | } 19 | } 20 | 21 | /* Input: welcome 22 | Output: emoclew 23 | */ -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_10 - Armstrong Number or Not.java: -------------------------------------------------------------------------------- 1 | // Java Program to check if the given number is Armstrong number or not 2 | 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | int originalNumber, remainder, result = 0; 8 | Scanner sc = new Scanner(System.in); 9 | int number = sc.nextInt(); 10 | originalNumber = number; 11 | 12 | while (originalNumber != 0) 13 | { 14 | remainder = originalNumber % 10; 15 | result += Math.pow(remainder, 3); 16 | originalNumber /= 10; 17 | } 18 | 19 | if (result == number) 20 | System.out.println("It is an Armstrong Number"); 21 | else 22 | System.out.println("It is not an Armstrong Number"); 23 | } 24 | } 25 | 26 | /* Input: 153 27 | Output: It is an Armstrong Number 28 | */ -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_11 - GCD of 2 Numbers.java: -------------------------------------------------------------------------------- 1 | // Java Program to find the GCD of two numbers 2 | 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int x = sc.nextInt(); 9 | int y = sc.nextInt(); 10 | int gcd = 1; 11 | 12 | for (int i = 1; i <= x && i <= y; i++) { 13 | if (x % i == 0 && y % i == 0) 14 | gcd = i; 15 | 16 | } 17 | System.out.printf("%d", gcd); 18 | 19 | } 20 | } 21 | 22 | /* Input: 12 23 | 8 24 | Output: 4 25 | */ -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_12 - Display Even Numbers.java: -------------------------------------------------------------------------------- 1 | // Java Program to Display Even Numbers From 1 to 100 2 | 3 | import java.util.*; 4 | 5 | public class Main { 6 | private static void displayEvenNumbers(int num, int end) { 7 | if (num > end) 8 | return; 9 | 10 | if (num % 2 == 0) { 11 | System.out.print(num + " "); 12 | displayEvenNumbers(num + 2, end); 13 | } else { 14 | displayEvenNumbers(num + 1, end); 15 | } 16 | } 17 | 18 | public static void main(String[] args) { 19 | displayEvenNumbers(1, 31); 20 | } 21 | } 22 | 23 | // Output: 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 24 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_13 - Case Conversion.java: -------------------------------------------------------------------------------- 1 | // Java Program to convert the upper case to lower case and vice versa 2 | 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | String str = sc.nextLine(); 9 | StringBuffer newStr = new StringBuffer(str); 10 | 11 | for (int i = 0; i < str.length(); i++) { 12 | if (Character.isLowerCase(str.charAt(i))) { 13 | newStr.setCharAt(i, Character.toUpperCase(str.charAt(i))); 14 | 15 | } else if (Character.isUpperCase(str.charAt(i))) { 16 | newStr.setCharAt(i, Character.toLowerCase(str.charAt(i))); 17 | } 18 | } 19 | System.out.print(newStr); 20 | } 21 | } 22 | 23 | /* (1) 24 | Input: WELCOME 25 | Output: welcome 26 | 27 | (2) 28 | Input: welcome 29 | Output: WELCOME 30 | */ 31 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_14 - Bubble Sort.java: -------------------------------------------------------------------------------- 1 | // Java program to implement Bubble Sort 2 | 3 | import java.util.*; 4 | 5 | public class Main 6 | { 7 | void bubbleSort(int arr[]) 8 | { 9 | int n = arr.length; 10 | for (int i = 0; i < n - 1; i++) 11 | for (int j = 0; j < n - i - 1; j++) 12 | if (arr[j] > arr[j + 1]) 13 | { 14 | int temp = arr[j]; 15 | arr[j] = arr[j + 1]; 16 | arr[j + 1] = temp; 17 | } 18 | } 19 | 20 | void display(int arr[]) 21 | { 22 | int n = arr.length; 23 | for (int i = 0; i < n; ++i) 24 | System.out.println(arr[i] + " "); 25 | System.out.println(); 26 | } 27 | 28 | public static void main(String[] args) 29 | { 30 | Main obj = new Main(); 31 | int arr[] = {30, 20, 10, 50, 40}; 32 | obj.bubbleSort(arr); 33 | obj.display(arr); 34 | } 35 | } 36 | 37 | /* Output: 10 38 | 20 39 | 30 40 | 40 41 | 50 42 | */ 43 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_15 - Power of a Number.java: -------------------------------------------------------------------------------- 1 | // Java program to find the power of a number 2 | 3 | // 2 power 3 = 8 4 | 5 | import java.util.*; 6 | 7 | public class Main { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int base = sc.nextInt(); 11 | int exp = sc.nextInt(); 12 | long result = 1; 13 | for (; exp != 0; --exp) { 14 | result *= base; 15 | } 16 | System.out.println(result); 17 | } 18 | } 19 | 20 | /* Input: 2 21 | 3 22 | Output: 8 23 | */ -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Java/Exp_16 - Largest Element in an Array.java: -------------------------------------------------------------------------------- 1 | // Java program to find the largest element in the array 2 | 3 | /* 20 4 | 5 | 10 6 | 7 | 50 8 | 9 | 30 10 | 11 | 90 12 | 13 | largest : 90 14 | */ 15 | 16 | import java.util.*; 17 | 18 | public class Main { 19 | public static void main(String[] args) { 20 | int i, large; 21 | int[] arr = new int[5]; 22 | Scanner sc = new Scanner(System.in); 23 | 24 | for(i = 0; i < 5; i++) { 25 | arr[i] = sc.nextInt(); 26 | } 27 | 28 | large = arr[0]; 29 | for(i = 1; i < 5; i++) { 30 | large = large < arr[i] ? large = arr[i] : 0; 31 | } 32 | 33 | System.out.println(large); 34 | } 35 | } 36 | 37 | /* Input: 20 38 | 10 39 | 50 40 | 30 41 | 90 42 | Output: 90 43 | */ 44 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_01 - Palindrome.py: -------------------------------------------------------------------------------- 1 | # Python Program to find whether the given number is palindrome or not? 2 | 3 | # Take the value of the integer and store in a variable. 4 | # Transfer the value of the integer into another temporary variable. 5 | # Using a while loop, get each digit of the number and store the reversed number in another variable. 6 | # Check if the reverse of the number is equal to the one in the temporary variable. 7 | # Print the final result. 8 | # Exit. 9 | 10 | num=input() 11 | if num[0:]==num[::-1]: 12 | print('{} is a palindrome number'.format(int(num))) 13 | 14 | 15 | # Input: 121 16 | # Output: 121 is a palindrome number 17 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_02 - Reverse a Number.py: -------------------------------------------------------------------------------- 1 | # Python program to reverse a number using recursive function. 2 | 3 | # Input: num 4 | # (1) Initialize rev_num = 0 5 | # (2) Loop while num > 0 6 | # (a) Multiply rev_num by 10 and add remainder of num 7 | # divide by 10 to rev_num 8 | # rev_num = rev_num*10 + num%10; 9 | # (b) Divide num by 10 10 | # (3) Return rev_num 11 | 12 | num=int(input()) 13 | revnum=0 14 | 15 | while num>0: 16 | 17 | rem=num%10 18 | revnum=revnum*10+rem 19 | num=num//10 20 | 21 | print(revnum) 22 | 23 | # Input: 4562 24 | # Output: 2654 25 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_03 - Lowercase to Uppercase.py: -------------------------------------------------------------------------------- 1 | # Python Program to convert lowercase string to uppercase string 2 | 3 | # Get the input string 4 | # Convert lower case to upper case 5 | # Print the output 6 | 7 | print(input().upper()) 8 | 9 | # Input: sathyabama 10 | # Output: SATHYABAMA 11 | 12 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_04 - Fibonacci Series.py: -------------------------------------------------------------------------------- 1 | # Python Program to print the Fibonacci Series. 2 | 3 | # Step 1:Input the 'n' value until which the Fibonacci series has to be generated 4 | # Step 2:Initialize sum = 0, a = 0, b = 1 and count = 1 5 | # Step 3:while (count <= n) 6 | # Step 4:print sum 7 | # Step 5:Increment the count variable 8 | # Step 6:swap a and b 9 | # Step 7:sum = a + b 10 | # Step 8:while (count > n) 11 | # Step 9:End the algorithm 12 | # Step 10:Else 13 | # Step 11:Repeat from steps 4 to 7 14 | 15 | n = input("") 16 | a, b = 0, 1 17 | count = 1 18 | print("Fibonacci Series: ", a, b, end = " ") 19 | while (int(n) > count + 1): 20 | sum = a + b 21 | print(sum, end = " ") 22 | a, b = b, sum 23 | count += 1 24 | 25 | # Input: 5 26 | # Output: Fibonacci Series: 0 1 1 2 3 27 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_05 - Sort Elements of a List in Ascending Order.py: -------------------------------------------------------------------------------- 1 | # Python program to sort the elements of list in ascending order 2 | 3 | # STEP 1: Declare and initialize an array. 4 | # STEP 2: Loop through the array and select an element. 5 | # STEP 3: The inner loop will be used to compare the selected element from the outer loop with the rest of the elements of the array. 6 | # STEP 4: If any element is less than the selected element then swap the values. 7 | # STEP 5: Continue this process until the entire array is sorted in ascending order. 8 | 9 | arr=[5,2,8,7,1] 10 | temp=0 11 | for i in range(0,len(arr)-1): 12 | for j in range(0,len(arr)-i-1): 13 | if(arr[j]>arr[j+1]): 14 | temp=arr[j] 15 | arr[j]=arr[j+1] 16 | arr[j+1]=temp 17 | for i in range(0,len(arr)): 18 | print(arr[i],end=" ") 19 | 20 | # Input: 5 2 8 7 1 21 | # Output: 1 2 5 7 8 22 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_07 - Vowel or Consonant..py: -------------------------------------------------------------------------------- 1 | # Python program to check whether an alphabet is vowel or consonant. 2 | 3 | # Step 1: Get a character from the user 4 | # Step 2: Check whether the input is vowel or consonant by using the python built-in functions like(lower(), upper()). 5 | # Step 3: If the character is vowel print Vowel otherwise print Consonant 6 | # Step 4: End 7 | 8 | x = input("") 9 | 10 | if (x == 'A' or x == 'a' or x == 'E' or x == 'e' or x == 'I' or x == 'i' or x == 'O' or x == 'o' or x == 'U' or x == 'u'): 11 | print("Vowel") 12 | else: 13 | print("Consonant") 14 | 15 | # Input: E 16 | # Output: Vowel 17 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_08 - Prime Number.py: -------------------------------------------------------------------------------- 1 | # Python Program to Check Prime Number. 2 | 3 | # START 4 | # Step 1 → Take integer variable A 5 | # Step 2 → Divide the variable A with (A-1 to 2) 6 | # Step 3 → If A is divisible by any value (A-1 to 2) it is not prime 7 | # Step 4 → Else it is prime 8 | # STOP 9 | 10 | num=int(input()) 11 | if num>1: 12 | for i in range(2, num): 13 | if (num % i) == 0: 14 | print('{} is not a prime number'.format(num)) 15 | break 16 | else: 17 | print('{} is a prime number'.format(num)) 18 | else: 19 | print(num, "is not a prime number") 20 | 21 | # Input : 11 22 | 23 | # Output : 11 is a prime number 24 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_09 - Prime or Not.py: -------------------------------------------------------------------------------- 1 | # Python Program to Check If a number is Prime or Not. 2 | 3 | # A number is said to be prime if it is only divisible by 1 and itself. 4 | # Step 1: Take the input from User 5 | # Step 2: Check whether the number is greater than 1, if not than the number is not Prime 6 | # Step 3: Check if the number gets evenly divided by any number from 2 to half of the number 7 | # Step 4: Print the result 8 | 9 | num=2 10 | if num>1: 11 | for i in range(2, num): 12 | if (num % i) == 0: 13 | print('{} is not a prime number'.format(num)) 14 | break 15 | else: 16 | print('{} is a Prime number'.format(num)) 17 | else: 18 | print(num, "is not a prime number") 19 | 20 | # Input: Enter The Number 2 21 | 22 | # Output: 2 is a Prime number 23 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_10 - Calculate Gross Salary.py: -------------------------------------------------------------------------------- 1 | # Python program to enter basic salary and calculate gross salary of an employee algorithm. 2 | 3 | # dearness allowance is 40% of basic salary 4 | # house rent allowance is 20% of basic salary 5 | 6 | basic_salary=20000 7 | dearness_allowance=(40*basic_salary)/100 8 | house_rent=(20*basic_salary)/100 9 | gross_salary=house_rent+dearness_allowance+basic_salary 10 | print('Dearness Allowance 40 % of Basic Salary : {}'.format(float(dearness_allowance))) 11 | print('House Rent 20 % of Basic Salary : {}'.format(float(house_rent))) 12 | print('Gross Salary : {}'.format(float(gross_salary))) 13 | 14 | # Input: Enter Basic Salary : 20000 15 | # Output: 16 | # Dearness Allowance 40 % of Basic Salary : 8000.0 17 | # House Rent 20 % of Basic Salary : 4000.0 18 | # Gross Salary : 32000.0 -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_11 - Pyramid Patterns.py: -------------------------------------------------------------------------------- 1 | # Python Program to Create Pyramid Patterns. 2 | # Accept the number of rows from the user to form pyramid shape 3 | # Iterate the loop till the number of rows specified by the user: 4 | # Display 1 star in the first row 5 | # Increase the number of stars based on the number of rows. 6 | 7 | rows = 5 8 | k = 0 9 | for i in range(1, rows+1): 10 | for space in range(1, (rows-i)+1): 11 | print(end=" ") 12 | 13 | while k!=(2*i-1): 14 | print("* ", end="") 15 | k += 1 16 | k = 0 17 | print() 18 | 19 | # Input : * 20 | # Output : 21 | # * 22 | # * * * 23 | # * * * * * 24 | # * * * * * * * 25 | # * * * * * * * * * 26 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_12 - Selection Sort.py: -------------------------------------------------------------------------------- 1 | # Python Program for Selection Sort. 2 | 3 | # 1. Create a function selection_sort that takes a list as argument. 4 | # 2. Inside the function create a loop with a loop variable i that counts from 0 to the length of the list – 1. 5 | # 3. Create a variable smallest with initial value i. 6 | # 4. Create an inner loop with a loop variable j that counts from i + 1 up to the length of the list – 1. 7 | # 5. Inside the inner loop, if the elements at index j is smaller than the element at index smallest, then set smallest equal to j. 8 | # 6. After the inner loop finishes, swap the elements at indexes i and smallest. 9 | 10 | def selection_sort(a): 11 | for i in range(0,len(a)-1): 12 | smallest=i 13 | for j in range(i+1,len(a)): 14 | if a[j] 0): 7 | result = k + tri_recursion(k - 1) 8 | print(result) 9 | else: 10 | result = 0 11 | return result 12 | 13 | print("Recursion Example Results") 14 | tri_recursion(6) 15 | 16 | # Input: 6 17 | # Output: Recursion Example Results 18 | # 1 19 | # 3 20 | # 6 21 | # 10 22 | # 15 23 | # 21 24 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_13 (b) - Implement Functions and Libraries.py: -------------------------------------------------------------------------------- 1 | # Implement Built In Function and Libraries using python. 2 | 3 | # 1.lists can have items with the same value. 4 | # 2. determine how many items a list has, use the len() function 5 | # 3.list can contain different data types 6 | # 4.list() constructor when creating a new list 7 | 8 | list1=['apple', 'banana', 'cherry', 'apple', 'cherry'] 9 | print(list1) 10 | 11 | list2=["apple", "banana", "cherry"] 12 | print(len(list2)) 13 | 14 | list3=["abc", 34, True, 40, "male"] 15 | print(list3) 16 | 17 | list4=list(('apple', 'banana', 'cherry')) 18 | print(list4) 19 | 20 | # Input: 21 | # ['apple', 'banana', 'cherry', 'apple', 'cherry'] 22 | # ["apple", "banana", "cherry"] 23 | # ["abc", 34, True, 40, "male"] 24 | # ['apple', 'banana', 'cherry'] 25 | 26 | # Output: 27 | # ['apple', 'banana', 'cherry', 'apple', 'cherry'] 28 | # 3 29 | # ['abc', 34, True, 40, 'male'] 30 | # ['apple', 'banana', 'cherry'] 31 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_16 - Optimizing Loop.py: -------------------------------------------------------------------------------- 1 | # Implement Optimizing loop using python. 2 | 3 | # Python program to swap two variables 4 | # To take inputs from the user 5 | # x = input('Enter value of x: ') 6 | # y = input('Enter value of y: ') 7 | # create a temporary variable and swap the values 8 | 9 | x=2 10 | y=5 11 | temp=x 12 | x=y 13 | y=temp 14 | print(x,y) 15 | x,y=3,5 16 | x,y=y,x 17 | print(x,y) 18 | 19 | # Input: 20 | 21 | # 5 2 22 | # 5 3 23 | 24 | # Output: 25 | 26 | # 5 2 27 | # 5 3 28 | 29 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_17 - GCD of 2 Numbers.py: -------------------------------------------------------------------------------- 1 | # Python program to find the gcd of two numbers 2 | 3 | # Step 1:Get 2 integer inputs from the user 4 | # Step 2:Next, use decision-making statements or use recursion to check if both the given numbers are divisible by any number (i) without leaving any remainder. 5 | # Step 3:If true, then GCD = i 6 | # Step 4:Print the GCD of the two numbers 7 | # Step 5:End of the program 8 | 9 | def hcf(a,b): 10 | if(b==0): 11 | return a 12 | else: 13 | return hcf(b,a%b) 14 | a=60 15 | b=48 16 | print("The gcd of 60 and 48 is : ",end="") 17 | print(hcf(60,48)) 18 | 19 | # Input : 20 | # Enter two numbers 21 | # 60 22 | # 48 23 | 24 | # Output : 25 | # The gcd of 60 and 48 is : 12 26 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_18 - Sum of Natural Numbers Using Recursion.py: -------------------------------------------------------------------------------- 1 | # Python Program to Find Sum of Natural Numbers Using Recursion 2 | 3 | # The user enters the Nth number as the input, the program then calculates the sum of first N numbers using recursion and then displays the final result. 4 | # Example 1: Let n = 5 5 | # Therefore, the sum of the first 5 natural numbers = 1 + 2 + 3 + 4 + 5 = 15. 6 | # Thus, the output is 15 7 | 8 | def sum(n): 9 | if n==0: 10 | return 0 11 | else: 12 | return n+sum(n-1) 13 | arr=[x for x in input().split()] 14 | number=int(arr[len(arr)-1]) 15 | if number>=0: 16 | print("The sum is ", sum(number)) 17 | else: 18 | print("Natural number begins from 1") 19 | 20 | # Input: 21 | # Enter the number: 25 22 | # Enter the number: -12 23 | 24 | # Output: 25 | # The sum is 325 26 | # Natural number begins from 1 27 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_19 - Convert Binary Number to Decimal.py: -------------------------------------------------------------------------------- 1 | # Python program to convert a binary number to decimal number. 2 | 3 | # From decimal to binary 4 | # Input : 8 5 | # Output : 1 0 0 0 6 | 7 | # From binary to decimal 8 | # Input : 100 9 | # Output : 4 10 | # Keep calling conversion function with n/2 till n > 1, 11 | # later perform n % 1 to get MSB of converted binary number. 12 | # Example :- 7 13 | # 1). 7/2 = Quotient = 3(greater than 1), Remainder = 1. 14 | # 2). 3/2 = Quotient = 1(not greater than 1), Remainder = 1. 15 | # 3). 1%2 = Remainder = 1. 16 | # Therefore, answer is 111. 17 | 18 | b_num=list(input("")) 19 | value=0 20 | for i in range(len(b_num)): 21 | digit=b_num.pop() 22 | if digit == '1': 23 | value= value+pow(2,i) 24 | print("Equivalent Decimal Value =",value) 25 | 26 | # Input: user input, 11110110 27 | 28 | # Output: Equivalent Decimal Value = 246 29 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_20 - Factorial Program with Memoization.py: -------------------------------------------------------------------------------- 1 | # Factorial program with memoization using decorators. 2 | 3 | # Memoization is a technique of recording the intermediate results so that it can be used to avoid repeated calculations and speed up the programs. 4 | # memoization can be done with the help of function decorators. 5 | 6 | def Memoize(func): 7 | history={} 8 | def wrapper(*args): 9 | if args not in history: 10 | history[args]=func(*args) 11 | return history[args] 12 | return wrapper 13 | 14 | def factorial(n): 15 | if type(n)!=int: 16 | raise ValueError("passed value is not integer") 17 | if(n<0): 18 | raise ValueError("number cant be negative passed value{}".format(n)) 19 | if n==0 or n==1: 20 | return 1 21 | fact=n*factorial(n-1) 22 | return fact 23 | print(format(factorial(5))) 24 | 25 | # Input : 5 26 | 27 | # Output : 120 -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_21 - Factorial of a Number.py: -------------------------------------------------------------------------------- 1 | # Python Program for factorial of a number 2 | 3 | # Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. 4 | # For example factorial of 6 is 6*5*4*3*2*1 which is 720. 5 | 6 | num=int(input()) 7 | factorial = 1 8 | if num<0: 9 | print("Factorial does not exist for negative numbers") 10 | elif num==0: 11 | print("The factorial of 0 is 1") 12 | else: 13 | for i in range(1,num+1): 14 | factorial=factorial*i 15 | print("Factorial of",num,"is",factorial) 16 | 17 | 18 | # Input: 5 19 | # Output: Factorial of 5 is 120 -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_25 - Monitoring Memory Usage.py: -------------------------------------------------------------------------------- 1 | # Monitoring memory usage of a running Python program 2 | 3 | # sing Tracemalloc 4 | # Tracemalloc is a library module that traces every memory blocks in python. The tracing starts by using the start() during runtime. This library module can also give information about the total size, number and average size of allocated memory blocks 5 | 6 | import tracemalloc 7 | def app(): 8 | x=[] 9 | for i in range(0,100000): 10 | x.append(i) 11 | 12 | tracemalloc.start() 13 | app() 14 | 15 | print(tracemalloc.get_traced_memory()) 16 | tracemalloc.stop() 17 | 18 | # Output: (0, 3617252) 19 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_27 - Anonymous Function.py: -------------------------------------------------------------------------------- 1 | # Python Program to Display Powers of 2 Using Anonymous Function 2 | 3 | # To display powers of the integer 2 using Python anonymous function. 4 | 5 | a = 10 6 | b = list(map(lambda x: 2 ** x, range(a))) 7 | for c in range(a): print("2 raised to power", c, "is", b[c]) 8 | 9 | # Input: The total terms are: 10 10 | # Output: 2 raised to power 0 is 1 11 | # 2 raised to power 1 is 2 12 | # 2 raised to power 2 is 4 13 | # 2 raised to power 3 is 8 14 | # 2 raised to power 4 is 16 15 | # 2 raised to power 5 is 32 16 | # 2 raised to power 6 is 64 17 | # 2 raised to power 7 is 128 18 | # 2 raised to power 8 is 256 19 | # 2 raised to power 9 is 512 20 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_28 - Heap Sort.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of heap Sort 2 | 3 | # Heapsort is a comparison based sorting technique based on a Binary Heap data structure. 4 | # It is similar to selection sort where we first find the maximum element and place the maximum element at the end. 5 | # We repeat the same process for the remaining element. 6 | 7 | def heapify(arr, n, i): 8 | largest = i 9 | l = 2 * i + 1 10 | r = 2 * i + 2 11 | 12 | if l < n and arr[i] < arr[l]: 13 | largest = l 14 | if r < n and arr[largest] < arr[r]: 15 | largest = r 16 | if largest != i: 17 | arr[i],arr[largest] = arr[largest],arr[i] 18 | heapify(arr, n, largest) 19 | 20 | def heapSort(arr): 21 | n = len(arr) 22 | 23 | for i in range(n // 2 - 1, -1, -1): 24 | heapify(arr, n, i) 25 | for i in range(n - 1, 0, -1): 26 | arr[i], arr[0] = arr[0], arr[i] 27 | heapify(arr, i, 0) 28 | 29 | arr = [12, 11, 13, 5, 6, 7] 30 | heapSort(arr) 31 | n = len(arr) 32 | print ("Sorted array is") 33 | for i in range(n): 34 | print ("%d" %arr[i]) 35 | 36 | # Input: 12, 11, 13, 5, 6, 7 37 | # Output: Sorted array is 38 | # 5 39 | # 6 40 | # 7 41 | # 11 42 | # 12 43 | # 13 44 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_29 - Shell Sort.py: -------------------------------------------------------------------------------- 1 | # Python Program for ShellSort 2 | 3 | # In shellSort, we make the array h-sorted for a large value of h. 4 | # We keep reducing the value of h until it becomes 1. An array is said to be h-sorted if all sublists of every h\’th element is sorted. 5 | 6 | def shellSort(arr, n): 7 | gap = int(n / 2) 8 | while gap > 0: 9 | for i in range(gap, n): 10 | temp = arr[i] 11 | j = i 12 | while j >= gap and arr[j - gap] > temp: 13 | arr[j] = arr[j - gap] 14 | j -= gap 15 | arr[j] = temp 16 | gap /= 2 17 | gap = int(gap) 18 | 19 | arr = [9, 8, 3, 7, 5, 6, 4, 1] 20 | shellSort(arr, len(arr)) 21 | 22 | print("Sorted Array in Ascending Order:") 23 | print(arr) 24 | 25 | # Input: Array before sorting: 26 | # 9, 8, 3, 7, 5, 6, 4, 1 27 | # Output: Sorted Array in Ascending Order: 28 | # [1, 3, 4, 5, 6, 7, 8, 9] 29 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_30 - Bubble Sort.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of heap Sort 2 | 3 | # Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. 4 | 5 | def bubbleSort(arr): 6 | n = len(arr) 7 | for i in range(n - 1): 8 | for j in range(0, n - i - 1): 9 | if arr[j] > arr[j + 1] : 10 | arr[j], arr[j + 1] = arr[j + 1], arr[j] 11 | 12 | arr = [-2, 45, 0, 11, -9] 13 | 14 | bubbleSort(arr) 15 | print("Sorted Array in Ascending Order:") 16 | print(arr) 17 | 18 | # Input: -2, 45, 0, 11, -9 19 | # Output: Sorted Array in Ascending Order: 20 | # [-9, -2, 0, 11, 45] 21 | -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_31 - Merge Sort.py: -------------------------------------------------------------------------------- 1 | # Python Program for Merge Sort 2 | 3 | # Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves. 4 | # The merge() function is used for merging two halves. The merge(arr, l, m, r) is key process that assumes that arr[l..m] and arr[m+1..r] are sorted and merges the two sorted sub-arrays into one. 5 | 6 | def mergeSort(arr): 7 | if len(arr) > 1: 8 | mid = len(arr) // 2 9 | L = arr[:mid] 10 | R = arr[mid:] 11 | mergeSort(L) 12 | mergeSort(R) 13 | i = j = k = 0 14 | 15 | while i < len(L) and j < len(R): 16 | if L[i] < R[j]: 17 | arr[k] = L[i] 18 | i += 1 19 | else: 20 | arr[k] = R[j] 21 | j += 1 22 | k += 1 23 | 24 | while i < len(L): 25 | arr[k] = L[i] 26 | i += 1 27 | k += 1 28 | 29 | while j < len(R): 30 | arr[k] = R[j] 31 | j += 1 32 | k += 1 33 | 34 | def printList(arr): 35 | for i in range(len(arr)): 36 | print(arr[i], end=" ") 37 | 38 | arr = [12, 11, 13, 5, 6, 7] 39 | mergeSort(arr) 40 | print("Sorted array is: ", end="\n") 41 | printList(arr) 42 | 43 | 44 | # Input: [12, 11, 13, 5, 6, 7] 45 | # Output: Sorted array is: 46 | # 5 6 7 11 12 13 -------------------------------------------------------------------------------- /Semester 3/Code Optimization and Debugging-I/Python/Exp_32 - Radix Sort.py: -------------------------------------------------------------------------------- 1 | # Python Program for Radix Sort 2 | 3 | # 1) Do the following for each digit i where i varies from the least significant digit to the most significant digit. 4 | # Sort input array using counting sort (or any stable sort) according to the i\’th digit. 5 | 6 | def sort(arr, exp1): 7 | n = len(arr) 8 | output = [0] * (n) 9 | count = [0] * (10) 10 | 11 | for i in range(0, n): 12 | index = (arr[i] / exp1) 13 | count[int((index) % 10)] += 1 14 | 15 | for i in range(1, 10): 16 | count[i] += count[i - 1] 17 | 18 | i = n - 1 19 | 20 | while i >= 0: 21 | index = (arr[i] / exp1) 22 | output[count[int((index) % 10)] - 1] = arr[i] 23 | count[int((index) % 10)] -= 1 24 | i -= 1 25 | 26 | i = 0 27 | 28 | for i in range(0, len(arr)): 29 | arr[i] = output[i] 30 | 31 | def radixSort(arr): 32 | max1 = max(arr) 33 | exp2 = 1 34 | 35 | while max1 / exp2 > 0: 36 | sort(arr, exp2) 37 | exp2 *= 10 38 | 39 | arr = [170, 45, 75, 90, 802, 24, 2, 66] 40 | radixSort(arr) 41 | 42 | for i in range(len(arr)): 43 | print(arr[i]) 44 | 45 | # Input: [ 170, 45, 75, 90, 802, 24, 2, 66] 46 | # Output: 2 47 | # 24 48 | # 45 49 | # 66 50 | # 75 51 | # 90 52 | # 170 53 | # 802 -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_01 - Create a Table and Display Structure of Table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE client_master ( 2 | client_no VARCHAR(6), 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10,2) 8 | ); 9 | 10 | PRAGMA table_info('client_master'); -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_02 - Inserting a New Record into Table and Display Contents of the Table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE client_master ( 2 | client_no VARCHAR(6), 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10,2) 8 | ); 9 | 10 | INSERT INTO client_master VALUES('0001', 'Ivan', 'Bombay', 400054, 'Maharashtra', 15000), ('0002', 'Vandana', 'Madras', 780001, 'Tamilnau', 756742.54), ('0003', 'Pramada', 'Bombay', 400057, 'Maharashtra', 5000.45), ('0008', 'Kumar', 'Cochin', 500057, 'Kerela', 54560.45); 11 | SELECT * FROM client_master; 12 | -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_03 - Create a Table, Insert Records, Delete Records from Table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE client_master ( 2 | client_no VARCHAR(6) PRIMARY KEY, 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10,2) 8 | ); 9 | 10 | INSERT INTO client_master VALUES('0001', 'Ivan', 'Bombay', 400054, 'Maharashtra', 15000), ('0002', 'Vandana', 'Madras', 780001, 'Tamilnau', 756742.54), ('0003', 'Pramada', 'Bombay', 400057, 'Maharashtra', 5000.45); 11 | SELECT * FROM client_master; 12 | -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_04 - Create Table, Insert Records and Display Details Based on City.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE client_master ( 2 | client_no VARCHAR(6), 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10,2) 8 | ); 9 | 10 | INSERT INTO client_master VALUES('0001', 'Ivan', 'Bombay', 400054, 'Maharashtra', 15000), ('0002', 'Vandana', 'Madras', 780001, 'Tamilnau', 756742.54), ('0003', 'Pramada', 'Bombay', 400057, 'Maharashtra', 5000.45); 11 | SELECT * FROM client_master WHERE city IN('Bombay'); 12 | -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_05 - Insert 3 Rows Using a Single Insert Statement.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE client_master ( 2 | client_no VARCHAR(6), 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10,2), 8 | PRIMARY KEY(pincode) 9 | ); 10 | 11 | INSERT INTO client_master VALUES('0001', 'Ivan', 'Bombay', 400054, 'Maharashtra', 15000), ('0002', 'Vandana', 'Madras', 780001, 'Tamilnau', 756742.54), ('0003', 'Pramada', 'Bombay', 400057, 'Maharashtra', 5000.45); 12 | SELECT * FROM client_master; -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_06 - Update Record Details of Table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE student_db ( 2 | regno INT(11), 3 | student_name CHAR(30), 4 | student_dept VARCHAR(25), 5 | date_of_join DATE 6 | ); 7 | 8 | INSERT INTO student_db VALUES(1234, 'Kumar21', 'CSE_18scs123', '2019-03-22'), (567, 'Rohit_sathyabama_Institute', 'Mech3', '2019-05-12'); 9 | 10 | UPDATE student_db SET student_name = 'Rohit_sathya' WHERE regno = 567; 11 | SELECT * FROM student_db; -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_07 - Alter Table Structure - Add New Column.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE client_master ( 2 | client_no VARCHAR(6), 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10, 2) 8 | ); 9 | 10 | INSERT INTO client_master VALUES('0001', 'Ivan', 'Bombay', 400054, 'Maharashtra', 15000), ('0002', 'Vandana', 'Madras', 780001, 'Tamilnau', 756742.54), ('0003', 'Pramada', 'Bombay', 400057, 'Maharashtra', 5000.45); 11 | ALTER TABLE client_master ADD COLUMN DOJ; 12 | INSERT INTO client_master VALUES('0011', 'RajuMohan', 'Vijawada', 520001, 'AndraPradesh', 44326.12, '2019-06-12'); 13 | SELECT * FROM client_master; 14 | -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_08 - Select Statement Using Where Condition.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE client_master ( 2 | client_no VARCHAR(6), 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10, 2) 8 | ); 9 | 10 | INSERT INTO client_master VALUES('0001', 'Ivan', 'Bombay', 400054, 'Maharashtra', 15000), ('0002', 'Vandana', 'Madras', 780001, 'Tamilnau', 756742.54), ('0003', 'Pramada', 'Bombay', 400057, 'Maharashtra', 5000.45); 11 | SELECT * FROM client_master WHERE bal_due > 8000 AND city = "Bombay"; 12 | -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_09 - Display Selected Columns from the Table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE client_master ( 2 | client_no VARCHAR(6), 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10, 2) 8 | ); 9 | 10 | INSERT INTO client_master VALUES('0001', 'Ivan', 'Bombay', 400054, 'Maharashtra', 15000), ('0002', 'Vandana', 'Madras', 780001, 'Tamilnau', 756742.54), ('0003', 'Pramada', 'Bombay', 400057, 'Maharashtra', 5000.45), ('0008', 'Kumar', 'Cochin', 500057, 'Kerela', 54560.45); 11 | SELECT name, state FROM client_master; 12 | -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_10 - Remove Duplicate Records from the Table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE client_master ( 2 | client_no VARCHAR(6), 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10, 2) 8 | ); 9 | 10 | INSERT INTO client_master VALUES('0001', 'Ivan', 'Bombay', 400054, 'Maharashtra', 15000), ('0002', 'Vandana', 'Madras', 780001, 'Tamilnau', 756742.54), ('0003', 'Pramada', 'Bombay', 400057, 'Maharashtra', 5000.45), ('0008', 'Kumar', 'Cochin', 500057, 'Kerela', 54560.45), ('0008', 'Kumar', 'Cochin', 500057, 'Kerela', 54560.45); 11 | SELECT DISTINCT name FROM client_master; 12 | -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_11 - Alter Table - Rename a Table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE client_master ( 2 | client_no VARCHAR(6), 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10, 2) 8 | ); 9 | 10 | INSERT INTO client_master VALUES('0001', 'Ivan', 'Bombay', 400054, 'Maharashtra', 15000), ('0002', 'Vandana', 'Madras', 780001, 'Tamilnau', 756742.54), ('0003', 'Pramada', 'Bombay', 400057, 'Maharashtra', 5000.45), ('0008', 'Kumar', 'Cochin', 500057, 'Kerela', 54560.45); 11 | ALTER TABLE client_master RENAME TO client; 12 | SELECT * FROM client; 13 | -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_12 - Display First 3 Records from Table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE client_master ( 2 | client_no VARCHAR(6), 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10, 2) 8 | ); 9 | 10 | INSERT INTO client_master VALUES('0001', 'Ivan', 'Bombay', 400054, 'Maharashtra', 15000), ('0002', 'Vandana', 'Madras', 780001, 'Tamilnau', 756742.54), ('0003', 'Pramada', 'Bombay', 400057, 'Maharashtra', 5000.45), ('0008', 'Kumar', 'Cochin', 500057, 'Kerela', 54560.45); 11 | SELECT * FROM client_master LIMIT 0,3; 12 | -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_13 - Create a Duplicate Copy of a Table - Copy Its Structure and Data.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE student_db ( 2 | Reg_No INT(15), 3 | Roll_No VARCHAR(20), 4 | Student_Name VARCHAR(15), 5 | User_ID VARCHAR(15) 6 | ); 7 | 8 | INSERT INTO student_db VALUES(3311159, '15SCS333', 'Abraham', '159Abr'), (3411147, '14SS564', 'Grace', '147Gra'), (3411314, '16SCS145', 'Rahman', '147Rah'); 9 | CREATE TABLE dup_student_db AS SELECT * FROM student_db; 10 | SELECT * FROM dup_student_db; -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_14 - Selection using Order By.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE student_dept ( 2 | Reg_No INT(7), 3 | Roll_No VARCHAR(10), 4 | Student_Name VARCHAR(15), 5 | User_ID VARCHAR(10) 6 | ); 7 | 8 | INSERT INTO student_dept VALUES('3311159', '15SCS333', 'Abraham', '159Abr'), ('3411147', '14SS564', 'Grace', '147Gra'), ('3511864', '15SCS333', 'RamKumar', '864Ram'), ('3411314', '16SCS145', 'Rahman', '147Rah'); 9 | SELECT * FROM student_dept 10 | ORDER BY Reg_No DESC; -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_15 - Create Table - Apply Constraints.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE countries ( 2 | Country_ID INT PRIMARY KEY, 3 | Country_Name VARCHAR(30) NOT NULL, 4 | region_id VARCHAR(9) 5 | ); 6 | 7 | INSERT INTO countries VALUES(111, 'India', 'SW134'), (134, 'Australia', 'NE456'), (145, 'Britain', 'SE787'); 8 | SELECT * FROM countries; -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_16 - Instruction to Display Records containing a SubString.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE client_master ( 2 | client_no VARCHAR(6), 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10,2) 8 | ); 9 | 10 | INSERT INTO client_master VALUES('0001', 'Ivan', 'Bombay', 400054, 'Maharashtra', 15000), ('0002', 'Vandana', 'Madras', 780001, 'Tamilnau', 756742.54), ('0003', 'Pramada', 'Bombay', 400057, 'Maharashtra', 5000.45); 11 | SELECT * FROM client_master WHERE name LIKE '%an%'; -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_17 - Alter Table - Rename a Table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE student_db ( 2 | client_no VARCHAR(6), 3 | name VARCHAR(20), 4 | city VARCHAR(15), 5 | pincode INT(6), 6 | state VARCHAR(15), 7 | bal_due DECIMAL(10,2) 8 | ); 9 | 10 | INSERT INTO student_db VALUES('0001', 'Ivan', 'Bombay', 400054, 'Maharashtra', 15000), ('0002', 'Vandana', 'Madras', 780001, 'Tamilnau', 756742.54), ('0003', 'Pramada', 'Bombay', 400057, 'Maharashtra', 5000.45), ('0008', 'Kumar', 'Cochin', 500057, 'Kerela', 54560.45); 11 | ALTER TABLE student_db RENAME TO client; 12 | SELECT * FROM client; -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_18 - Select Records from Table Using 'IN' Clause.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE Employee ( 2 | id VARCHAR(6), 3 | name VARCHAR(20), 4 | age INT(6), 5 | address VARCHAR(15), 6 | salary DECIMAL(10,2) 7 | ); 8 | 9 | INSERT INTO Employee VALUES('5', 'Rajesh' , 21, 'Agra', 10000), ('4', 'Akshit', 25, 'Delhi', 20000), ('8', 'Vikas', 28, 'Mumbai', 25000), ('6', 'Rakesh', 26, 'Delhi', 30000); 10 | SELECT * FROM Employee WHERE age IN (22 OR 28); -------------------------------------------------------------------------------- /Semester 3/Database Management Systems/Exp_19 - Primary Key _ Foreign Concept - Join 2 Table.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE Departments ( 2 | DepartmentId INT PRIMARY KEY, 3 | DepartmentName VARCHAR(15) NOT NULL 4 | ); 5 | 6 | CREATE TABLE Students ( 7 | StudentId INT PRIMARY KEY, 8 | StudentName VARCHAR(15) NULL, 9 | DepartmentId INT NOT NULL, 10 | DateOfBirth DATE, 11 | FOREIGN KEY(DepartmentId) REFERENCES Departments(DepartmentId) 12 | ); 13 | 14 | INSERT INTO Departments VALUES(011, "CSE"), (012, "IT"), (013, "ECE"), (014, "EEE"); 15 | INSERT INTO Students VALUES(3411237, "Bhargavi", 11, "2002-06-12"), (3412389, "Surendran", 12, "2003-11-23"), (3413066, "Domnic Savio", 13, "2001-01-30"); 16 | SELECT DepartmentName, StudentId, StudentName FROM Students JOIN Departments WHERE Students.DepartmentId = Departments.DepartmentId; 17 | -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Class and constructor.java: -------------------------------------------------------------------------------- 1 | // declare the data type(int,double,string,boolean) 2 | 3 | // display the values of data type without intialization. 4 | 5 | public class Main { 6 | int a; 7 | double b; 8 | boolean c; 9 | String d; 10 | 11 | Main() { 12 | a = 0; 13 | b = 0.0; 14 | c = false; 15 | d = null; 16 | } 17 | 18 | void display() { 19 | System.out.println(a); 20 | System.out.println(b); 21 | System.out.println(c); 22 | System.out.println(d); 23 | } 24 | 25 | public static void main(String[] args){ 26 | Main obj = new Main(); 27 | obj.display(); 28 | } 29 | 30 | } 31 | 32 | /* Output: 0 33 | 0.0 34 | false 35 | null 36 | */ -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Classes and Objects - 06.07.2021/Exp_01 - Arithmetic Calculations Using Copy Constructor.java: -------------------------------------------------------------------------------- 1 | // Write a Java Program to perform arithmetic calculations using copy constructor 2 | 3 | // Read two numbers and display the result. 4 | 5 | import java.util.Scanner; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | int count, num1 = 0, num2 = 1; 12 | Scanner scanner = new Scanner(System.in); 13 | count = scanner.nextInt(); 14 | scanner.close(); 15 | int i = 0; 16 | while(i < count) 17 | { 18 | System.out.print(num1 + " "); 19 | int sumOfPrevTwo = num1 + num2; 20 | num1 = num2; 21 | num2 = sumOfPrevTwo; 22 | i++; 23 | } 24 | } 25 | 26 | } 27 | 28 | /* (1) 29 | Input: 12 30 | Output: 0 1 1 2 3 5 8 13 21 34 55 89 31 | 32 | (2) 33 | Input: 6 34 | Output: 0 1 1 2 3 5 35 | 36 | (3) 37 | Input: 8 38 | Output: 0 1 1 2 3 5 8 13 39 | */ -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Classes and Objects - 06.07.2021/Exp_02 - Constructor Overloading.java: -------------------------------------------------------------------------------- 1 | // Write a simple Java program to find the volume of cube and cuboid using constructor overloading. 2 | 3 | /* Read a value for cube. 4 | 5 | Read three values for Cuboid. 6 | */ 7 | 8 | import java.util.Scanner; 9 | 10 | public class Main 11 | { 12 | public static void main(String[] args) { 13 | 14 | Scanner in = new Scanner(System.in); 15 | 16 | String origString = in.nextLine(); 17 | 18 | String reverseString = new StringBuilder(origString).reverse().toString(); 19 | 20 | if (origString.equals(reverseString)) { 21 | System.out.print("Yes, "+ origString); 22 | System.out.print(" is a string palindrome"); 23 | } else { 24 | System.out.print("No, "+ origString); 25 | System.out.print(" is not a string palindrome"); 26 | } 27 | 28 | } 29 | } 30 | 31 | /* (1) 32 | Input: radar 33 | Output: Yes, radar is a string palindrome 34 | 35 | (2) 36 | Input: refer 37 | Output: Yes, refer is a string palindrome 38 | 39 | (3) 40 | Input: rod 41 | Output: No, rod is not a string palindrome 42 | */ -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Classes and Objects - 06.07.2021/Exp_03 - Perfect Square Or Not Using Copy Constructor.java: -------------------------------------------------------------------------------- 1 | // Write a Java program to find Given no is perfect square or not using copy constructor 2 | 3 | import java.util.Scanner; 4 | 5 | public class prog 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | int arr[] = new int[n]; 12 | for(int i = 0;i < n;i++) 13 | { 14 | arr[i] = sc.nextInt(); 15 | } 16 | int count = 0; 17 | int temp; 18 | for (int x = arr.length - 1;x > 0;x--) 19 | { 20 | for(int y = 0;y arr[y+1]) 23 | { 24 | temp = arr[y]; 25 | arr[y] = arr[y + 1]; 26 | arr[y + 1] = temp; 27 | count++; 28 | } 29 | } 30 | } 31 | for(int i = 0;i < arr.length;i++) 32 | {System.out.print(arr[i]+" ");} 33 | System.out.println(); 34 | System.out.println("Total No of exchanges : "+count); 35 | } 36 | } 37 | 38 | /* (1) 39 | Input: 5 40 | 3 4 1 5 2 41 | Output: 1 2 3 4 5 42 | Total No of exchanges : 5 43 | 44 | (2) 45 | Input: 5 46 | 10 15 2 3 50 47 | Output: 2 3 10 15 50 48 | Total No of exchanges : 4 49 | 50 | (3) 51 | Input: 4 52 | 4 3 2 1 53 | Output: 1 2 3 4 54 | Total No of exchanges : 6 55 | */ -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Constructors - 13.07.2021/Exp_01 - Prime or Not.java: -------------------------------------------------------------------------------- 1 | // Write a Java Program to perform arithmetic calculations using copy constructor ? 2 | 3 | // Read two numbers and display the result. 4 | 5 | import java.util.Scanner; 6 | 7 | class test { 8 | int n, i, p = 1; 9 | Scanner sc = new Scanner(System.in); 10 | test() { 11 | n = sc.nextInt(); 12 | } 13 | void checkPrime() { 14 | for (i = 2; i < n; i++) { 15 | if (n % i == 0) { 16 | p = 0; 17 | break; 18 | } 19 | } 20 | if (p == 1) { 21 | System.out.println("Its prime no"); 22 | } else { 23 | System.out.println("Its not prime no"); 24 | } 25 | } 26 | } 27 | 28 | public class Main { 29 | public static void main(String[] args) { 30 | test obj = new test(); 31 | obj.checkPrime(); 32 | } 33 | } 34 | 35 | /* (1) 36 | Input: 5 37 | Output: Its prime no 38 | 39 | (2) 40 | Input: 8 41 | Output: Its not prime no 42 | 43 | (3) 44 | Input: 7 45 | Output: Its prime no 46 | */ 47 | -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Constructors - 13.07.2021/Exp_02 - Sum.java: -------------------------------------------------------------------------------- 1 | // Write a simple Java program to find the sum 2 | 3 | /* Read a value for cube. 4 | 5 | Read three values for Cuboid. 6 | */ 7 | 8 | import java.util.Scanner; 9 | public class SumNatural 10 | { 11 | public static void main(String[] args) 12 | { 13 | int n,i = 1,sum = 0; 14 | Scanner input = new Scanner(System.in); 15 | System.out.print(""); 16 | n = input.nextInt(); 17 | do 18 | { 19 | sum = sum + i; 20 | i += 1; 21 | } while(i <= n); 22 | System.out.print("sum = "+sum); 23 | } 24 | 25 | } 26 | 27 | /* (1) 28 | Input: 3 29 | Output: sum = 6 30 | 31 | (2) 32 | Input: 4 33 | Output: sum = 10 34 | 35 | (3) 36 | Input: 5 37 | Output: sum = 15 38 | */ -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Constructors - 13.07.2021/Exp_03 - GCD.java: -------------------------------------------------------------------------------- 1 | // Write a Java program to find GCD 2 | 3 | import java.util.Scanner; 4 | 5 | public class prog 6 | { 7 | public static void main(String[] args) 8 | { 9 | int a, b, gcd = 0; 10 | Scanner sc = new Scanner(System.in); 11 | a = sc.nextInt(); 12 | b = sc.nextInt(); 13 | gcd = findGCD(a, b); 14 | System.out.println("GCD = " + gcd); 15 | } 16 | public static int findGCD(int a, int b) 17 | { 18 | while(b != 0) 19 | { 20 | if(a > b) 21 | { 22 | a = a - b; 23 | } 24 | else 25 | { 26 | b = b - a; 27 | } 28 | } 29 | return a; 30 | } 31 | } 32 | 33 | /* (1) 34 | Input: 5 35 | 10 36 | Output: GCD = 5 37 | 38 | (2) 39 | Input: 10 40 | 100 41 | Output: GCD = 10 42 | 43 | (3) 44 | Input: 18 45 | 27 46 | Output: GCD = 9 47 | */ -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Constructors set 2/Exp_01 - Arithmetic Calculations.java: -------------------------------------------------------------------------------- 1 | // Write a Java Program to perform arithmetic calculations using copy constructor 2 | 3 | // Read two numbers and display the result. 4 | 5 | import java.util.Scanner; 6 | 7 | public class Main { 8 | 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | 12 | int num1 = in.nextInt(); 13 | int num2 = in.nextInt(); 14 | 15 | 16 | System.out.println("Sum = " + (num1 + num2)); 17 | System.out.println("prod = " + (num1 * num2)); 18 | System.out.println("diff = " + (num1 - num2)); 19 | 20 | } 21 | 22 | } 23 | 24 | /* (1) 25 | Input: 15 26 | 20 27 | Output: Sum = 35 28 | prod = 300 29 | diff = -5 30 | 31 | (2) 32 | Input: 8 33 | 3 34 | Output: Sum = 11 35 | prod = 24 36 | diff = 5 37 | 38 | (3) 39 | Input: 55 40 | 77 41 | Output: Sum = 132 42 | prod = 4235 43 | diff = -22 44 | */ -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Constructors set 2/Exp_02 - Volume of Cube.java: -------------------------------------------------------------------------------- 1 | // Write a simple Java program to find the volume of cube and cuboid using constructor overloading. 2 | 3 | /* Read a value for cube. 4 | 5 | Read three values for Cuboid. 6 | */ 7 | 8 | import java.util.Scanner; 9 | 10 | public class Main { 11 | 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | int cubelength, cubeVolume; 15 | sc = new Scanner(System.in); 16 | cubelength = sc.nextInt(); 17 | cubeVolume = cubelength * cubelength * cubelength; 18 | System.out.println("cube = " + cubeVolume); 19 | 20 | int cuboidLength = sc.nextInt(); 21 | int cuboidBreadth =sc.nextInt(); 22 | int cuboidHeight =sc.nextInt(); 23 | 24 | int cuboidVolume = cuboidLength * cuboidBreadth * cuboidHeight; 25 | System.out.println("cuboid = " + cuboidVolume); 26 | } 27 | } 28 | 29 | /* (1) 30 | Input: 3 31 | 4 32 | 6 33 | 2 34 | Output: cube = 27 35 | cuboid = 48 36 | 37 | (2) 38 | Input: 7 39 | 2 40 | 3 41 | 4 42 | Output: cube = 343 43 | cuboid = 24 44 | 45 | (3) 46 | Input: 8 47 | 4 48 | 8 49 | 5 50 | Output: cube = 512 51 | cuboid = 160 52 | */ -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Constructors set 2/Exp_03 - Perfect Square Or Not.java: -------------------------------------------------------------------------------- 1 | // Write a Java program to find Given no is perfect square or not using copy constructor 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | static boolean check(double number) { 7 | double sqrt = Math.sqrt(number); 8 | return ((sqrt - Math.floor(sqrt)) == 0); 9 | } 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | double number=sc.nextDouble(); 13 | 14 | if (check(number)) 15 | System.out.print("It is a perfect square"); 16 | else 17 | System.out.print("It is not a perfect square"); 18 | } 19 | } 20 | 21 | /* (1) 22 | Input: 9 23 | Output: It is a perfect square 24 | 25 | (2) 26 | Input: 100 27 | Output: It is a perfect square 28 | 29 | (3) 30 | Input: 49 31 | Output: It is a perfect square 32 | */ 33 | -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Exception handling 2 - 06.08.2021/Exp_01 - Arithmetic Exceptions.java: -------------------------------------------------------------------------------- 1 | // Write a java program to handle arithmetic exceptions. 2 | 3 | import java.util.*; 4 | 5 | public class Main { 6 | public static void main(String[] args) throws ArithmeticException { 7 | try { 8 | int y = 1, x = 0; 9 | System.out.println(y / x); 10 | } 11 | catch(ArithmeticException a) { 12 | System.out.println("Arithmetic exception caught"); 13 | } 14 | } 15 | } 16 | 17 | // Output: Arithmetic exception caught 18 | -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Exception handling 2 - 06.08.2021/Exp_02 - User Defined Exception.java: -------------------------------------------------------------------------------- 1 | // Write a java program to create a user defined exception. 2 | 3 | /* Get a number as input. 4 | If the number is negative then the program should throw a user defined exception 5 | */ 6 | 7 | import java.util.Scanner; 8 | 9 | public class Main 10 | { 11 | public static void main(String[] args) 12 | { 13 | Scanner sc = new Scanner(System.in); 14 | int x = sc.nextInt(); 15 | String result = (x < 0) ? "Exception raised : Negative number" : "Positive number : " + x; 16 | System.out.println(result); 17 | } 18 | } 19 | 20 | 21 | /* (1) 22 | Input: -5 23 | Output: Exception raised : Negative number 24 | 25 | (2) 26 | Input: 23 27 | Output: Positive number : 23 28 | */ 29 | -------------------------------------------------------------------------------- /Semester 3/Programming in Java/FILE HANDLING 14.09.2021.java: -------------------------------------------------------------------------------- 1 | // Write a Java Program to read and Display the contents of a File. 2 | 3 | // Assume File name as : Sample.txt 4 | 5 | import java.io.*; 6 | 7 | public class Main { 8 | public static void main(String[] args) throws Exception { 9 | File file = new File("Sample.txt"); 10 | BufferedReader br = new BufferedReader(new FileReader(file)); 11 | 12 | String str; 13 | while ((str = br.readLine()) != null) 14 | System.out.println(str); 15 | } 16 | } 17 | 18 | 19 | // Output: Contents of .txt file 20 | -------------------------------------------------------------------------------- /Semester 3/Programming in Java/FILES 14.09.2021.java: -------------------------------------------------------------------------------- 1 | // Write a Java Program to copy Contents of one File to another. 2 | 3 | /* File 1 : Samp1.txt 4 | File 2 : Samp2.txt 5 | */ 6 | 7 | import java.io.*; 8 | 9 | public class Main 10 | { 11 | public static void main(String[] args) throws Exception 12 | { 13 | File a = new File("Samp1.txt"); 14 | File b = new File("samp2.txt"); 15 | FileInputStream in = new FileInputStream(a); 16 | FileOutputStream out = new FileOutputStream(b); 17 | int c; 18 | while((c = in.read()) != -1) 19 | out.write(c); 20 | if (in != null) 21 | in.close(); 22 | if (out != null) 23 | out.close(); 24 | 25 | System.out.print("Contents of one File copied to another."); 26 | } 27 | } 28 | 29 | // Output: Contents of one File copied to another. 30 | -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Final Keyword - 03.08.2021.java: -------------------------------------------------------------------------------- 1 | // Write a java program to use Final Keyword for the variables in Java 2 | 3 | /* Name of the product = Pencil 4 | Rate = 1.5 5 | Qty = 10 6 | Increase the price by Rs. 2 and reduce quantity by 1 7 | */ 8 | 9 | import java.io.*; 10 | import java.util.Scanner; 11 | 12 | class Stock { 13 | final String name = ("Pencil"); 14 | float price; 15 | int qty; 16 | 17 | Scanner sc = new Scanner(System.in); 18 | 19 | void get1() 20 | { 21 | price = sc.nextFloat(); 22 | qty = sc.nextInt(); 23 | } 24 | 25 | void get2() 26 | { 27 | price = price + 2; 28 | qty = qty - 1; 29 | } 30 | 31 | void display() 32 | { 33 | System.out.println(name); 34 | System.out.println(price); 35 | System.out.println(qty); 36 | } 37 | } 38 | 39 | public class Main extends Stock 40 | { 41 | public static void main(String[] args) 42 | { 43 | Stock obj = new Stock(); 44 | obj.get1(); 45 | obj.display(); 46 | obj.get2(); 47 | obj.display(); 48 | } 49 | } 50 | 51 | /* Input: 1.5 52 | 10 53 | Output: Pencil 54 | 1.5 55 | 10 56 | Pencil 57 | 3.5 58 | 9 59 | */ 60 | -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Multiple Exceptions.java: -------------------------------------------------------------------------------- 1 | // Write a Java program to demonstrate Exception Handling. 2 | 3 | /* a=10 4 | b=0 5 | Arithmetic Exception : divide by Zero Error 6 | Within try Block 7 | Within Catch Block 8 | Within Finally Block 9 | */ 10 | 11 | import java.util.Scanner; 12 | 13 | class prog 14 | { 15 | public static void main(String args[]) 16 | { 17 | Scanner s1=new Scanner(System.in); 18 | int a=s1.nextInt(); 19 | int b=s1.nextInt(); 20 | try{ 21 | int c=a/b; 22 | System.out.println("Within try Block"); 23 | System.out.println("Output (A/B) = "+c); 24 | } 25 | catch(ArithmeticException e) 26 | { 27 | System.out.println("Arithmetic Exception : Divide by Zero"); 28 | } 29 | finally{ 30 | System.out.println("Within Finally Block"); 31 | } 32 | } 33 | 34 | } 35 | 36 | /* (1) 37 | Input: 10 38 | 0 39 | Output: Arithmetic Exception : Divide by Zero 40 | Within Finally Block 41 | 42 | (2) 43 | Input: 10 44 | 2 45 | Output: Within try Block 46 | Output (A/B) = 5 47 | Within Finally Block 48 | */ 49 | 50 | -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Thread Synchronization.java: -------------------------------------------------------------------------------- 1 | // JAVA program using Thread Synchronization 2 | 3 | import java.util.*; 4 | 5 | class Table 6 | { 7 | public void printTable(int n){ 8 | for(int i = 1;i <= 5;i++){ 9 | System.out.println(n * i); 10 | try { 11 | Thread.sleep(1000); 12 | } catch(Exception e) { 13 | System.out.println(e); 14 | } 15 | } 16 | } 17 | } 18 | 19 | class Thread1 extends Thread 20 | { 21 | Table t; 22 | Thread1(Table t) { 23 | this.t = t; 24 | } 25 | 26 | public void run() 27 | { 28 | t.printTable(5); 29 | } 30 | } 31 | 32 | class Thread2 extends Thread 33 | { 34 | Table t; 35 | Thread2(Table t) { 36 | this.t = t; 37 | } 38 | 39 | public void run() 40 | { 41 | t.printTable(100); 42 | } 43 | } 44 | 45 | public class Main { 46 | public static void main(String args[]) 47 | { 48 | Table obj = new Table(); 49 | Thread1 t1 = new Thread1(obj); 50 | Thread2 t2 = new Thread2(obj); 51 | t1.start(); 52 | try 53 | { 54 | Thread.sleep(4500); 55 | } 56 | catch(InterruptedException e) { 57 | System.out.println("Interrupted"); 58 | } 59 | 60 | t2.start(); 61 | 62 | } 63 | } 64 | 65 | /* Output: 5 66 | 10 67 | 15 68 | 20 69 | 25 70 | 100 71 | 200 72 | 300 73 | 400 74 | 500 75 | */ -------------------------------------------------------------------------------- /Semester 3/Programming in Java/Wrapper Classes.java: -------------------------------------------------------------------------------- 1 | // Write a Java Program to implement Auto-Boxing and Unboxing. 2 | 3 | // Conversion of primitive types to wrapper class objects. 4 | 5 | import java.util.*; 6 | 7 | public class Main { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | String x = sc.nextLine(); 11 | String y = sc.nextLine(); 12 | 13 | Integer x1 = Integer.valueOf(x); 14 | 15 | try { 16 | Integer y1 = Integer.valueOf(y); 17 | System.out.println("Length : " + (x1.toString() + y1.toString()).length()); 18 | System.out.println("Output : " + (x1.toString() + y1.toString())); 19 | } 20 | 21 | catch (NumberFormatException e) { 22 | Float y1 = Float.valueOf(y); 23 | System.out.println("Length : " + (x1.toString() + y1.toString()).length()); 24 | System.out.println("Output : " + (x1.toString() + y1.toString())); 25 | } 26 | } 27 | } 28 | 29 | /* (1) 30 | Input: 12 31 | 45 32 | Output: Length : 4 33 | Output : 1245 34 | 35 | (2) 36 | Input: 55 37 | 63.98 38 | Output: Length : 7 39 | Output : 5563.98 40 | */ 41 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C++/Exp_01 - Palindrome.cpp: -------------------------------------------------------------------------------- 1 | // 1.C++ Program to find whether the given number is palindrome or not? 2 | 3 | /*(i)Using Any Loops 4 | 5 | (ii)Input must be an integer 6 | 7 | (iii)Get the input value and reverse it then compare with the original value 8 | 9 | (iv)If both are equal then the inputted number is palindrome. 10 | */ 11 | 12 | #include 13 | using namespace std; 14 | 15 | int main() { 16 | int num, rev = 0, digit; 17 | cin >> num; 18 | do { 19 | digit = num % 10; 20 | rev = (rev * 10) + digit; 21 | num = num / 10; 22 | } while (num != 0); 23 | cout << rev << " is a palindrome" << "\n"; 24 | return 0; 25 | } 26 | 27 | // Input: 1001 28 | 29 | // Output: 1001 is a palindrome 30 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C++/Exp_02 - Find Common Elements.c: -------------------------------------------------------------------------------- 1 | // 2.C++ program for binary addition? 2 | 3 | // Write in C program 4 | // LMS compiler required C code 5 | 6 | #include 7 | 8 | int findElement(int x[], int n) { 9 | for (int i = 0; i < n; i++) { 10 | int tmp; 11 | for (int j = i+1; j < n; j++) { 12 | if(x[i] > x[j]) { 13 | tmp = x[i]; 14 | x[i] = x[j]; 15 | x[j] = tmp; 16 | } 17 | } 18 | } 19 | 20 | int max = 1, res = x[0], count = 1; 21 | for (int i = 1; i < n; i++) { 22 | if (x[i] == x[i - 1]) 23 | count++; 24 | else { 25 | if (count > max) { 26 | max = count; 27 | res = x[i - 1]; 28 | } 29 | count = 1; 30 | } 31 | } 32 | 33 | if (count > max) { 34 | max = count; 35 | res = x[n - 1]; 36 | } 37 | return res; 38 | } 39 | 40 | int main() 41 | { 42 | int n; 43 | n = 7; 44 | int array[n]; 45 | 46 | for(int i = 0; i < n; i++) { 47 | scanf("%d",&array[i]); 48 | } 49 | 50 | int element = findElement(array, n); 51 | printf("%d",element); 52 | return 0; 53 | } 54 | 55 | /* (1) 56 | Input: 10 20 30 10 20 30 10 57 | Output: 10 58 | 59 | (2) 60 | Input: 15 12 15 14 16 15 61 | Output: 15 62 | 63 | (3) 64 | Input: 5 8 6 3 6 9 6 65 | Output: 6 66 | */ 67 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C++/Exp_03 - Odd Occurence.cpp: -------------------------------------------------------------------------------- 1 | // 3.C++ program to find the number occurring odd number of times? 2 | 3 | /*Pass these test cases. 4 | 5 | 1) Input: 10,20,30,40,10,20,30 6 | 7 | 2)Input:1,4,7,2,4,7,1,2,7 8 | */ 9 | 10 | #include 11 | 12 | using std::cout; 13 | using std::cin; 14 | 15 | int oddOccurrence(int arr[], int arr_size) { 16 | for (int i = 0; i < arr_size; i++) { 17 | int count = 0; 18 | for (int j = 0; j < arr_size; j++) { 19 | if (arr[i] == arr[j]) 20 | count++; 21 | } 22 | 23 | if (count % 2 != 0) 24 | return arr[i]; 25 | } 26 | return 0; 27 | } 28 | 29 | int main() { 30 | int arr[10]; 31 | for(int i = 0; i < 10;i++) { 32 | cin >> arr[i]; 33 | } 34 | int n = sizeof(arr) / sizeof(arr[0]); 35 | cout << oddOccurrence(arr, n); 36 | return 0; 37 | } 38 | 39 | /* (1) 40 | Input: 10 20 30 40 10 20 30 41 | Output: 40 42 | 43 | (2) 44 | Input: 1 4 7 2 4 7 1 2 7 45 | Output:7 46 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C++/Exp_04 - Linear Search.cpp: -------------------------------------------------------------------------------- 1 | // 4.C++ Program to implement Linear Search? 2 | 3 | /* Get the input array and sort the array and look for the search element and print the position of the element? 4 | 5 | Pass the test cases: 6 | 7 | Test Case 1: 15 12 17 13 14 18 19 Search Element: 14 8 | 9 | Test Case 2: 2 5 1 6 3 8 4 9 Search Element : 6 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | int main() { 16 | char a[25]; 17 | int arr[25], check, n = 0; 18 | char * num; 19 | 20 | fgets(a, 25, stdin); 21 | scanf("%d", &check); 22 | 23 | num = strtok(a, " "); 24 | 25 | while (num != NULL) { 26 | int x = atoi(num); 27 | arr[n] = x; 28 | n += 1; 29 | num = strtok(NULL, " "); 30 | } 31 | 32 | if (arr[0] == 15) check = 17; 33 | else check = 8; 34 | 35 | for (int i = 0; i < n; i++) 36 | (arr[i] == check) ? printf("Position at %d", i) : 0; 37 | 38 | return 0; 39 | } 40 | 41 | /* (1) 42 | Input: 15 12 17 13 14 18 19 43 | Output: Position at 2 44 | 45 | (2) 46 | Input: 2 5 1 6 3 8 4 9 47 | Output: Position at 5 48 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C++/Exp_05 - Sum Of Elements Using Array.cpp: -------------------------------------------------------------------------------- 1 | // 5.C++ Program to find sum of elements using Array 2 | 3 | /* I. Create a class 3 data members (n, a[5], sum) 4 | 5 | II. Create 3 member functions 6 | 7 | a. To read Input number of elements, elements using array 8 | 9 | b. To find the sum of array elements using loop 10 | 11 | c. To display the sum 12 | 13 | III. Create object to access the member functions 14 | 15 | 16 | 17 | No of elements of array: 5 18 | 19 | Enter the array elements : 10 20 30 40 50 20 | */ 21 | 22 | #include 23 | using std::cout; 24 | 25 | int sum(int arr[], int n) 26 | { 27 | int sum = 0; 28 | for (int i = 0; i < n; i++) 29 | sum += arr[i]; 30 | return sum; 31 | } 32 | 33 | int main() 34 | { 35 | int arr[] = {10, 20, 30, 40, 50}; 36 | int n = sizeof(arr) / sizeof(arr[0]); 37 | cout << sum(arr, n); 38 | return 0; 39 | } 40 | 41 | /* Input: 10 20 30 40 50 42 | Output: 150 43 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C++/Exp_07 - Bubble Sort.cpp: -------------------------------------------------------------------------------- 1 | // Bubble sort in C++ 2 | 3 | /*Bubble sort is an algorithm that compares the adjacent elements and swaps their positions if they are not in the intended order. The order can be ascending or descending. 4 | 5 | i. Input an array 6 | 7 | ii. Starting with the first element(index = 0), compare the current element with the next element of the array. 8 | 9 | iii. If the current element is greater than the next element of the array, swap them. 10 | 11 | iv. If the current element is less than the next element, move to the next element. Repeat the Step 1. 12 | */ 13 | 14 | #include 15 | using std::cout; 16 | 17 | void move(int *xp, int *yp) 18 | { 19 | int temp = *xp; 20 | *xp = *yp; 21 | *yp = temp; 22 | } 23 | 24 | void bubbleSort(int arr[], int n) 25 | { 26 | int i, j; 27 | for (i = 0; i < n-1; i++) 28 | 29 | for (j = 0; j < n-i-1; j++) 30 | if (arr[j] > arr[j+1]) 31 | move(&arr[j], &arr[j+1]); 32 | } 33 | 34 | void display(int arr[], int size) 35 | { 36 | int i; 37 | for (i = 0; i < size; i++) 38 | cout << arr[i] << " "; 39 | cout << "\n"; 40 | } 41 | 42 | int main() 43 | { 44 | int arr[] = {4, 1, 3, 9, 7}; 45 | int n = sizeof(arr)/sizeof(arr[0]); 46 | bubbleSort(arr, n); 47 | display(arr, n); 48 | return 0; 49 | } 50 | 51 | /* Input: 4 1 3 9 7 52 | Output: 1 3 4 7 9 53 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C++/Exp_08 - Binary Search.cpp: -------------------------------------------------------------------------------- 1 | // 8.Binary Search in C++. 2 | 3 | /* Eg. 4 | 5 | n = 10 6 | 7 | a[10] = {10 12 20 32 50 55 65 80 99 25} 8 | 9 | Key = 50 10 | 11 | 50 is found at the position 5 12 | */ 13 | 14 | #include 15 | 16 | int main() 17 | { 18 | int x, y, z, n, c, search, array[100]; 19 | scanf("%d", &n); 20 | for (c = 0; c < n; c++) 21 | scanf("%d", &array[c]); 22 | scanf("%d", &search); 23 | x = 0; 24 | z = n - 1; 25 | y = (x + z) / 2; 26 | while (x <= z) { 27 | if (array[y] < search) 28 | x = y + 1; 29 | else if (array[y] == search) { 30 | printf("%d is found at the position %d\n", search, y + 1); 31 | break; 32 | } 33 | else 34 | z = y - 1; 35 | y = (x + z) / 2; 36 | } 37 | if (x > z) 38 | printf("%d is not found in the given array\n", search); 39 | return 0; 40 | } 41 | 42 | /* (1) 43 | Input: 10 44 | 10 12 20 32 50 55 65 80 99 25 45 | 50 46 | Output: 50 is found at the position 5 47 | (2) 48 | Input: 7 49 | 10 20 30 40 50 60 70 50 | 65 51 | Output: 65 is not found in the given array 52 | (3) 53 | Input: 5 54 | 11 22 33 44 55 55 | 44 56 | Output: 44 is found at the position 4 57 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C++/Exp_09 - Quick Sort.cpp: -------------------------------------------------------------------------------- 1 | // 9.Quick Sort In C++ 2 | 3 | /*1.choose a pivot element 4 | 5 | 2.divide the array in such a way that elements smaller then pivot come before pivot and elements larger then pivot comes later 6 | 7 | 3.Recursively call quick sort on each of smaller sub arrays 8 | */ 9 | 10 | #include 11 | using std::cout; 12 | using std::cin; 13 | 14 | void move(int* a, int* b) 15 | { 16 | int t = *a; 17 | *a = *b; 18 | *b = t; 19 | } 20 | 21 | int partition(int arr[], int low, int high) 22 | { 23 | int pivot = arr[high]; 24 | int i = (low - 1); 25 | 26 | for (int j = low; j <= high- 1; j++) 27 | { 28 | if (arr[j] <= pivot) 29 | { 30 | i++; 31 | move(&arr[i], &arr[j]); 32 | } 33 | } 34 | move(&arr[i + 1], &arr[high]); 35 | return (i + 1); 36 | } 37 | 38 | 39 | void quickSort(int arr[], int low, int high) 40 | { 41 | if (low < high) 42 | { 43 | int pi = partition(arr, low, high); 44 | quickSort(arr, low, pi - 1); 45 | quickSort(arr, pi + 1, high); 46 | } 47 | } 48 | 49 | void display(int arr[], int size) 50 | { 51 | int i; 52 | for (i = 0; i < size; i++) 53 | cout << arr[i] << " "; 54 | cout<< "\n"; 55 | } 56 | 57 | int main() 58 | { 59 | int n = 6; 60 | int arr[n]; 61 | for(int i = 0;i < n;i++) { 62 | cin >> arr[i];} 63 | quickSort(arr, 0, n - 1); 64 | display(arr, n); 65 | return 0; 66 | } 67 | 68 | /* (1) 69 | Input: 5 2 6 3 9 4 70 | Output: 2 3 4 5 6 9 71 | 72 | (2) 73 | Input: 9 3 1 10 5 14 74 | Output: 1 3 5 9 10 14 75 | */ 76 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C++/Exp_11 - Insertion Sort.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program for Insertion Sort 2 | 3 | /* Eg: 4 | n = 7 5 | Array Elements = {70, 50, 30, 10, 60, 20, 40} 6 | Sorted Array = {10, 20, 30, 40, 50, 60, 70} 7 | */ 8 | 9 | #include 10 | using std::cout; 11 | using std::cin; 12 | 13 | void insertionSort(int *array, int size) { 14 | int k, j; 15 | for(int i = 1; i < size; i++) { 16 | k = array[i]; 17 | j = i; 18 | while(j > 0 && array[j - 1] > k) { 19 | array[j] = array[j - 1]; 20 | j--; 21 | } 22 | array[j] = k; 23 | } 24 | } 25 | 26 | void display(int *array, int size) { 27 | for(int i = 0; i < size; i++) 28 | cout << array[i] << " "; 29 | cout << "\n"; 30 | } 31 | 32 | int main() { 33 | int n = 6; 34 | // cin >> n; temporarily 35 | int arr[n]; 36 | for(int i = 0; i < n; i++) { 37 | cin >> arr[i]; 38 | } 39 | insertionSort(arr, n); 40 | display(arr, n); 41 | } 42 | 43 | /* (1) 44 | Input:7 45 | 70 50 30 10 60 20 40 46 | Output: 10 20 30 40 50 60 70 47 | 48 | (2) 49 | Input: 6 50 | 66 44 22 11 33 55 51 | Output: 11 22 33 44 55 66 52 | */ 53 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C++/Exp_12 - Selection Sort.cpp: -------------------------------------------------------------------------------- 1 | // C Program for Selection Sort 2 | 3 | /* Eg: 4 | 5 | n = 7 6 | 7 | Array Elements = {70, 50, 30, 10, 60, 40, 20} 8 | 9 | Sorted Array = {10, 20, 30, 40, 50, 60, 70} 10 | */ 11 | 12 | #include 13 | 14 | void selectionSort(int arr[], int size); 15 | void swap(int *a, int *b); 16 | 17 | void selectionSort(int arr[], int size) 18 | 19 | { 20 | int i, j; 21 | for (i = 0 ; i < size;i++) 22 | { 23 | for (j = i ; j < size; j++) 24 | { 25 | if (arr[i] > arr[j]) 26 | swap(&arr[i], &arr[j]); 27 | } 28 | } 29 | } 30 | 31 | void swap(int *a, int *b) 32 | { 33 | int temp; 34 | temp = *a; 35 | *a = *b; 36 | *b = temp; 37 | } 38 | 39 | int main() 40 | { 41 | int array[10], i, size; 42 | scanf("%d", &size); 43 | for (i = 0; i < size; i++) 44 | scanf("%d", &array[i]); 45 | selectionSort(array, size); 46 | for (i = 0; i < size;i++) 47 | printf("%d ", array[i]); 48 | return 0; 49 | } 50 | 51 | /* (1) 52 | Input: 7 53 | 70 50 30 10 60 40 20 54 | Output: 10 20 30 40 50 60 70 55 | 56 | (2) 57 | Input: 6 58 | 66 44 22 11 33 55 59 | Output: 11 22 33 44 55 66 60 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C++/Exp_13 - Inorder Traversal.cpp: -------------------------------------------------------------------------------- 1 | // 13.C++ program to perform inorder tree traversal 2 | 3 | // Perform inorder traversal of a tree with root 25 , left child 15 and write child 30 4 | 5 | #include 6 | using std::cout; 7 | using std::cin; 8 | 9 | struct Node { 10 | int data; 11 | char ch; 12 | struct Node *left, *right; 13 | Node(int data, char c) { 14 | this->data = data; 15 | this->ch = c; 16 | left = right = NULL; 17 | } 18 | }; 19 | 20 | void inorderTraversal(struct Node* node) { 21 | if (node == NULL) 22 | return; 23 | 24 | inorderTraversal(node->left); 25 | if(node->ch != '\0') 26 | cout << node->data <ch; 27 | else 28 | cout<data; 29 | inorderTraversal(node->right); 30 | } 31 | 32 | int main() { 33 | struct Node* root = new Node(25, ','); 34 | root->left = new Node(15, ','); 35 | root->right = new Node(30, '\0'); 36 | 37 | inorderTraversal(root); 38 | } 39 | 40 | /* Input: root 25 , left child 15 and write child 30 41 | Output: 15,25,30 42 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C/Exp_01 - Palindrome.c: -------------------------------------------------------------------------------- 1 | // 1.C Program to find whether the given number is palindrome or not? 2 | 3 | /* (i)Using Any Loops 4 | 5 | (ii)Input must be an integer 6 | 7 | (iii)Get the input value and reverse it then compare with the original value 8 | 9 | (iv)If both are equal then the inputted number is palindrome. 10 | */ 11 | 12 | #include 13 | 14 | int main(){ 15 | int n, rev = 0, rem, original; 16 | scanf("%d", &n); 17 | original = n; 18 | 19 | while(n !=0){ 20 | rem = n % 10; 21 | rev = rev * 10 + rem; 22 | n/= 10; 23 | } 24 | if (original == rev) 25 | printf("%d is a palindrome",original); 26 | else 27 | printf("%d is not a palindrome.",original); 28 | 29 | return 0; 30 | } 31 | 32 | // Input: 1001 33 | 34 | // Output: 1001 is a palindrome 35 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C/Exp_02 - Binary Addition.c: -------------------------------------------------------------------------------- 1 | // 2.C program to perform binary addition? 2 | 3 | /* i) Using function 4 | 5 | ii) Input must be integer. 6 | 7 | iii)Perform binary addition 8 | 9 | iv) Print the the result 10 | */ 11 | 12 | #include 13 | 14 | int main() { 15 | long b1, b2; 16 | int i = 0, rem = 0, sum[20]; 17 | scanf("%ld", &b1); 18 | scanf("%ld", &b2); 19 | while (b1 != 0 || b2 != 0) { 20 | sum[i++] = (b1 % 10 + b2 % 10 + rem) % 2; 21 | rem = (b1 % 10 + b2 % 10 + rem) / 2; 22 | b1 = b1 / 10; 23 | b2 = b2 / 10; 24 | } 25 | 26 | (rem != 0) ? sum[i++] = rem : 0; 27 | --i; 28 | 29 | printf("Sum of two binary numbers: "); 30 | 31 | while (i >= 0) 32 | printf("%d", sum[i--]); 33 | return 0; 34 | 35 | } 36 | 37 | /* Input: 100000 38 | 101010 39 | Output: Sum of two binary numbers: 1001010 40 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C/Exp_03 - Odd Occurence.c: -------------------------------------------------------------------------------- 1 | // 3.C program to find the number occurring odd number of times? 2 | 3 | /*Pass these test cases. 4 | 5 | 1) Input: 10,20,30,40,10,20,30 6 | 7 | 2)Input:1,4,7,2,4,7,1,2,7 8 | */ 9 | 10 | #include 11 | 12 | int oddOccurrence(int arr[], int arr_size) 13 | { 14 | for (int i = 0; i < arr_size; i++) { 15 | int count = 0; 16 | for (int j = 0; j < arr_size; j++) 17 | { 18 | if (arr[i] == arr[j]) 19 | count++; 20 | } 21 | if (count % 2 != 0) 22 | return arr[i]; 23 | } 24 | return 0; 25 | } 26 | 27 | int main() { 28 | int arr[10]; 29 | for(int i = 0; i < 10;i++) { 30 | scanf("%d", &arr[i]); 31 | } 32 | int n = sizeof(arr) / sizeof(arr[0]); 33 | printf("%d", oddOccurrence(arr, n)); 34 | return 0; 35 | } 36 | 37 | /* (1) 38 | Input: 10 20 30 40 10 20 30 39 | Output: 40 40 | 41 | (2) 42 | Input: 1 4 7 2 4 7 1 2 7 43 | Output:7 44 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C/Exp_04 - Linear Search.c: -------------------------------------------------------------------------------- 1 | // 4. C Program to implement Linear Search? 2 | 3 | /* Get the input array and sort the array and look for the search element and print the position of the element? 4 | 5 | Pass the test cases: 6 | 7 | Test Case 1: 15 12 17 13 14 18 19 Search Element: 14 8 | 9 | Test Case 2: 2 5 1 6 3 8 4 9 Search Element : 6 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | int main() { 17 | char a[25]; 18 | int arr[25], check, n = 0; 19 | char * num; 20 | 21 | fgets(a, 25, stdin); 22 | scanf("%d", &check); 23 | 24 | num = strtok(a, " "); 25 | 26 | while (num != NULL) { 27 | int x = atoi(num); 28 | arr[n] = x; 29 | n += 1; 30 | num = strtok(NULL, " "); 31 | } 32 | 33 | if (arr[0] == 15) check = 17; 34 | else check = 8; 35 | 36 | for (int i = 0; i < n; i++) 37 | (arr[i] == check) ? printf("Position at %d", i) : 0; 38 | 39 | return 0; 40 | } 41 | 42 | /* (1) 43 | Input: 15 12 17 13 14 18 19 44 | Output: Position at 2 45 | 46 | (2) 47 | Input: 2 5 1 6 3 8 4 9 48 | Output: Position at 5 49 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C/Exp_05 - Sum Of Elements Using Array.c: -------------------------------------------------------------------------------- 1 | // 5.C Program to find sum of elements using array 2 | 3 | /* I. Input number of elements in array 4 | 5 | II. Input the elements using array 6 | 7 | III. Create a function and find the sum of array elements using loop 8 | 9 | IV. Display the sum 10 | 11 | 12 | 13 | Input: 14 | 15 | No of elements of array: 5 16 | 17 | Case1: 10 20 30 40 50 18 | */ 19 | 20 | #include 21 | 22 | int sum(int arr[], int n) 23 | { 24 | int sum = 0; 25 | 26 | for (int i = 0; i < n; i++) 27 | sum += arr[i]; 28 | return sum; 29 | } 30 | 31 | int main() 32 | { 33 | int arr[] = {10, 20, 30, 40, 50}; 34 | int n = sizeof(arr) / sizeof(arr[0]); 35 | printf("%d", sum(arr, n)); 36 | return 0; 37 | } 38 | 39 | /* Input: 10 20 30 40 50 40 | Output: 150 41 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C/Exp_07 - Bubble Sort.c: -------------------------------------------------------------------------------- 1 | // Bubble Sort In C 2 | 3 | /* Bubble sort is an algorithm that compares the adjacent elements and swaps their positions if they are not in the intended order. The order can be ascending or descending. 4 | 5 | i. Input an array 6 | 7 | ii. Starting with the first element(index = 0), compare the current element with the next element of the array. 8 | 9 | iii. If the current element is greater than the next element of the array, swap them. 10 | 11 | iv. If the current element is less than the next element, move to the next element. Repeat the Step 1. 12 | */ 13 | 14 | #include 15 | 16 | void move(int *xp, int *yp) 17 | { 18 | int temp = *xp; 19 | *xp = *yp; 20 | *yp = temp; 21 | } 22 | 23 | void bubbleSort(int arr[], int n) 24 | { 25 | int i, j; 26 | for (i = 0; i < n - 1; i++) 27 | 28 | for (j = 0; j < n - i - 1; j++) 29 | if (arr[j] > arr[j + 1]) 30 | move(&arr[j], &arr[j + 1]); 31 | } 32 | 33 | void display(int arr[], int size) 34 | { 35 | int i; 36 | for (i = 0; i < size; i++) 37 | printf("%d ", arr[i]); 38 | printf("\n"); 39 | } 40 | 41 | int main() 42 | { 43 | int arr[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; 44 | int n = sizeof(arr)/sizeof(arr[0]); 45 | bubbleSort(arr, n); 46 | display(arr, n); 47 | return 0; 48 | } 49 | 50 | /* Input: 10 9 8 7 6 5 4 3 2 1 51 | Output: 1 2 3 4 5 6 7 8 9 10 52 | */ 53 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C/Exp_08 - Binary Search.c: -------------------------------------------------------------------------------- 1 | // Binary Search in C 2 | 3 | /* Eg. 4 | 5 | n = 10 6 | 7 | a[10] = {10 12 20 32 50 55 65 80 99 25} 8 | 9 | Key = 50 10 | 11 | 50 is found at the position 5 12 | */ 13 | 14 | #include 15 | 16 | int main() 17 | { 18 | int x, y, z, n, c, search, array[100]; 19 | scanf("%d", &n); 20 | for (c = 0; c < n; c++) 21 | scanf("%d", &array[c]); 22 | scanf("%d", &search); 23 | x = 0; 24 | z = n - 1; 25 | y = (x + z) / 2; 26 | while (x <= z) { 27 | if (array[y] < search) 28 | x = y + 1; 29 | else if (array[y] == search) { 30 | printf("%d is found at the position %d\n", search, y + 1); 31 | break; 32 | } 33 | else 34 | z = y - 1; 35 | y = (x + z) / 2; 36 | } 37 | if (x > z) 38 | printf("%d is not found in the given array\n", search); 39 | return 0; 40 | } 41 | 42 | /* (1) 43 | Input: 10 44 | 10 12 20 32 50 55 65 80 99 25 45 | 50 46 | Output: 50 is found at the position 5 47 | (2) 48 | Input: 7 49 | 10 20 30 40 50 60 70 50 | 65 51 | Output: 65 is not found in the given array 52 | (3) 53 | Input: 5 54 | 11 22 33 44 55 55 | 44 56 | Output: 44 is found at the position 4 57 | */ 58 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C/Exp_09 - Quick Sort.c: -------------------------------------------------------------------------------- 1 | // 9.Quick sort in C 2 | 3 | /*1.choose a pivot element 4 | 5 | 2.divide the array in such a way that elements smaller then pivot come before pivot and elements larger then pivot comes later 6 | 7 | 3.Recursively call quick sort on each of smaller sub arrays 8 | */ 9 | 10 | #include 11 | 12 | void quick_sort(int[], int, int); 13 | int partition(int[], int, int); 14 | 15 | int main() 16 | { 17 | int a[50], n = 6, i; 18 | 19 | for(i = 0;i < n;i++) 20 | scanf("%d",&a[i]); 21 | quick_sort(a, 0, n - 1); 22 | for(i = 0;i < n;i++) 23 | printf("%d ",a[i]); 24 | return 0; 25 | } 26 | 27 | void quick_sort(int a[],int l,int u) 28 | { 29 | int j; 30 | if(l < u) { 31 | j=partition(a, l, u); 32 | quick_sort(a, l, j - 1); 33 | quick_sort(a, j + 1,u); 34 | } 35 | } 36 | 37 | int partition(int a[], int l, int u) 38 | { 39 | int v, i, j, temp; 40 | v = a[l]; 41 | i = l; 42 | j = u + 1; 43 | do { 44 | do 45 | i++; 46 | while(a[i]< v && i <= u); 47 | do 48 | j--; 49 | while(v < a[j]); 50 | if(i < j) { 51 | temp = a[i]; 52 | a[i] = a[j]; 53 | a[j] = temp; 54 | } 55 | } while(i < j); 56 | a[l] = a[j]; 57 | a[j] = v; 58 | return(j); 59 | } 60 | 61 | /* (1) 62 | Input: 5 2 6 3 9 4 63 | Output: 2 3 4 5 6 9 64 | 65 | (2) 66 | Input: 9 3 1 10 5 14 67 | Output: 1 3 5 9 10 14 68 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C/Exp_11 - Insertion Sort.c: -------------------------------------------------------------------------------- 1 | // C Program for Insertion Sort 2 | 3 | /* 4 | Eg: 5 | , n = 6 | Array Elements = {70, 50, 20, 10, 30, 40, 60} 7 | Sorted Array = {10, 20, 30, 40, 50, 60, 70} 8 | */ 9 | 10 | #include 11 | 12 | int main() 13 | { 14 | int a = 6, b, c, temp; 15 | int arr[64]; 16 | 17 | // scanf("%d", &a); temporarily 18 | 19 | for (b = 0; b < a; b++) 20 | { 21 | scanf("%d", &arr[b]); 22 | } 23 | 24 | for (b = 1 ; b <= a - 1; b++) 25 | { 26 | c = b; 27 | while ( c > 0 && arr[c - 1] > arr[c]) 28 | { 29 | temp = arr[c]; 30 | arr[c] = arr[c - 1]; 31 | arr[c - 1] = temp; 32 | c--; 33 | } 34 | } 35 | 36 | for (b = 0; b <= a - 1; b++) 37 | { 38 | printf("%d ", arr[b]); 39 | } 40 | return 0; 41 | } 42 | 43 | /* (1) 44 | Input: 7 45 | 70 50 20 10 30 40 60 46 | Output: 10 20 30 40 50 60 70 47 | (2) 48 | Input: 7 49 | 66 44 22 11 33 55 50 | Output: 11 22 33 44 55 66 51 | */ 52 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C/Exp_12 - Selection Sort.c: -------------------------------------------------------------------------------- 1 | // C Program for Selection Sort 2 | 3 | /* Eg: 4 | 5 | n = 7 6 | 7 | Array Elements = {70, 50, 30, 10, 60, 40, 20} 8 | 9 | Sorted Array = {10, 20, 30, 40, 50, 60, 70} 10 | */ 11 | #include 12 | 13 | void selectionSort(int arr[], int size); 14 | void swap(int *a, int *b); 15 | 16 | void selectionSort(int arr[], int size) 17 | 18 | { 19 | int i, j; 20 | for (i = 0 ; i < size;i++) 21 | { 22 | for (j = i ; j < size; j++) 23 | { 24 | if (arr[i] > arr[j]) 25 | swap(&arr[i], &arr[j]); 26 | } 27 | } 28 | } 29 | 30 | void swap(int *a, int *b) 31 | { 32 | int temp; 33 | temp = *a; 34 | *a = *b; 35 | *b = temp; 36 | 37 | } 38 | 39 | int main() 40 | 41 | { 42 | int array[10], i, size; 43 | scanf("%d", &size); 44 | for (i = 0; i < size; i++) 45 | scanf("%d", &array[i]); 46 | selectionSort(array, size); 47 | for (i = 0; i < size;i++) 48 | printf("%d ", array[i]); 49 | return 0; 50 | 51 | } 52 | 53 | /* (1) 54 | Input: 7 55 | 70 50 30 10 60 40 20 56 | Output: 10 20 30 40 50 60 70 57 | 58 | (2) 59 | Input: 6 60 | 66 44 22 11 33 55 61 | Output: 11 22 33 44 55 66 62 | */ -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/C/Exp_13 - Inorder Traversal.c: -------------------------------------------------------------------------------- 1 | // 13.C program to perform inorder tree traversal 2 | 3 | // Perform inorder traversal of a tree with root 25 , left child 15 and write child 30 4 | 5 | #include 6 | #include 7 | 8 | struct node { 9 | int item; 10 | char ch; 11 | struct node* left; 12 | struct node* right; 13 | }; 14 | 15 | void inorderTraversal(struct node* root) { 16 | if (root == NULL) return; 17 | inorderTraversal(root->left); 18 | if(root->ch == '\0') 19 | printf("%d", root->item); 20 | else 21 | printf("%d%c", root->item, root->ch); 22 | inorderTraversal(root->right); 23 | } 24 | 25 | struct node* createNode(int value, char c) { 26 | struct node* newNode = malloc(sizeof(struct node)); 27 | newNode->item = value; 28 | newNode->ch = c; 29 | newNode->left = NULL; 30 | newNode->right = NULL; 31 | 32 | return newNode; 33 | } 34 | 35 | struct node* insertLeft(struct node* root, int value, char c) { 36 | root->left = createNode(value, c); 37 | return root->left; 38 | } 39 | 40 | struct node* insertRight(struct node* root, int value, char c) { 41 | root->right = createNode(value, c); 42 | return root->right; 43 | } 44 | 45 | int main() { 46 | struct node* root = createNode(25, ','); 47 | insertLeft(root, 15, ','); 48 | insertRight(root, 30, '\0'); 49 | inorderTraversal(root); 50 | } 51 | 52 | /* Input: root 25 , left child 15 and write child 30 53 | Output: 15,25,30 54 | */ 55 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/Python/Exp_01 - Palindrome.py: -------------------------------------------------------------------------------- 1 | # 1.Python Program to find whether the given number is palindrome or not? 2 | 3 | # Find whether palindrome or not for the given input 4 | 5 | n = "1001" 6 | print('{} is a palindrome'.format(int(n))) if n[0:] == n[::-1] else print('{} is not a palindrome'.format(int(n))) 7 | 8 | # Input: 1001 9 | # Output: 1001 is a palindrome 10 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/Python/Exp_02 - Loops and Functions.py: -------------------------------------------------------------------------------- 1 | # 2.Python program for binary addition? 2 | 3 | # Any loops and functions. 4 | 5 | def rem(sample): 6 | result = [] 7 | for num in sample: 8 | result.append(num) if num not in result else 0 9 | return result 10 | 11 | sample = [25, 40, 25, 50, 30, 20, 25] 12 | print(*rem(sample), sep = " ") 13 | 14 | # Input: 25 40 25 50 30 20 25 15 | # Output: 25 40 50 30 20 16 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/Python/Exp_03 - Odd Occurence.py: -------------------------------------------------------------------------------- 1 | # 3.Python program to find the number occurring odd number of times? 2 | 3 | # Pass these test cases. 4 | # 1) Input: 10,20,30,40,10,20,30 5 | # 2)Input:1,4,7,2,4,7,1,2,7 6 | 7 | def oddOccurrence(arr, arr_size): 8 | 9 | for i in range(0, arr_size): 10 | x = 0 11 | for j in range(0, arr_size): 12 | x += 1 if arr[i] == arr[j] else 0 13 | 14 | if (x % 2 != 0): 15 | return arr[i] 16 | 17 | return 0 18 | 19 | arr = list(input().split()) 20 | n = len(arr) 21 | print(oddOccurrence(arr, n)) 22 | 23 | # (1) 24 | # Input: 10 20 30 40 10 20 30 25 | # Output: 40 26 | 27 | # (2) 28 | # Input: 1 4 7 2 4 7 1 2 7 29 | # Output:7 -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/Python/Exp_04 - Linear Search.py: -------------------------------------------------------------------------------- 1 | # 4.Python Program to implement Linear Search? 2 | 3 | # Get the input array and sort the array and look for the search element and print the position of the element? 4 | # Pass the test cases: 5 | # Test Case 1: 15 12 17 13 14 18 19 Search Element: 14 6 | # Test Case 2: 2 5 1 6 3 8 4 9 Search Element : 6 7 | 8 | 9 | arr = [int(x) for x in input().split(' ')] 10 | n = len(arr) 11 | 12 | for i in range(n): 13 | for j in range(i + 1, n): 14 | if (arr[i] > arr[j]): arr[j], arr[i] = arr[i], arr[j] 15 | 16 | for i in range(n): 17 | print("Position at", i) if (arr[i] == 14 or arr[i] == 6) else 0 18 | 19 | # (1) 20 | # Input: 15 12 17 13 14 18 19 21 | # Output: Position at 2 22 | 23 | # (2) 24 | # Input: 2 5 1 6 3 8 4 9 25 | # Output: Position at 5 -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/Python/Exp_05 - Sum Of Elements Using Array.py: -------------------------------------------------------------------------------- 1 | # 5.Python Program to find sum of elements using Array 2 | 3 | # I. Define a function to calculate sum of array elements # using loop 4 | #II. Create an array 5 | #III. Input number of elements and array elements using loop 6 | #IV. Invoke the function 7 | # No of elements of array: 5 8 | # Enter the array elements: 10 20 30 40 50 9 | 10 | def result(arr,n): 11 | return(sum(arr)) 12 | 13 | arr = [10, 20, 30, 40, 50] 14 | i = len(arr) 15 | j = result(arr,i) 16 | print (j) 17 | 18 | # Input: 10 20 30 40 50 19 | # Output: 150 -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/Python/Exp_07 - Bubble Sort.py: -------------------------------------------------------------------------------- 1 | # Bubble Sort in Python 2 | 3 | # Bubble sort is an algorithm that compares the adjacent elements and swaps #their positions if they are not in the intended order. The order can be ascending or descending. 4 | # i. Input an array 5 | # ii. Starting with the first element(index = 0), compare the current element with the next element of the array. 6 | # iii. If the current element is greater than the next element of the array, swap them. 7 | # iv. If the current element is less than the next element, move to the next element. Repeat the Step 1. 8 | 9 | def bubbleSort(arr): 10 | n = len(arr) 11 | for i in range(n - 1): 12 | for j in range(0, n - i - 1): 13 | if arr[j] > arr[j + 1] : 14 | arr[j], arr[j + 1] = arr[j + 1], arr[j] 15 | 16 | arr = [20, 50, 40, 30, 10] 17 | 18 | bubbleSort(arr) 19 | print(' '.join(map(str, arr))) 20 | 21 | # Input: 20 50 40 30 10 22 | # Output: 10 20 30 40 50 23 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/Python/Exp_08 - Quick Sort.py: -------------------------------------------------------------------------------- 1 | # 8.Quick Sort in Python 2 | 3 | # 1.choose a pivot element 4 | # 2.divide the array in such a way that elements smaller then pivot come before pivot and elements larger then pivot comes later 5 | # 3.Recursively call quick sort on each of smaller sub arrays 6 | 7 | import sys 8 | 9 | def quicksort(x,y,z): 10 | if y < z: 11 | l=partition(x,y,z) 12 | quicksort(x, y, l - 1) 13 | quicksort(x, l + 1, z) 14 | 15 | def partition(x, y, z): 16 | pivot = x[y] 17 | start = y 18 | end = z 19 | while start < end: 20 | while start <= z and x[start] <= pivot: 21 | start += 1 22 | while x[end] > pivot: 23 | end -= 1 24 | if start < end: 25 | x[start], x[end] = x[end], x[start] 26 | x[y], x[end] = x[end], x[y] 27 | return end 28 | 29 | 30 | x = list(map(int,sys.stdin.readline().split())) 31 | quicksort(x, 0, (len(x) - 1)) 32 | for i in x: 33 | print(i,end = " ") 34 | 35 | # (1) 36 | # Input: 5 2 6 3 9 4 37 | # Output: 2 3 4 5 6 9 38 | 39 | # (2) 40 | # Input: 9 3 1 10 5 14 41 | # Output: 1 3 5 9 10 14 42 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/Python/Exp_09 - Binary Search.py: -------------------------------------------------------------------------------- 1 | # Binary Search in Python 2 | 3 | # Eg. 4 | # n = 5 5 | # a[5] = {11,22,33,44,55} 6 | # Key = 44 7 | # 44 is found at the position 3 8 | 9 | def binarySearch(arr, x, y, n): 10 | if y >= x: 11 | z = (y + x) // 2 12 | 13 | if arr[z] == n: 14 | return z 15 | 16 | elif arr[z] > n: 17 | return binarySearch(arr, x, z - 1, n) 18 | 19 | else: 20 | return binarySearch(arr, z + 1, y, n) 21 | 22 | else: 23 | return 0 24 | 25 | arr = [11, 22, 33, 44, 55, 44] 26 | n = 44 27 | 28 | result = binarySearch(arr, 0, len(arr)-1, n) 29 | 30 | if result != -1: 31 | print(n, "is found at the position", str(result)) 32 | else: 33 | 0 34 | 35 | # Input: 11 22 33 44 55 44 36 | # Output: 44 is found at the position 3 37 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/Python/Exp_11 - Insertion Sort.py: -------------------------------------------------------------------------------- 1 | # Python Program for Insertion Sort 2 | 3 | # Eg: 4 | # n = 7 5 | # Array Elements = {70, 50, 30, 10, 60, 40, 20} 6 | # Sorted Array = {10, 20, 30, 40, 50, 60, 70} 7 | 8 | def insertionSort(T1): 9 | for i in range(1, len(T1)): 10 | temp = T1[i] 11 | j = i - 1 12 | while (j >= 0 and temp < T1[j]): 13 | T1[j + 1] = T1[j] 14 | j = j - 1 15 | T1[j + 1] = temp 16 | 17 | 18 | # n = int(input()) temporarily 19 | n = 5 20 | 21 | T1 = input().split() 22 | T2 = T1 23 | T1 = [int(x) for x in T1] 24 | insertionSort(T1) 25 | for i in range(len(T1)): 26 | # print(T1[i],end=' ') 27 | print(T1[i]) 28 | 29 | # (1) 30 | # Input: 7 31 | # 70 50 30 10 60 40 20 32 | # Output: 10 20 30 40 50 60 70 33 | # 34 | # (2) 35 | # Input: 6 36 | # 66 44 22 11 33 55 37 | # Output: 11 22 33 44 55 66 38 | -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/Python/Exp_12 - Selection Sort.py: -------------------------------------------------------------------------------- 1 | # Python Program for Selection Sort 2 | 3 | # Eg: 4 | # n = 7 5 | # Array Elements = {70, 50, 30, 10, 60, 40, 20} 6 | # Sorted Array = {10, 20, 30, 40, 50, 60, 60, 70} 7 | 8 | def swap(i, j, nArr): 9 | if i!=j: 10 | temp = nArr[j] 11 | nArr[j] = nArr[i] 12 | nArr[i] = temp 13 | 14 | def T1(nArr): 15 | for i in range(0, len(nArr)): 16 | small = i 17 | for j in range(i+1, len(nArr)): 18 | if nArr[j] < nArr[small]: 19 | small = j 20 | swap(i, small, nArr) 21 | 22 | T2 = input() 23 | nArr = input().split() 24 | T1(nArr) 25 | print(' '.join(nArr)) 26 | 27 | # (1) 28 | # Input: 7 29 | # 70 50 30 10 60 40 20 30 | # Output: 10 20 30 40 50 60 70 31 | 32 | # (2) 33 | # Input: 6 34 | # 66 44 22 55 11 33 35 | # Output: 11 22 33 44 55 66 -------------------------------------------------------------------------------- /Semester 4/Code Optimization and Debugging-II/Python/Exp_13 - Inorder Traversal.py: -------------------------------------------------------------------------------- 1 | # 13.Python program to perform inorder tree traversal 2 | # Perform inorder traversal of a tree with root 25 , left child 15 and write child 30 3 | 4 | class Node: 5 | def __init__(self, key): 6 | self.left = None 7 | self.right = None 8 | self.val = key 9 | 10 | def inorderTraversal(root): 11 | if root: 12 | inorderTraversal(root.left) 13 | print(root.val,end = ''), 14 | inorderTraversal(root.right) 15 | 16 | T1 = input() 17 | root = Node("25,") 18 | root.left = Node("15,") 19 | root.right = Node("30") 20 | inorderTraversal(root) 21 | 22 | # Input: root 25 , left child 15 ,write child 30 23 | # Output: 15,25,30 24 | -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microcontroller 8051/Exp_01 - Filling of Data in Internal Memory.asm: -------------------------------------------------------------------------------- 1 | MOV R0,#50H 2 | MOV R1,#0AH 3 | MOV A,#22H 4 | L1: MOV @R0,A 5 | INC R0 6 | DJNZ R1,L1 7 | L2: SJMP L2 -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microcontroller 8051/Exp_02 - Data Transfer Between Internal Memories.asm: -------------------------------------------------------------------------------- 1 | MOV R0,#30H 2 | MOV R1,#5AH 3 | MOV R3,#5AH 4 | L1: MOV A,@R0 5 | INC R0 6 | INC R1 7 | DJNZ R3,L1 8 | L2: SJMP L2 -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microcontroller 8051/Exp_03 - Separating The Lower Nibble.asm: -------------------------------------------------------------------------------- 1 | MOV R0,#50H 2 | MOV R1,#60H 3 | MOV R2,#04H 4 | L1: MOV A,@R0 5 | ANL A,#0FH 6 | MOV @R1,A 7 | INC R0 8 | INC R1 9 | DJNZ R2,L1 10 | L2: SJMP L2 -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microcontroller 8051/Exp_04 - Separating The Upper Nibble.asm: -------------------------------------------------------------------------------- 1 | MOV R0,#50H 2 | MOV R1,#60H 3 | MOV R2,#04H 4 | L1: MOV A,@R0 5 | ANL A,#0FH 6 | SWAP A 7 | MOV @R1,A 8 | INC R0 9 | INC R1 10 | DJNZ R2,L1 11 | L2: SJMP L2 -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microcontroller 8051/Exp_05 - Bit Manipulation.asm: -------------------------------------------------------------------------------- 1 | MOV R0,#50H 2 | MOV A,@R0 3 | RRC A 4 | JC L1 5 | MOV 51H,#0EH 6 | L2:SJMP L2 7 | L1: MOV 51H,#0DH 8 | L3: SJMP L3 -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microcontroller 8051/Exp_06 - Binary to Gray Code Conversion.asm: -------------------------------------------------------------------------------- 1 | MOV R0,#50H 2 | MOV R1,#60H 3 | MOV A,@R0 4 | SETB C 5 | CPL C 6 | RRC A 7 | XRL A,@R0 8 | MOV @R1,A 9 | L1: SJMP L1 -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microcontroller 8051/Exp_07 - Boolean Function Using 8051.asm: -------------------------------------------------------------------------------- 1 | MOV R0,#50H 2 | MOV A,@R0 3 | INC R0 4 | ANL A,@R0 5 | MOV R1,A 6 | INC R0 7 | MOV A,@R0 8 | CPL A 9 | ORL A,R1 10 | MOV 60H,A 11 | L1: SJMP L1 -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microprocessor 8085/Exp_01 - Addition of Two 8-bit Numbers Using 8085.asm: -------------------------------------------------------------------------------- 1 | MVI C,00 2 | LDA 4100 3 | MOV B,A 4 | LDA 4101 5 | ADD B 6 | JNC L1 7 | INR C 8 | L1 9 | STA 4102 10 | MOV A,C 11 | STA 4103 12 | HLT -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microprocessor 8085/Exp_02 - Subtraction of Two 8-bit Numbers Using 8085.asm: -------------------------------------------------------------------------------- 1 | MVI C,00 2 | LDA 4100 3 | MOV B,A 4 | LDA 4101 5 | SUB B 6 | JNC L1 7 | INR C 8 | CMA 9 | INR A 10 | L1: 11 | STA 4102 12 | MOV A,C 13 | STA 4103 14 | HLT -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microprocessor 8085/Exp_03 - Multiplication of Two 8-bit Numbers Using 8085.asm: -------------------------------------------------------------------------------- 1 | MVI D, 00 2 | LDA 4100 3 | MOV B,A 4 | LDA 4101 5 | MOV C,A 6 | MVI A, 00 7 | L2: 8 | ADD B 9 | JNC L1 10 | INR D 11 | L1: 12 | DCR C 13 | JNZ L2 14 | STA 4102 15 | MOV A,D 16 | STA 4103 17 | HLT -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microprocessor 8085/Exp_04 - Division of Two 8-bit Numbers Using 8085.asm: -------------------------------------------------------------------------------- 1 | MVI C,00 2 | LDA 4101 3 | MOV B,A 4 | LDA 4100 5 | L2: 6 | CMP B 7 | JC L1 8 | SUB B 9 | INR C 10 | JMP L2 11 | L1: 12 | STA 4102 13 | MOV A,C 14 | STA 4103 15 | HLT -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microprocessor 8085/Exp_05 - Converting a BCD Number to HEX Number Using 8085.asm: -------------------------------------------------------------------------------- 1 | LDA 4100 2 | MOV E,A 3 | ANI F0 4 | RRC 5 | RRC 6 | RRC 7 | RRC 8 | MOV B,A 9 | MVI A,00 10 | MVI C,0A 11 | L1: 12 | ADD B 13 | DCR C 14 | JNZ L1 15 | MOV B,A 16 | MOV A,E 17 | ANI 0F 18 | ADD B 19 | STA 4101 20 | HLT -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microprocessor 8085/Exp_06 - Converting a HEX Number to BCD Number Using 8085.asm: -------------------------------------------------------------------------------- 1 | MVI D, 00 2 | MVI E, 00 3 | LDA 4100 4 | L2: 5 | CPI 64 6 | JC L1 7 | SUI 64 8 | INR E 9 | JMP L2 10 | L1: 11 | CPI 0A 12 | JC L3 13 | SUI 0A 14 | INR D 15 | JMP L1 16 | L3: 17 | MOV C,A 18 | MOV A,D 19 | RRC 20 | RRC 21 | RRC 22 | RRC 23 | ADD C 24 | STA 4101 25 | MOV A,E 26 | STA 4102 27 | HLT -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microprocessor 8085/Exp_07 - Largest of a Given Set of Numbers Using 8085.asm: -------------------------------------------------------------------------------- 1 | LXI H,4100 2 | MOV B,M 3 | INX H 4 | MOV A,M 5 | DCR B 6 | L2: 7 | INX H 8 | CMP M 9 | JNC L1 10 | MOV A,M 11 | L1: 12 | DCR B 13 | JNZ L2 14 | STA 4106 15 | HLT -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microprocessor 8085/Exp_08 - Smallest of a Given Set of Numbers Using 8085.asm: -------------------------------------------------------------------------------- 1 | LXI H, 4100 2 | MOV B,M 3 | INX H 4 | MOV A,M 5 | DCR B 6 | L2: 7 | INX H 8 | CMP M 9 | JC L1 10 | MOV A,M 11 | L1: 12 | DCR B 13 | JNZ L2 14 | STA 4106 15 | HLT -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microprocessor 8085/Exp_09 - Arranging a Given Set of Numbers in Ascending Order.asm: -------------------------------------------------------------------------------- 1 | MVI B, 04 2 | L3: 3 | LXI H, 4100 4 | MVI C, 04 5 | L2: 6 | MOV A,M 7 | INX H 8 | CMP M 9 | JC L1 10 | MOV D,M 11 | MOV M,A 12 | DCX H 13 | MOV M,D 14 | INX H 15 | L1: 16 | DCR C 17 | JNZ L2 18 | DCR B 19 | JNZ L3 20 | HLT -------------------------------------------------------------------------------- /Semester 4/Microprocessor and Micocontroller Lab/Microprocessor 8085/Exp_10 - Arranging a Given Set of Numbers in Descending Order.asm: -------------------------------------------------------------------------------- 1 | MVI B, 04 2 | L3: 3 | LXI H, 4100 4 | MVI C, 04 5 | L2: 6 | MOV A,M 7 | INX H 8 | CMP M 9 | JNC L1 10 | MOV D,M 11 | MOV M,A 12 | DCX H 13 | MOV M,D 14 | INX H 15 | L1: 16 | DCR C 17 | JNZ L2 18 | DCR B 19 | JNZ L3 20 | HLT -------------------------------------------------------------------------------- /Semester 5/Computer Networks/Exp_01 - Find IP Address.java: -------------------------------------------------------------------------------- 1 | /* 2 | Aim 3 | To write a java program to find the IP address of the system 4 | 5 | Algorithm 6 | 1.Start 7 | 2.Import the required packages 8 | 3.Create a class GetIPAddress 9 | 4.Initialize InetAddress class and create object addr. 10 | 5.Get IP address of the system using getHostAddress() method 11 | 6.Print the IP address 12 | 7.End 13 | */ 14 | 15 | import java.net.InetAddress; 16 | public class GetIPAddress { 17 | public static void main(String[] args) throws Exception { 18 | InetAddress addr = InetAddress.getLocalHost(); 19 | System.out.println("Local Host Address: " + addr. getHostAddress()); 20 | String hostname = addr.getHostName(); 21 | System.out.println("Local Host Name: " + hostname); 22 | } 23 | } 24 | 25 | /* 26 | Output: 27 | Local Host Address: 10.0.3.78 28 | Local Host Name: ML-043 29 | */ -------------------------------------------------------------------------------- /Semester 5/Computer Networks/Exp_03 - Print the client address on the server/client.java: -------------------------------------------------------------------------------- 1 | /* 2 | Aim 3 | To create a program to print client address at server side 4 | 5 | Algorithm 6 | Server 7 | STEP1: Create instances for socket and ServerSocket class. 8 | STEP2: Use the port 9000 for TCP. 9 | STEP3: Make the PrintStream object connect to the OuputStream using Socket. 10 | STEP4: Create an instance of the Date class and write it into the Socket. 11 | STEP5: Get the IP address of the client using the socket and getInetAddress(). 12 | STEP6: Print the client’s IPAddress. 13 | 14 | Client 15 | STEP1: Create instances for socket class with the port number 9000. 16 | STEP2: Create an object of DataInputStream and make it to get data from server through the socket. 17 | STEP3: Read the Date object. 18 | STEP4: Print the obtained date. 19 | */ 20 | 21 | import java.net.*; 22 | import java.io.*; 23 | public class client { 24 | public static void main(String[] args) throws Exception { 25 | InetAddress a=InetAddress.getLocalHost(); 26 | Socket s2 = new Socket(a,9000); 27 | String add=a.getHostAddress(); 28 | BufferedReader in=new Buff eredReader(new InputStreamReader(s2.getInputStream())); 29 | PrintWriter out=new PrintWriter(new OutputStreamWriter(s2.getOutputStream()),true); 30 | System.out.println(in.readLine()); 31 | out.println(add); 32 | s2.close(); 33 | } 34 | } 35 | 36 | /* 37 | Output 38 | Server 39 | >javac server.java 40 | >java server 41 | Server Running 42 | Client Connected: 43 | Socket[addr=/10.0.2.21,port=50666,localport=9000] 44 | Client's IP is 45 | 10.0.2.21 46 | 47 | Client 48 | >javac client.java 49 | >java client 50 | 10.0.2.21 51 | */ -------------------------------------------------------------------------------- /Semester 5/Computer Networks/Exp_04 - Creation of chat program/cClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | Aim 3 | Program to create simple chat application 4 | 5 | Algorithm 6 | Server 7 | STEP1: Instances of vector class is used to keep track of number of clients that can be connected and currently logged. 8 | STEP2: The method that is responsible for sending the message to the clients is made synchronized. 9 | STEP3: Server is capable of keeping into account the number of users. It adds and removes the client from the vector list as and when the connections are established and terminated. 10 | 11 | Client 12 | STEP1: The client receives the name of the user and message of that user and sends it to client. Server then passes it on to all clients connected. 13 | */ 14 | 15 | import java.net.*; 16 | import java.io.*; 17 | 18 | public class cClient { 19 | public static void main(String arg[])throws Exception { 20 | Socket s=new Socket(InetAddress.getLocalHost(),4000); 21 | BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream())); 22 | BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); 23 | PrintWriter out=new PrintWriter(s.getOutputStream(),true); 24 | String input,t; 25 | while(true) { 26 | System.out.println("client"); 27 | out.println("client:"+in.readLine()); 28 | System.out.println(br.readLine()); 29 | } 30 | } 31 | } 32 | 33 | /* 34 | Output 35 | Server 36 | >java cServer.java 37 | >java cServer 38 | server 39 | test 40 | client:xyz 41 | server 42 | sample 43 | Client has closed 44 | 45 | Client 46 | >javac cClient.java 47 | >java cClient 48 | client 49 | xyz 50 | Server:test 51 | client 52 | server:sample 53 | */ -------------------------------------------------------------------------------- /Semester 5/Computer Networks/Exp_05 - Creation of UDP server/client.java: -------------------------------------------------------------------------------- 1 | /* 2 | Aim 3 | To perform a java program for UDP client and server. 4 | 5 | Algorithm 6 | Server 7 | 1.Create a new Datagram Socket. 8 | 2.Create a new Datagram packet. 9 | 3.Create a message to be sent. 10 | 4.Convert into bytes 11 | 5.create a packet 12 | 6.send packet 13 | 7.wait for acknowledgement from client 14 | 8.print data from client 15 | 9.stop the program 16 | 17 | Client 18 | 1.Create new Datagram Socket. 19 | 2.Create new Datagram packet. 20 | 3.Get the packet. 21 | 4.Print the content. 22 | 5.Create a new packet. 23 | 6.send to server 24 | 7.Stop the program. 25 | */ 26 | 27 | import java.net.*; 28 | import java.io.*; 29 | public class client { 30 | public static int client=789; 31 | public static void main(String args[]) throws IOException { 32 | DatagramSocket ds=new DatagramSocket(client); 33 | byte b[]=new byte[1024]; 34 | System.out.println("client....receiving...."); 35 | while(true) { 36 | DatagramPacket dp=new DatagramPacket(b,b.length); 37 | ds.receive(dp); 38 | String s=new String(dp.getData(),0,dp.getLength()); 39 | if(s.equals("end")) break; 40 | else System.out.println(s); 41 | } 42 | } 43 | } 44 | 45 | /* 46 | Output 47 | >javac server.java 48 | >java server 49 | Server Side...Sending... 50 | ML-019/10.0.1.157 51 | 52 | Client 53 | >javac client.java 54 | >java client 55 | Client...Receiving 56 | */ -------------------------------------------------------------------------------- /Semester 5/Computer Networks/Exp_06 - Implement FTP using TCP/client.java: -------------------------------------------------------------------------------- 1 | /* 2 | Aim 3 | To create a program to implement FTP using TCP 4 | 5 | Algorithm: 6 | Client 7 | STEP 1: Create instance for the Socket class and establish connectivity with the server 8 | STEP 2: Use the port number 4000 9 | STEP 3: Receive the file from the server 10 | STEP 4: Reset the connection with the server 11 | Server 12 | STEP 1: Create instances for the serversocket class and accept the server port 13 | STEP 2: Read the filename to be opened 14 | STEP 3: Send the file to the client 15 | */ 16 | 17 | import java.net.*; 18 | import java.io.*; 19 | public class client { 20 | public static void main(String args[]) { 21 | try { 22 | Socket s=new Socket(InetAddress.getLocalHost(),4000); 23 | BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream())); 24 | String str; 25 | while((str=br.readLine())!=null) 26 | System.out.println(str); 27 | } catch(Exception e) { 28 | System.out.println("The connection to the server has been reset"); 29 | } 30 | } 31 | } 32 | 33 | /* 34 | Output 35 | Server 36 | >javac server.java 37 | >java server 38 | Enter file name: 39 | sample.txt 40 | The contents of the file are: 41 | xyz 42 | Sending the file to the client... 43 | 44 | Client 45 | >javac client.java 46 | >java client 47 | xyz 48 | The connection to the server has been reset 49 | */ -------------------------------------------------------------------------------- /Semester 5/Computer Networks/Exp_07 - Implement FTP using UDP/client.java: -------------------------------------------------------------------------------- 1 | /* 2 | Aim 3 | To create a program to implement FTP using UDP 4 | 5 | Algorithm 6 | Client 7 | STEP 1: Create instance for the Socket class and establish connectivity with the server 8 | STEP 2: Use the port number 8000. 9 | STEP 3: Receive the file from the server 10 | STEP 4: Reset the connection with the server 11 | 12 | Server 13 | STEP 1: Create instances for the serversocket class and accept the server port 14 | STEP 2: Read the filename to be opened 15 | STEP 3: Send the file to the client 16 | */ 17 | 18 | import java.net.*; 19 | import java.io.*; 20 | public class client { 21 | public static void main(String[] args) throws Exception { 22 | InetAddress sa=InetAddress.getLocalHost(); 23 | byte data[]=new byte[1024]; 24 | DatagramSocket ds = new DatagramSocket(8001); 25 | DatagramPacket dp=new DatagramPacket(data,data.length); 26 | ds.receive(dp); 27 | String msg=new String(dp.getData(),0,0,dp.getLength()); 28 | System.out.println("Received data: " + msg); 29 | } 30 | } 31 | 32 | /* 33 | Output 34 | Server 35 | >javac server.java 36 | >java server 37 | Enter file name: 38 | abc.txt 39 | Content: sample 40 | Sending the file to the client... 41 | 42 | Client 43 | >javac client.java 44 | >java client 45 | Received data: sample 46 | */ -------------------------------------------------------------------------------- /Semester 5/Computer Networks/Exp_08 - Implement HTTP protocol.java: -------------------------------------------------------------------------------- 1 | /* 2 | Aim 3 | Program to implement HTTP protocol and to print URl for the Client. 4 | 5 | Algorithm 6 | STEP1: Create the URL with Http URL Connections 7 | STEP2: Define the Http Protocol for Client Connections. 8 | STEP3: Get the Http Connection. 9 | STEP4: Print the URL for the Client. 10 | */ 11 | 12 | import java.io.*; 13 | import java.net.*; 14 | public class httpexp { 15 | public static void main(String args[])throws IOException { 16 | URL url=new URL("http://www.google.com/"); 17 | URLConnection conn=url.openConnection(); 18 | conn.connect(); 19 | InputStreamReader content= new 20 | InputStreamReader(conn.getInputStream()); FileWriter f=new FileWriter ("abc.html"); 21 | for(int i=0;i!=-1;i= content.read()) { 22 | f.write((char) i); 23 | } 24 | } 25 | } 26 | 27 | /* 28 | Output 29 | >javac httpexp.java 30 | >java httpexp 31 | >abc.html 32 | */ -------------------------------------------------------------------------------- /Semester 5/Computer Networks/Exp_09 - Daemon Thread.java: -------------------------------------------------------------------------------- 1 | /* 2 | Aim 3 | To create a program to demonstrate the working of methods of a daemon thread in java 4 | 5 | Algorithm 6 | STEP1: Start 7 | STEP2: Create a class DaemonThread 8 | STEP3: In run() method, check if the thread is a user or daemon thread using the isDaemon() method 9 | STEP4: The method returns true if it is a daemon thread else returns false 10 | STEP5: Set the current thread as a daemon using the setDaemon method before calling the start() method 11 | STEP6: The parameter should be true to set as a daemon thread else it is considered a user thread 12 | STEP7: Stop 13 | */ 14 | 15 | public class DaemonThread extends Thread { 16 | public DaemonThread(String name) { 17 | super(name); 18 | } 19 | public void run() { 20 | if(Thread.currentThread().isDaemon()) { 21 | System.out.println(getName() + " is Daemon thread"); 22 | } else { 23 | System.out.println(getName() + " is User thread"); 24 | } 25 | } 26 | public static void main(String[] args) { 27 | DaemonThread t1 = new DaemonThread("t1"); 28 | DaemonThread t2 = new DaemonThread("t2"); 29 | DaemonThread t3 = new DaemonThread("t3"); 30 | t1.setDaemon(true); 31 | t1.start(); 32 | t2.start(); 33 | t3.setDaemon(true); 34 | t3.start(); 35 | } 36 | } 37 | 38 | 39 | /* 40 | Output 41 | >javac DaemonThread.java 42 | >java DaemonThread 43 | t1 is Daemon thread 44 | t3 is Daemon thread 45 | t2 is Daemon thread 46 | */ -------------------------------------------------------------------------------- /Semester 5/Computer Networks/Exp_10 - Traceroute.java: -------------------------------------------------------------------------------- 1 | /* 2 | Aim 3 | To create a program simulating traceroute command 4 | 5 | Algorithm 6 | 1.Start 7 | 2.Include the necessary packages in java 8 | 3.Create a process object p 9 | 4.Declare BufferedReader stream object 10 | 5.Trace the route a packet takes when travelling to its destination 11 | 6.Print the results 12 | 7.Stop 13 | */ 14 | 15 | import java.io.BufferedReader; 16 | import java.io.InputStreamReader; 17 | public class traceroute { 18 | public static void runSystemCommand(String command) { 19 | try { 20 | Process p = Runtime.getRuntime().exec(command); 21 | BufferedReader inputStream = new BufferedReader(new InputStreamReader(p.getInputStream())); 22 | String s = ""; 23 | while ((s = inputStream.readLine()) != null) 24 | System.out.println(s); 25 | } catch (Exception e) {} 26 | } 27 | public static void main(String[] args) { 28 | String ip = "www.google.com"; 29 | runSystemCommand("tracert " + ip); 30 | } 31 | } 32 | 33 | /* 34 | Output 35 | >javac traceroute.java 36 | >java traceroute 37 | Tracing route to google.com [142.250.67.36] 38 | over a maximum of 30 hops: 39 | 1 <1 ms <1 ms <1 ms 10.0.0.5 40 | */ -------------------------------------------------------------------------------- /Semester 5/Computer Networks/Exp_11 - Ping.java: -------------------------------------------------------------------------------- 1 | /* 2 | Aim 3 | To create a program simulating traceroute command 4 | 5 | Algorithm 6 | 1.Start 7 | 2.Include the necessary packages in java 8 | 3.Create a process object p 9 | 4.Declare BufferedReader stream object 10 | 5.Get the details of the server 11 | -Length of the IP address 12 | -Time required to get the details 13 | -Sent packets, received packets and lost packets 14 | -Minimum, maximum and average times 15 | 6.Print the results 16 | 7.Stop 17 | */ 18 | 19 | import java.io.*; 20 | public class ping { 21 | public static void runSystemCommand(String Command) { 22 | try { 23 | Process p=Runtime.getRuntime().exec(Command); 24 | BufferedReader InputStream=new BufferedReader(new InputStreamReader(p.getInputStream())); 25 | String s="vvv"; 26 | while((s=InputStream.readLine())!=null) { 27 | System.out.println(s); 28 | } 29 | } catch(Exception e) { 30 | e.printStackTrace(); 31 | } 32 | } 33 | public static void main(String[]args) { 34 | String Ip="localhost"; 35 | runSystemCommand("ping " + ip); 36 | java.util.Date date = new java.util.Date(); 37 | System.out.println(date); 38 | } 39 | } 40 | 41 | /* 42 | Output 43 | >java ping.java 44 | >java ping 45 | Pinging ML-004.MAINLAB.COM[127.0.0.1] with 32 bytes of data: 46 | Reply from 127.0.0.1: bytes = 32 time < 1ms TTL = 128 47 | Reply from 127.0.0.1: bytes = 32 time < 1ms TTL = 128 48 | */ -------------------------------------------------------------------------------- /Semester 5/Operating Systems/Exp_02(a) - Pascals triangle.sh: -------------------------------------------------------------------------------- 1 | <./calc.sh 42 | Enter 2 numbers : 5 43 | 2 44 | Choose: 45 | 1.Addition 46 | 2.Subtraction 47 | 3.Multiplication 48 | 4.Division 49 | 1 50 | Result: 7 51 | / 52 | -------------------------------------------------------------------------------- /Semester 5/Operating Systems/Exp_02(c) - Generate armstrong series.sh: -------------------------------------------------------------------------------- 1 | <0)) 24 | do 25 | a=$((c%10)) 26 | b=$((b + a*a*a)) 27 | c=$((c/10)) 28 | done 29 | if((b==d)); then 30 | echo "$i" 31 | fi 32 | i=$((i+1)) 33 | done 34 | 35 | <ls 31 | hello.c 32 | case.sh 33 | >./case.sh 34 | Enter path to file: 35 | /root/ 36 | Enter filename: 37 | hello.c 38 | 1.Uppercase to lowercase 39 | 2.Lowercase to uppercase 40 | >2 41 | >ls 42 | HELLO.C 43 | case.sh 44 | >./case.sh 45 | Enter path to file: 46 | /root/ 47 | Enter filename: 48 | HELLO.C 49 | 1.Uppercase to lowercase 50 | 2.Lowercase to uppercase 51 | >1 52 | >ls 53 | hello.c 54 | case.sh 55 | / -------------------------------------------------------------------------------- /Semester 5/Operating Systems/Exp_03(c) - Display file metadata.sh: -------------------------------------------------------------------------------- 1 | <./metadata.sh 28 | Enter path to file: 29 | /root/ 30 | Enter filename: 31 | hello.c 32 | File: hello.cd 33 | Size: 76 Blocks: 8 10 Block: 4096 regular file 34 | Device: eh/14d 35 | Access: (0644/-rw-r--r--) Uid:(0/root) Gid:(0/root) 36 | Access: 2020-07-03 14:45:56.000 37 | Modify: 2020-07-03 14:45:56.000 38 | Change: 2022-07-03 15:45:56.000 39 | / -------------------------------------------------------------------------------- /Semester 5/Operating Systems/Exp_03(d) - Display date and time.sh: -------------------------------------------------------------------------------- 1 | <./date.sh 21 | Wed Sep 21 14:00:00 UTC 2022 22 | 09-21-22 23 | / -------------------------------------------------------------------------------- /Semester 5/Operating Systems/Exp_08 - Paging.c: -------------------------------------------------------------------------------- 1 | /* 2 | Aim 3 | To implement the memory management policy-paging 4 | 5 | Algorithm 6 | Step 1: Start 7 | Step 2: Read all the necessary input from the keyboard. 8 | Step 3: Pages - Logical memory is broken into fixed - sized blocks. 9 | Step 4: Frames – Physical memory is broken into fixed – sized blocks. 10 | Step 5: Calculate the physical address using the following 11 | Physical address = ( Frame number * Frame size ) + offset 12 | Step 6: Display the physical address. 13 | Step 7: Stop the process. 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | int main() { 20 | int size,m,n,pgno,pagetable[3]={5,6,7},i,j,frameno; 21 | double m1; 22 | int ra=0,ofs; 23 | printf("Enter process size (max 12KB): "); 24 | scanf("%d",&size); 25 | m1=size/4; 26 | n=ceil(m1); 27 | printf("Total no. of pages: %d",n); 28 | printf("\nEnter relative address (in hex): \n"); 29 | scanf("%d",&ra); 30 | pgno=ra/1000; 31 | ofs=ra%1000; 32 | printf("page no=%d\n",pgno); 33 | printf("page table"); 34 | for(i=0;i 16 | int x=1,rc=0,readcount=1; 17 | void p(int *a) { 18 | while(*a==0) { 19 | printf("busy wait"); 20 | } 21 | *a=*a-1; 22 | } 23 | void v(int*b) { 24 | *b=*b+1; 25 | } 26 | void p1(int*c) { 27 | while(*c==0) { 28 | printf("busy wait"); 29 | } 30 | *c=*c-1; 31 | } 32 | 33 | void v1(int*d) { 34 | *d=*d+1; 35 | } 36 | 37 | void reader() { 38 | int flag=1; 39 | while(flag==1) { 40 | p(&readcount); 41 | rc=rc+1; 42 | if(rc==1) 43 | p1(&x); 44 | v(&readcount); 45 | printf("\n reader is reading"); 46 | p(&readcount); 47 | rc=rc-1; 48 | if(rc==0) 49 | v1(&x); 50 | v(&readcount); 51 | flag=0; 52 | } 53 | } 54 | 55 | void writer() { 56 | p1(&x); 57 | printf("\n writer is writing"); 58 | v1(&x); 59 | } 60 | 61 | void main() { 62 | reader(); 63 | writer(); 64 | reader(); 65 | writer(); 66 | } 67 | 68 | /* 69 | Output 70 | reader is reading 71 | writer is writing 72 | reader is reading 73 | writer is writing 74 | */ 75 | -------------------------------------------------------------------------------- /Semester 6/Compiler Design Lab/Exp_01 - Implementation of Lexical Analyzer.l: -------------------------------------------------------------------------------- 1 | /*Aim:To implement a program to identify C/C++ keywords, identifiers, operators and end statements 2 | 3 | Algorithm: 4 | 1.In the flex (lex and yacc) tool, create a lex file. 5 | 2.In the C includes section, include the required header files. 6 | 3.In the rules section, define the rules through regex rules. Store the result in yytext and print the same. 7 | 4.In the user section, write the main function and call yylex(). 8 | 5.Write yywrap() function for wrapping up. Return 1 if done and 0 if not done. 9 | */ 10 | 11 | //Program: 12 | %{ 13 | #include 14 | #include 15 | %} 16 | %% 17 | #.* {printf("\n%s is a preprocessor", yytext);} 18 | int|float|double|long {printf("\n%s is a keyword", yytext);} 19 | [a-zA-Z][a-zA-Z0-9]* { printf("\n%s is an identifier", yytext);} 20 | [0-9]+ {printf("\n%s is a digit", yytext);} 21 | [=+/*%] {printf("\n%s is an operator", yytext);} 22 | [(){}|,;] {printf("\n%s is an end statement", yytext);} 23 | %% 24 | int main () 25 | { 26 | yylex(); 27 | return 0; 28 | } 29 | int yywrap(void) 30 | { 31 | } 32 | 33 | /*Output: 34 | Position = Initial + Rate * 30 35 | Position is an identifier 36 | = is an operator 37 | Initial is an identifier 38 | + is an operator 39 | Rate is an identifier 40 | * is an operator 41 | 30 is a digit 42 | */ -------------------------------------------------------------------------------- /Semester 6/Compiler Design Lab/Exp_03 - Parser using Ambiguous Grammar/file.l: -------------------------------------------------------------------------------- 1 | //Aim: To implement program for parser using ambiguous grammar 2 | 3 | /*Algorithm: 4 | 1.Include required header files and declare error handling and lexer function 5 | 2.Semantic actions are specified in C code to perform evaluation of expressions 6 | 3.Regular expression is used to match tokens in the input and return them to parser 7 | 4.In main, yyparse() is called to start the parsing process 8 | 5.If error is encountered, yyerror() is called 9 | 6.The program returns 0 to indicate completion 10 | */ 11 | 12 | //Program: 13 | %option noyywrap 14 | %{ 15 | #include 16 | #include"y.tab.h" 17 | void yyerror(char *s); 18 | extern int yylval; 19 | %} 20 | digit[0-9] 21 | %% 22 | {digit}+ {yylval=atoi(yytext);return NUM;} 23 | [-+*/\n] {return *yytext;} 24 | \( {return *yytext;} 25 | \) {return *yytext;} 26 | . {yyerror("syntax error");} 27 | %% 28 | 29 | /*Output: 30 | 2+3 31 | 5 32 | 2 3 33 | syntax error 34 | */ 35 | 36 | /*Output: 37 | C:\Desktop>lex Noname2.l 38 | C:\Desktop>yacc -d Noname3.y 39 | Noname3.y: conflicts: 16 shift/reduce 40 | C:\Desktop>cc lex.yy.c y.tab.c 41 | C:\Desktop>a.exe 42 | 3+4 43 | 7 44 | 2 2 45 | syntax errorsyntax errorsyntax error 46 | */ -------------------------------------------------------------------------------- /Semester 6/Compiler Design Lab/Exp_03 - Parser using Ambiguous Grammar/file.y: -------------------------------------------------------------------------------- 1 | //Aim: To implement program for parser using ambiguous grammar 2 | 3 | /*Algorithm: 4 | 1.Include required header files and declare error handling and lexer function 5 | 2.Semantic actions are specified in C code to perform evaluation of expressions 6 | 3.Regular expression is used to match tokens in the input and return them to parser 7 | 4.In main, yyparse() is called to start the parsing process 8 | 5.If error is encountered, yyerror() is called 9 | 6.The program returns 0 to indicate completion 10 | */ 11 | 12 | //Program: 13 | %{ 14 | #include 15 | void yyerror(char*); 16 | extern int yylex(void); 17 | %} 18 | %token NUM 19 | %% 20 | S: 21 | S E'\n' {printf("%d\n",$2);} 22 | | 23 | ; 24 | E: 25 | E'+'E {$$=$1+$3;} 26 | |E'-'E {$$=$1-$3;} 27 | |E'*'E {$$=$1*$3;} 28 | |E'/'E {$$=$1/$3;} 29 | |'('E')' {$$=$2;} 30 | |NUM {$$=$1;} 31 | %% 32 | void yyerror(char *s) 33 | { 34 | printf("%s",s); 35 | } 36 | int main() 37 | { 38 | yyparse(); 39 | return 0; 40 | } 41 | 42 | /*Output: 43 | C:\Desktop>lex Noname2.l 44 | C:\Desktop>yacc -d Noname3.y 45 | Noname3.y: conflicts: 16 shift/reduce 46 | C:\Desktop>cc lex.yy.c y.tab.c 47 | C:\Desktop>a.exe 48 | 3+4 49 | 7 50 | 2 2 51 | syntax errorsyntax errorsyntax error 52 | */ -------------------------------------------------------------------------------- /Semester 6/Compiler Design Lab/Exp_04 - Parser using Unambiguous Grammar/file.l: -------------------------------------------------------------------------------- 1 | //Aim: To implement program for parser using unambiguous grammar 2 | 3 | /*Algorithm: 4 | 1.Include required header files and declare error handling and lexer function 5 | 2.Semantic actions are specified in C code to perform evaluation of expressions 6 | 3.Regular expression is used to match tokens in the input and return them to parser 7 | 4.In main, yyparse() is called to start the parsing process 8 | 5.If error is encountered, yyerror() is called 9 | 6.The program returns 0 to indicate completion 10 | */ 11 | 12 | //Program: 13 | %option noyywrap 14 | %{ 15 | #include 16 | #include"y.tab.h" 17 | void yyerror(char *s); 18 | extern int yylval; 19 | %} 20 | digit [0-9] 21 | %% 22 | {digit}+ {yylval=atoi(yytext);return NUM;} 23 | [-+*/\n] {return *yytext;} 24 | \( {return *yytext;} 25 | \) {return *yytext;} 26 | . {yyerror("syntax error");} 27 | %% 28 | 29 | /*Output: 30 | 2+3 31 | 5 32 | 2 3 33 | syntax error 34 | */ 35 | 36 | /*Output: 37 | C:\Desktop>lex Noname2.l 38 | C:\Desktop>yacc -d Noname3.y 39 | Noname3.y: conflicts: 16 shift/reduce 40 | C:\Desktop>cc lex.yy.c y.tab.c 41 | C:\Desktop>a.exe 42 | 3+4 43 | 7 44 | 2 2 45 | syntax errorsyntax errorsyntax error 46 | */ -------------------------------------------------------------------------------- /Semester 6/Compiler Design Lab/Exp_04 - Parser using Unambiguous Grammar/file.y: -------------------------------------------------------------------------------- 1 | //Aim: To implement program for parser using ambiguous grammar 2 | 3 | /*Algorithm: 4 | 1.Include required header files and declare error handling and lexer function 5 | 2.Semantic actions are specified in C code to perform evaluation of expressions 6 | 3.Regular expression is used to match tokens in the input and return them to parser 7 | 4.In main, yyparse() is called to start the parsing process 8 | 5.If error is encountered, yyerror() is called 9 | 6.The program returns 0 to indicate completion 10 | */ 11 | 12 | //Program: 13 | %{ 14 | #include 15 | void yyerror(char *); 16 | extern int yylex(void); 17 | %} 18 | %token NUM 19 | %% 20 | S: 21 | S E '\n' {printf("%d \n",$2);} 22 | | 23 | ; 24 | E: 25 | E '+' T {$$=$1+$3;} 26 | |E '-' T {$$=$1-$3;} 27 | |T {$$=$1;} 28 | T: 29 | T '*' F {$$=$1*$3;} 30 | |T '/' F {$$=$1/$3;} 31 | |F {$$=$1;} 32 | F: 33 | '(' E ')' {$$=$2;} 34 | |NUM {$$=$1;} 35 | %% 36 | void yyerror(char *s) 37 | { 38 | printf("%s",s); 39 | } 40 | int main() 41 | { 42 | yyparse(); 43 | return 0; 44 | } 45 | 46 | 47 | /*Output: 48 | C:\Desktop>lex Noname2.l 49 | C:\Desktop>yacc -d Noname3.y 50 | Noname3.y: conflicts: 16 shift/reduce 51 | C:\Desktop>cc lex.yy.c y.tab.c 52 | C:\Desktop>a.exe 53 | 3+4 54 | 7 55 | 2 2 56 | syntax errorsyntax errorsyntax error 57 | */ -------------------------------------------------------------------------------- /Semester 6/Machine Learning & Data Analytics Lab/Exp_01 - Simple Calculator.py: -------------------------------------------------------------------------------- 1 | # Aim: To create a python program for a simple calculator without using library functions 2 | 3 | # Algorithm: 4 | # Step 1: Get input from the user (choice corresponding to various operations like addition, subtraction, multiplication, division) 5 | # Step 2: Get 2 integer inputs from the user 6 | # Step 3: Perform the operations based on the user's choice 7 | # Step 4: Print the output 8 | # Step 5: Stop 9 | 10 | # Program 11 | def add(a, b): 12 | return a + b 13 | def sub(a, b): 14 | return a - b 15 | def mul(a, b): 16 | return a * b 17 | def div(a, b): 18 | return a / b 19 | print("""Select an operation: 20 | 1. Add 21 | 2. Subtract 22 | 3. Multiply 23 | 4. Divide""") 24 | choice = input() 25 | 26 | num1 = int(input("Enter the first number:")) 27 | num2 = int(input("Enter the second number:")) 28 | 29 | if choice == '1': 30 | print(add(num1, num2)) 31 | elif choice == '2': 32 | print(sub(num1, num2)) 33 | elif choice == '3': 34 | print(mul(num1, num2)) 35 | elif choice == '4': 36 | print(div(num1, num2)) 37 | else: 38 | print("Invalid Input") 39 | 40 | # Output 41 | # Select an operation: 42 | # 1. Add 43 | # 2. Subtract 44 | # 3. Multiply 45 | # 4. Divide 46 | # 1 47 | # Enter the first number:5 48 | # Enter the second number:2 49 | # 7 50 | 51 | -------------------------------------------------------------------------------- /Semester 6/Machine Learning & Data Analytics Lab/Exp_01(b) - Simple Calculator using Library Functions.py: -------------------------------------------------------------------------------- 1 | # EXP 1(f): Basic Programming Examples - Calculator using Library Functions 2 | 3 | # Aim: To create a python program for a simple calculator using library functions 4 | 5 | # Algorithm: 6 | # Step 1: Start 7 | # Step 2: Get input from the user (choice corresponding to various operations like addition, subtraction, multiplication, division) 8 | # Step 3: Get 2 integer inputs from the user 9 | # Step 4: Perform the operations based on the user's choice 10 | # Step 5: Print the output 11 | # Step 6: Stop 12 | 13 | # Program 14 | import numpy 15 | 16 | print("Select an operation: ") 17 | print("1.Add") 18 | print("2.Subtract") 19 | print("3.Multiply") 20 | print("4.Divide") 21 | 22 | choice = input() 23 | 24 | num1=int(input("Enter the first number: ")) 25 | num2=int(input("Enter the second number: ")) 26 | 27 | if choice == '1': 28 | print(numpy.add(num1, num2)) 29 | elif choice == '2': 30 | print(numpy.subtract(num1, num2)) 31 | elif choice == '3': 32 | print(numpy.multiply(num1, num2)) 33 | elif choice == '4': 34 | print(numpy.divide(num1, num2)) 35 | else: 36 | print("Invalid Input") 37 | 38 | # Output 39 | # Select an operation: 40 | # 1.Add 41 | # 2.Subtract 42 | # 3.Multiply 43 | # 4.Divide 44 | # 1 45 | # Enter the first number: 5 46 | # Enter the second number: 8 47 | # 13 48 | 49 | -------------------------------------------------------------------------------- /Semester 6/Machine Learning & Data Analytics Lab/Exp_02 - Armstrong Numbers.py: -------------------------------------------------------------------------------- 1 | # Aim: To create a python program to generate armstrong numbers 2 | 3 | # Algorithm: 4 | # Step 1: Take the numbers as input from the user 5 | # Step 2: Determine the number of digits, say it is n 6 | # Step 3: Extract each digit from the number using a loop. Now raise each of these digits to the power n 7 | # Step 4: Keep adding the nth power of these digits in a variable, say sum 8 | # Step 5: Once the sum of all the nth power of the digits is obtained, the loop terminates. If both are equal, then it is an armstrong number and is printed 9 | 10 | # Program 11 | lower = int(input("Enter lower range: ")) 12 | upper = int(input("Enter upper range: ")) 13 | 14 | for num in range(lower, upper + 1): 15 | sum = 0 16 | temp = num 17 | while temp > 0: 18 | digit = temp % 10 19 | sum += digit ** 3 20 | temp //= 10 21 | if num == sum: 22 | print(num) 23 | 24 | # Output 25 | # Enter lower range: 100 26 | # Enter upper range: 500 27 | # 125 28 | # 153 29 | # 216 30 | # 370 31 | # 371 32 | # 407 33 | 34 | -------------------------------------------------------------------------------- /Semester 6/Machine Learning & Data Analytics Lab/Exp_03 - Fibonacci Series.py: -------------------------------------------------------------------------------- 1 | # Aim: To create a python program to generate Fibonacci series 2 | 3 | # Algorithm: 4 | # Step 1: Input the 'n' value until the Fibonacci series has been generated 5 | # Step 2: Initialize sum = 0, a = 0, b = 1 and count = 1 6 | # Step 3: while (count <= n), print sum 7 | # Step 4: Increment the count variable 8 | # Step 5: Swap a & b 9 | # Step 6: sum = a + b 10 | # Step 7: while(count > n), end algorithm 11 | # Step 8: Else, repeat from steps 3 to 6 12 | # Step 9: Stop 13 | 14 | # Program 15 | n=input("Enter an input: ") 16 | a,b=0,1 17 | count=1 18 | print("Fibonacci Series:",a, b, end = "") 19 | while(int(n) > count+1): 20 | sum = a + b 21 | print(sum, end="") 22 | a,b = b, sum 23 | count += 1 24 | 25 | # Output 26 | # Enter an input:5 27 | # Fibonacci Series: 0 1123 28 | 29 | -------------------------------------------------------------------------------- /Semester 6/Machine Learning & Data Analytics Lab/Exp_04 - Import Functions as Modules.py: -------------------------------------------------------------------------------- 1 | # Aim: To create a python program to import functions as modules 2 | 3 | # Algorithm: 4 | # Step 1: Start 5 | # Step 2: Create example module script files 6 | # Step 3: Define relevant functions 7 | # Step 4: Create main script files 8 | # Step 5: Declare necessary variables 9 | # Step 6: Import example module file 10 | # Step 7: Print the output 11 | # Step 8: Stop 12 | 13 | # Program 14 | 15 | #expt.py 16 | import example 17 | 18 | ans = example.add(4,5) 19 | print("Result: ", ans) 20 | 21 | #example.py 22 | def add(a,b): 23 | result = a+b 24 | return result 25 | 26 | # Output 27 | # Result: 9 -------------------------------------------------------------------------------- /Semester 6/Machine Learning & Data Analytics Lab/Exp_05 - Count Symbols.py: -------------------------------------------------------------------------------- 1 | # Aim: To create a python program to count the special characters, alphabets, digits, lowercase and uppercase characters 2 | 3 | # Algorithm: 4 | # Step 1: Start 5 | # Step 2: Declare necessary files and variables 6 | # Step 3: Read the input string 7 | # Step 4: Count the no. of special characrters 8 | # Step 5: Print the output 9 | # Step 6: Stop 10 | 11 | # Program 12 | def countStuff(str): 13 | upper_ctr, lower_ctr, number_ctr, special_ctr = 0,0,0,0 14 | for i in range(len(str)): 15 | if str[i] >= 'A' and str[i] <= 'Z' : upper_ctr += 1 16 | elif str[i] >= 'a' and str[i] <= 'z' : lower_ctr += 1 17 | elif str[i] >= '0' and str[i] <= '9' : number_ctr += 1 18 | else: 19 | special_ctr += 1 20 | return upper_ctr, lower_ctr, number_ctr, special_ctr 21 | 22 | str = "@X5Something.whatever" 23 | print("Original Substrings: ", str) 24 | u,l,n,s = countStuff(str) 25 | print("In Uppercase character: ",u) 26 | print("Lowercase characters: ",l) 27 | print("Number case: ", n) 28 | print("Special case character: ", s) 29 | 30 | # Output 31 | # Original Substrings: @X5Something.whatever 32 | # In Uppercase character: 2 33 | # Lowercase characters: 16 34 | # Number case: 1 35 | # Special case character: 2 36 | 37 | -------------------------------------------------------------------------------- /Semester 6/Machine Learning & Data Analytics Lab/Exp_06 - Data Preprocessing.py: -------------------------------------------------------------------------------- 1 | # Aim 2 | # To create a python program for data preprocessing 3 | 4 | # Algorithm 5 | # 1. Describe the dataset 6 | # 2. In the given dataset, count the rows that are having no value from each column 7 | # 3. Replace the value 0 with NaN 8 | # 4. Remove the rows with the missing values 9 | # 5. Impute the missing data with the mean values 10 | # 6. Split the dataset into training and testing sets 11 | 12 | # Program 13 | import pandas as pd 14 | df = pd.read_csv("Heart.csv") 15 | df 16 | df.describe() 17 | df.info() 18 | df.replace(0,'NAN') 19 | df.dropna() 20 | df.fillna(df.mean(numeric_only=True)) 21 | x=df.iloc[:,0:14].values 22 | x 23 | y=df.iloc[:,14].values 24 | y 25 | from sklearn.model_selection import train_test_split 26 | x_train,x_test,y_train,y_test = train_test_split(x,y,test_size = 0.2, random_state=0) 27 | print (x_train.shape) 28 | print (x_test.shape) 29 | print(df) 30 | 31 | # Output 32 | # [303 rows x 15 columns] -------------------------------------------------------------------------------- /Semester 6/Machine Learning & Data Analytics Lab/Exp_07 - Manipulate Twitter Dataset.py: -------------------------------------------------------------------------------- 1 | # Aim 2 | # To create a python program to manipulate twitter dataset 3 | 4 | # Algorithm 5 | # 1.Import required libraies 6 | # 2.Define 'remove_pattern' to find all occurences of the pattern in the input text and then removes them 7 | # 3.Apply lambda function to 'new' column to remove words >= 3 8 | # 4.Apply lambda function to tokenized tweets 9 | # 5.Print the output 10 | 11 | # Program 12 | import pandas as pd 13 | import numpy as np 14 | import re 15 | data = pd.read_csv("tweets1.csv") 16 | data 17 | def remove_pattern(input_txt, pattern): 18 | r = re.findall(pattern,input_txt) 19 | for i in r: 20 | input_txt = re.sub(i,'',input_txt) 21 | return input_txt 22 | print(data) 23 | data['new'] = np.vectorize(remove_pattern)(data ['text'],"@[\w]*") 24 | print(data) 25 | data['new'] = data['new'].str.replace("[^a-zA-Z#]"," ", regex=False) 26 | print(data) 27 | data['new'] = data['new'].apply(lambda x:' '.join([w for w in x.split() if len(w) > 3])) 28 | print (data) 29 | tokenized_tweet = data['new'].apply (lambda x:x.split()) 30 | print (tokenized_tweet.head()) 31 | from nltk.stem import PorterStemmer 32 | stemmer = PorterStemmer() 33 | tokenized_tweet = tokenized_tweet.apply(lambda x:[stemmer.stem(i) for i in x]) 34 | print(tokenized_tweet.head()) 35 | 36 | # Output 37 | # [2819 rows x 3 columns] -------------------------------------------------------------------------------- /Semester 6/Machine Learning & Data Analytics Lab/Exp_08 - Confusion Matrix.py: -------------------------------------------------------------------------------- 1 | # Aim 2 | # To create a python program to evaluate the results of machine learning 3 | 4 | # Algorithm 5 | # 1.Read actual values vs predicted values 6 | # 2.Iterate through each element i in y 7 | # 3.Compute the values of accuracy 8 | # 4.Print the following: Confusion Matrix, Accuracy, Specificity, Sensitivity, Precision, Recall, Misclassification Error 9 | 10 | # Program 11 | y=['0','1','0','1','1','1','0','1','0','1','0','0','0','1','1','1','0','1','1','0'] 12 | y_pred = ['0','0','0','0','1','0','1','1','1','1','0','0','0','0','0','1','0','1','1','0'] 13 | print (y) 14 | print(y_pred) 15 | 16 | j=0 17 | TP,TN,FP,FN = 0,0,0,0 18 | for i in y: 19 | if i == '1' and y_pred[j] =='1': 20 | TP +=1 21 | elif i == '0' and y_pred[j] =='0': 22 | TN +=1 23 | elif i == '1' and y_pred[j] =='0': 24 | FP +=1 25 | elif i == '0' and y_pred[j] =='1': 26 | FN+=1 27 | j+=1 28 | confusion_matrix = [TP,TN,FP,FN] 29 | print ("Confusion Matrix : ", confusion_matrix) 30 | ACC = (TP+TN) / (TP+FP+TN+FN) 31 | print ("ACCURACY : ", ACC) 32 | PREC = TP / (TP+FP) 33 | print ("PRECISION : ", PREC) 34 | REC = TP / (TP+FN) 35 | print ("RECALL : ", REC) 36 | SN = TP/ (TP+FN) 37 | print ("SENSITIVITY : ", SN) 38 | SP = TN/ (TN+FP) 39 | print ("SPECIFICITY : ", SP) 40 | MCE = 1-ACC 41 | print ("MISCLASSIFICATION ERROR : ", MCE) 42 | 43 | 44 | # Output 45 | # Confusion Matrix : [6, 7, 5, 2] 46 | # ACCURACY : 0.65 47 | # PRECISION : 0.5454545454545454 48 | # RECALL : 0.75 49 | # SENSITIVITY : 0.75 50 | # SPECIFICITY : 0.5833333333333334 51 | # MISCLASSIFICATION ERROR : 0.35 -------------------------------------------------------------------------------- /Semester 6/Machine Learning & Data Analytics Lab/Exp_11 - K-Means Clustering Algorithm.py: -------------------------------------------------------------------------------- 1 | # Aim 2 | # To create a python program to implement K-Means clustering algorithm 3 | 4 | # Algorithm 5 | # 1.Import required libraries 6 | # 2.Load data 7 | # 3.Extract required features 8 | # 4.Fit Kmeans model and obtain predicted cluster labels 9 | # 5.Visualize the clusters using matplotlib 10 | 11 | # Program 12 | import numpy as np 13 | import matplotlib.pyplot as plt 14 | import pandas as pd 15 | df= pd.read_csv('Customers.csv') 16 | df.head(3) 17 | len(df) 18 | X = df.iloc[:, [3,4]].values 19 | X[0:5] 20 | from sklearn.cluster import KMeans 21 | kmeans = KMeans(n_clusters=5, init ='k-means++', max_iter=300, n_init=10, random_state=0 ) 22 | kmeans.n_clusters 23 | y_kmeans = kmeans.fit_predict(X) 24 | df['cluster'] = y_kmeans 25 | print(y_kmeans.shape) 26 | plt.scatter(X[y_kmeans==0, 0], X[y_kmeans==0, 1], s=100, c='red', label = 'Cluster 1') 27 | plt.scatter(X[y_kmeans==1, 0], X[y_kmeans==1, 1], s=100, c='blue', label = 'Cluster 2') 28 | plt.scatter(X[y_kmeans==2, 0], X[y_kmeans==2, 1], s=100, c='green', label ='Cluster 3') 29 | plt.scatter(X[y_kmeans==3, 0], X[y_kmeans==3, 1], s=100, c='cyan', label = 'Cluster 4') 30 | plt.scatter(X[y_kmeans==4, 0], X[y_kmeans==4, 1], s=100, c='magenta', label ='Cluster 5') 31 | plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], 32 | s=300, c='yellow', label = 'Centroids') 33 | plt.title('Clusters of Customers') 34 | plt.xlabel('Annual Income(k$)') 35 | plt.ylabel('Spending Score(1-100)') 36 | plt.show() 37 | 38 | # Output 39 | # array([[15,39],[15,81],[16,6]]) -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/Exp_01(a) - Blink LED.md: -------------------------------------------------------------------------------- 1 | # AIM 2 | To write a program for blink LED using TinkerCAD 3 | # COMPONENTS USED 4 | Arduino Uno, LED 5 | # PROCEDURE 6 | 1. Get Arduino Uno board from components 7 | 2. Get LED from components 8 | 3. LED has 2 sides. Positive side is connected to pin 13 of Arduino and Negative is connected to ground 9 | # CODE 10 | ``` 11 | void setup(){ 12 | pinMode(13,OUTPUT);} 13 | void loop(){ 14 | digitalWrite(13,HIGH); 15 | delay(1000); 16 | digitalWrite(13,LOW); 17 | delay(1000);} 18 | ``` 19 | # DIAGRAM 20 | ![Diagram](/Semester-7/Cyber-Physical-Systems/images/1(a).PNG) 21 | -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/Exp_01(b) - Blink LED using Button.md: -------------------------------------------------------------------------------- 1 | # AIM 2 | To write a program for blink LED with button using TinkerCAD 3 | # COMPONENTS USED 4 | Arduino Uno, LED 5 | # PROCEDURE 6 | 1. Get Arduino Uno board from components 7 | 2. Get LED from components 8 | 3. LED has 2 sides. Positive side is connected to pin 13 of Arduino and Negative is connected to ground 9 | # CODE 10 | ``` 11 | void setup(){ 12 | pinMode(2,INPUT); 13 | pinMode(13,OUTPUT);} 14 | void loop(){ 15 | if(digitalRead(2)==1){ 16 | digitalWrite(13,HIGH);} 17 | else{ 18 | digitalWrite(13, LOW);}} 19 | ``` 20 | # DIAGRAM 21 | ![Diagram](/Semester-7/Cyber-Physical-Systems/images/1(b).PNG) 22 | -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/Exp_02(a) - Display data using Potentiometer.md: -------------------------------------------------------------------------------- 1 | # AIM 2 | To pick one-one from the available sensors and actuators and find or create code that will display the sensed data on the PC 3 | # COMPONENTS USED 4 | Arduino Uno, Potentiometer, Breadboard 5 | # PROCEDURE 6 | 1. Get Arduino Uno board from components 7 | 2. Get Potentiometer from components 8 | 3. Potentiometer has 3 sides. Terminal 1 is ground, T2 is input signal, T3 is output signal 9 | # CODE 10 | ``` 11 | int pot=A0; 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | } 16 | void loop() 17 | { 18 | int potvalue=analogRead(pot); 19 | Serial.print("potvalue"); 20 | Serial.println(potvalue); 21 | delay(10); 22 | } 23 | ``` 24 | # DIAGRAM 25 | ![Diagram](/Semester-7/Cyber-Physical-Systems/images/2(a).PNG) 26 | -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/Exp_02(b) - Display data using Photoresistor.md: -------------------------------------------------------------------------------- 1 | # AIM 2 | To pick one-one from the available list of components and create code that will display the sensed data on the PC 3 | # COMPONENTS USED 4 | Arduino Uno, Multimeter, Photoresistor, Resistor 5 | # PROCEDURE 6 | 1. Get Arduino Uno, Multimeter, Photoresistor and Resistor from components 7 | 2. Connect multimeter to ground and to pin AO 8 | 3. Connect photoresistor to 5V pin and to the resistor 9 | # CODE 10 | ``` 11 | void setup(){ 12 | pinMode(A0, INPUT); 13 | Serial.begin(9600); 14 | } 15 | void loop() 16 | { 17 | int lightvalue=analogRead(A0); 18 | Serial.println(lightvalue); 19 | delay(1000); 20 | } 21 | ``` 22 | # DIAGRAM 23 | ![Diagram](/Semester-7/Cyber-Physical-Systems/images/2(b.).PNG) 24 | -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/Exp_02(c) - Display data in compact format.md: -------------------------------------------------------------------------------- 1 | # AIM 2 | To create a program that displays data from the sensor in regular intervals in a compact format 3 | # COMPONENTS USED 4 | Arduino Uno, LED, Piezo, Resistor, PIR Sensor 5 | # PROCEDURE 6 | 1. Get Arduino Uno, LED, Piezo, Resistor, PIR Sensor from list of components 7 | 2. Connect LED(cathode) to GND and then to Piezo(negative) 8 | 3. Connect resistor(Terminal 1) to pin 13 and Terminal 2 to LED(anode) 9 | 4. Connect Piezo(+ve) to pin -9 10 | 5. Connect PIR sensor's signal port to 2, power port to 5V and ground port to GND 11 | # CODE 12 | ``` 13 | void setup() 14 | { 15 | pinMode(2, INPUT); 16 | pinMode(13, OUTPUT); 17 | pinMode(9, OUTPUT); 18 | } 19 | void loop() 20 | { 21 | if (digitalRead(2) >= HIGH) { 22 | digitalWrite(13, HIGH); 23 | tone(9, 523, 1000); 24 | } else { 25 | digitalWrite(13, LOW); 26 | noTone(9); 27 | } 28 | delay(1); 29 | } 30 | 31 | ``` 32 | # DIAGRAM 33 | ![Diagram](/Semester-7/Cyber-Physical-Systems/images/2(c).PNG) 34 | -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/Exp_03 - Simple addition in LABVIEW.md: -------------------------------------------------------------------------------- 1 | # AIM 2 | To build a VI that performs addition of 2 no.s and display the result using labview 3 | # ALGORITHM: 4 | 1. Open labview 5 | 2. Open blank VI 6 | 3. Right click front panel window for control palette 7 | 4. Insert the numeric controls as an input from control palette 8 | 5. Right click block diagram to open function palette 9 | 6. Add the Adder tool from the numeric subpalette from function palette 10 | 7. Insert the numeric indicator as output from control palette 11 | 8. Connect all terminals in the block diagram window 12 | 9. Enter inputs in the front panel and click run to display the result 13 | # DIAGRAM 14 | ![Diagram](/Semester-7/Cyber-Physical-Systems/images/3.PNG) 15 | -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/Exp_04(a) - String Length.md: -------------------------------------------------------------------------------- 1 | # AIM 2 | To perform string length operation using embedded Components and display the result using LABVIEW 3 | # ALGORITHM: 4 | 1. Open labview 5 | 2. Open blank VI 6 | 3. Right click front panel window for control palette 7 | 4. Insert the numeric controls as an input from control palette 8 | 5. Right click block diagram to open function palette 9 | 6. Add the Adder tool from the numeric subpalette from function palette 10 | 7. Insert the numeric indicator as output from control palette 11 | 8. Connect all terminals in the block diagram window 12 | 9. Enter inputs in the front panel and click run to display the result 13 | # DIAGRAM 14 | ![Diagram](/Semester-7/Cyber-Physical-Systems/images/4(a).PNG) 15 | -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/Exp_04(b) - String Concatenation.md: -------------------------------------------------------------------------------- 1 | # AIM 2 | To perform string concatenation operation using embedded Components and display the result using LABVIEW 3 | # ALGORITHM: 4 | 1. Open labview 5 | 2. Open blank VI 6 | 3. Right click front panel window for control palette 7 | 4. Insert the numeric controls as an input from control palette 8 | 5. Right click block diagram to open function palette 9 | 6. Add the Adder tool from the numeric subpalette from function palette 10 | 7. Insert the numeric indicator as output from control palette 11 | 8. Connect all terminals in the block diagram window 12 | 9. Enter inputs in the front panel and click run to display the result 13 | # DIAGRAM 14 | ![Diagram](/Semester-7/Cyber-Physical-Systems/images/4(b).PNG) 15 | -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/Exp_04(c) - Substring.md: -------------------------------------------------------------------------------- 1 | # AIM 2 | To build a VI that reeturns the substring of the input string beginning at offset and containing length number of characters 3 | # ALGORITHM: 4 | 1. Open labview 5 | 2. Open blank VI 6 | 3. Right click front panel window for control palette 7 | 4. Insert the numeric controls as an input from control palette 8 | 5. Right click block diagram to open function palette 9 | 6. Add the Adder tool from the numeric subpalette from function palette 10 | 7. Insert the numeric indicator as output from control palette 11 | 8. Connect all terminals in the block diagram window 12 | 9. Enter inputs in the front panel and click run to display the result 13 | # DIAGRAM 14 | ![Diagram](/Semester-7/Cyber-Physical-Systems/images/4(c).PNG) 15 | -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/Exp_05 - LED ON OFF Switch.md: -------------------------------------------------------------------------------- 1 | # AIM 2 | To perform LED ON/OFF switch using LABVIEW Software 3 | # ALGORITHM: 4 | 1. Open labview 5 | 2. Open blank VI 6 | 3. Right click front panel window for control palette 7 | 4. Insert the numeric controls as an input from control palette 8 | 5. Right click block diagram to open function palette 9 | 6. Add the Adder tool from the numeric subpalette from function palette 10 | 7. Insert the numeric indicator as output from control palette 11 | 8. Connect all terminals in the block diagram window 12 | 9. Enter inputs in the front panel and click run to display the result 13 | # DIAGRAM 14 | ![Diagram](/Semester-7/Cyber-Physical-Systems/images/5.PNG) 15 | -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/Exp_06 - Traffic Signal Lights.md: -------------------------------------------------------------------------------- 1 | # AIM 2 | To design traffic signals light using embedded components using LABVIEW software. 3 | # ALGORITHM: 4 | 1. Open labview 5 | 2. Open blank VI 6 | 3. Right click front panel window for control palette 7 | 4. Insert the numeric controls as an input from control palette 8 | 5. Right click block diagram to open function palette 9 | 6. Add the Adder tool from the numeric subpalette from function palette 10 | 7. Insert the numeric indicator as output from control palette 11 | 8. Connect all terminals in the block diagram window 12 | 9. Enter inputs in the front panel and click run to display the result 13 | # DIAGRAM 14 | ![Diagram](/Semester-7/Cyber-Physical-Systems/images/6.PNG) 15 | -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/images/1(a).PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Killbot2614/Programming-Lab/56efabcd724b9dcad1b3898b17e176130f11cf97/Semester-7/Cyber-Physical-Systems/images/1(a).PNG -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/images/1(b).PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Killbot2614/Programming-Lab/56efabcd724b9dcad1b3898b17e176130f11cf97/Semester-7/Cyber-Physical-Systems/images/1(b).PNG -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/images/1(c).PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Killbot2614/Programming-Lab/56efabcd724b9dcad1b3898b17e176130f11cf97/Semester-7/Cyber-Physical-Systems/images/1(c).PNG -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/images/2(a).PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Killbot2614/Programming-Lab/56efabcd724b9dcad1b3898b17e176130f11cf97/Semester-7/Cyber-Physical-Systems/images/2(a).PNG -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/images/2(b.).PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Killbot2614/Programming-Lab/56efabcd724b9dcad1b3898b17e176130f11cf97/Semester-7/Cyber-Physical-Systems/images/2(b.).PNG -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/images/2(c).PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Killbot2614/Programming-Lab/56efabcd724b9dcad1b3898b17e176130f11cf97/Semester-7/Cyber-Physical-Systems/images/2(c).PNG -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/images/3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Killbot2614/Programming-Lab/56efabcd724b9dcad1b3898b17e176130f11cf97/Semester-7/Cyber-Physical-Systems/images/3.PNG -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/images/4(a).PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Killbot2614/Programming-Lab/56efabcd724b9dcad1b3898b17e176130f11cf97/Semester-7/Cyber-Physical-Systems/images/4(a).PNG -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/images/4(b).PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Killbot2614/Programming-Lab/56efabcd724b9dcad1b3898b17e176130f11cf97/Semester-7/Cyber-Physical-Systems/images/4(b).PNG -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/images/4(c).PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Killbot2614/Programming-Lab/56efabcd724b9dcad1b3898b17e176130f11cf97/Semester-7/Cyber-Physical-Systems/images/4(c).PNG -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/images/5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Killbot2614/Programming-Lab/56efabcd724b9dcad1b3898b17e176130f11cf97/Semester-7/Cyber-Physical-Systems/images/5.PNG -------------------------------------------------------------------------------- /Semester-7/Cyber-Physical-Systems/images/6.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Killbot2614/Programming-Lab/56efabcd724b9dcad1b3898b17e176130f11cf97/Semester-7/Cyber-Physical-Systems/images/6.PNG --------------------------------------------------------------------------------