├── .github └── workflows │ └── c-cpp.yml ├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── launch.json └── tasks.json ├── Assignments ├── .vscode │ └── tasks.json ├── assignment_2_p1.c ├── assignment_2_p2.c ├── assignment_3_p1.c ├── assignment_3_p2.c ├── assignment_3_p3.c └── assignment_3_p4.c ├── C ├── In class codes └── arrays │ ├── counting_arr.c │ ├── reversing_arr.c │ ├── scan_n_print_2d_arr.c │ └── taking_input_arr.c ├── Interesting problems ├── Interesting_P2.c ├── Interesting_p1.c ├── Mem_Location_arr.c ├── counting_whitespaces.c ├── interesting_p3.c ├── str_repeat.c └── this also works.c ├── LICENSE ├── Lab Files ├── Array sorting with xor.c ├── Array_2d.c ├── Check_upper_lower.c ├── Factorial.c ├── Float_limits.c ├── Matrix_mul.c ├── Pattern_Printing.c ├── PnC_nCr.c ├── Prime_num.c ├── Swapping_With_Pointers.c ├── addition_in_arr.c ├── area_of_circle.c ├── area_of_triangle.c ├── armstrong_number.c ├── array_P1.c ├── array_of_strings.c ├── average_testing.c ├── converting_string_lowerC.c ├── even_odd.c ├── factorial_recursion.c ├── faren_to_celc.c ├── fibonacci.c ├── fibonaci_recursion.c ├── just_another_test.c ├── malloc_basics.c ├── ok.c ├── pyramid.c ├── simple_interest.c ├── string_Arr.c ├── string_concat.c ├── string_length.c ├── string_rev_cmp.c ├── swapping.c └── table.c ├── Problems from Dietel book ├── chap_2_p2.16.c ├── chap_2_p2.17.c ├── chap_2_p2.18.c ├── chap_2_p2.19.c ├── chap_2_p2.20.c ├── chap_2_p2.23.c ├── chap_2_p2.26.c ├── chap_2_p2.27.c ├── chap_2_p2.3.c └── chap_2_p2.30.c ├── README.md └── abhinav.h /.github/workflows/c-cpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: configure 17 | run: ./configure 18 | - name: make 19 | run: make 20 | - name: make check 21 | run: make check 22 | - name: make distcheck 23 | run: make distcheck 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "defines": [ 9 | "_DEBUG", 10 | "UNICODE", 11 | "_UNICODE" 12 | ], 13 | "windowsSdkVersion": "10.0.22000.0", 14 | "cStandard": "c23", 15 | "cppStandard": "c++17", 16 | "compilerPath": "C:/MinGW/bin/g++.exe" 17 | } 18 | ], 19 | "version": 4 20 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "(gdb) Bash on Windows Attach", 5 | "type": "cppdbg", 6 | "request": "attach", 7 | "program": "enter program name, for example ${workspaceFolder}/a.exe", 8 | "processId": "${command:pickRemoteProcess}", 9 | "pipeTransport": { 10 | "debuggerPath": "/usr/bin/gdb", 11 | "pipeProgram": "${env:windir}\\system32\\bash.exe", 12 | "pipeArgs": ["-c"], 13 | "pipeCwd": "" 14 | }, 15 | "setupCommands": [ 16 | { 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | }, 21 | { 22 | "description": "Set Disassembly Flavor to Intel", 23 | "text": "-gdb-set disassembly-flavor intel", 24 | "ignoreFailures": true 25 | } 26 | ] 27 | }, 28 | 29 | { 30 | "name": "C/C++: gcc.exe build and debug active file", 31 | "type": "cppdbg", 32 | "request": "launch", 33 | "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", 34 | "args": [], 35 | "stopAtEntry": false, 36 | "cwd": "${fileDirname}", 37 | "environment": [], 38 | "externalConsole": false, 39 | "MIMode": "gdb", 40 | "miDebuggerPath": "gdb.exe", 41 | "setupCommands": [ 42 | { 43 | "description": "Enable pretty-printing for gdb", 44 | "text": "-enable-pretty-printing", 45 | "ignoreFailures": true 46 | }, 47 | { 48 | "description": "Set Disassembly Flavor to Intel", 49 | "text": "-gdb-set disassembly-flavor intel", 50 | "ignoreFailures": true 51 | } 52 | ], 53 | "preLaunchTask": "C/C++: gcc.exe build active file" 54 | } 55 | ], 56 | "version": "2.0.0" 57 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: gcc.exe build active file", 6 | "command": "C:\\msys64\\ucrt64\\bin\\gcc.exe", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /Assignments/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: gcc.exe build active file", 6 | "command": "C:\\msys64\\ucrt64\\bin\\gcc.exe", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /Assignments/assignment_2_p1.c: -------------------------------------------------------------------------------- 1 | /* Read from user ages of all students in class and 2 | save them in an array which can store floating 3 | point and find average, minimum and maximum 4 | age.*/ 5 | #include 6 | 7 | int main() { 8 | int numStudents; 9 | 10 | // yaha se number of students lenge 11 | printf("Enter the number of students: "); 12 | scanf("%d", &numStudents); 13 | 14 | // Check krenge ki number of students valid hai ki nahi 15 | if (numStudents <= 0) { 16 | printf("Invalid number of students. Exiting program.\n"); 17 | return 1; 18 | } 19 | 20 | // yaha array declare krrhe age store krne ke liye 21 | float ages[numStudents]; 22 | 23 | // Read ages 24 | printf("Enter the ages of students:\n"); 25 | for (int i = 0; i < numStudents; ++i) { 26 | printf("Student %d: ", i + 1); 27 | scanf("%f", &ages[i]); 28 | } 29 | 30 | // Calculate average age 31 | float sum = 0; 32 | for (int i = 0; i < numStudents; ++i) { 33 | sum += ages[i]; 34 | } 35 | float average = sum / numStudents; 36 | 37 | // Max aur min age find karo 38 | float minAge = ages[0]; 39 | float maxAge = ages[0]; 40 | for (int i = 1; i < numStudents; ++i) { 41 | if (ages[i] < minAge) { 42 | minAge = ages[i]; 43 | } 44 | if (ages[i] > maxAge) { 45 | maxAge = ages[i]; 46 | } 47 | } 48 | 49 | // yaha display Kara rahe 50 | printf("\nAverage Age: %.2f\n", average); 51 | printf("Minimum Age: %.2f\n", minAge); 52 | printf("Maximum Age: %.2f\n", maxAge); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Assignments/assignment_2_p2.c: -------------------------------------------------------------------------------- 1 | /* Assignment 2 problem 2 - A six faced die is rolled 600 times. Find the 2 | frequency of the occurrence of each face?*/ 3 | #include 4 | #include 5 | #include 6 | 7 | int main() { 8 | // Seed the random number generator 9 | srand(time(NULL)); 10 | 11 | // Declare an array to store the frequency of each face 12 | int frequency[6] = {0}; 13 | 14 | // Simulate rolling the die 600 times 15 | for (int i = 0; i < 600; ++i) { 16 | // Generate a random number between 1 and 6 to represent the die face 17 | int face = rand() % 6 + 1; 18 | 19 | // Increment the corresponding frequency counter 20 | frequency[face - 1]++; 21 | } 22 | 23 | // Display the results 24 | printf("Face\tFrequency\n"); 25 | for (int i = 0; i < 6; ++i) { 26 | printf("%d\t%d\n", i + 1, frequency[i]); 27 | } 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Assignments/assignment_3_p1.c: -------------------------------------------------------------------------------- 1 | /* Assignment 3 problem 1 - Store marks obtained by students in an array. 2 | Find if there is more than one student who scored 3 | same marks. Assume minimum marks obtained 4 | is 30 and maximum marks obtained is 85.*/ 5 | 6 | #include 7 | 8 | int main() { 9 | // Constants for minimum and maximum marks 10 | const int MIN_MARKS = 30; 11 | const int MAX_MARKS = 85; 12 | 13 | int numStudents; 14 | 15 | // Get the number of students 16 | printf("Enter the number of students: "); 17 | scanf("%d", &numStudents); 18 | 19 | // Check if the number of students is valid 20 | if (numStudents <= 0) { 21 | printf("Invalid number of students. Exiting program.\n"); 22 | return 1; 23 | } 24 | 25 | 26 | int marks[numStudents]; 27 | 28 | // Read marks from the user ok 29 | printf("Enter the marks of students:\n"); 30 | for (int i = 0; i < numStudents; ++i) { 31 | printf("Student %d: ", i + 1); 32 | scanf("%d", &marks[i]); 33 | 34 | // Check if marks are within the valid range 35 | if (marks[i] < MIN_MARKS || marks[i] > MAX_MARKS) { 36 | printf("Invalid marks. Marks should be between %d and %d.\n", MIN_MARKS, MAX_MARKS); 37 | return 1; 38 | } 39 | } 40 | 41 | // Check for students with the same marks 42 | int foundDuplicate = 0; 43 | for (int i = 0; i < numStudents - 1; ++i) { 44 | for (int j = i + 1; j < numStudents; ++j) { 45 | if (marks[i] == marks[j]) { 46 | foundDuplicate = 1; 47 | printf("Students %d and %d scored the same marks: %d\n", i + 1, j + 1, marks[i]); 48 | } 49 | } 50 | } 51 | 52 | if (!foundDuplicate) { 53 | printf("No students scored the same marks.\n"); 54 | } 55 | 56 | return 0; 57 | } -------------------------------------------------------------------------------- /Assignments/assignment_3_p2.c: -------------------------------------------------------------------------------- 1 | // assignment - 03 - problem 3 - print the transpose of matrix 2 | 3 | #include 4 | 5 | // transpose krvane ke liye functions 6 | void transposeMatrix(int rows, int cols, int mat[rows][cols], int result[cols][rows]) { 7 | for (int i = 0; i < rows; i++) { 8 | for (int j = 0; j < cols; j++) { 9 | result[j][i] = mat[i][j]; 10 | } 11 | } 12 | } 13 | 14 | // matrix dikhane ke liye function 15 | void displayMatrix(int rows, int cols, int mat[rows][cols]) { 16 | for (int i = 0; i < rows; i++) { 17 | for (int j = 0; j < cols; j++) { 18 | printf("%d\t", mat[i][j]); 19 | } 20 | printf("\n"); 21 | } 22 | } 23 | 24 | int main() { 25 | int rows, cols; 26 | 27 | // yaha humlog matrix ka size inpuit krva rahe hai like n x m wala 28 | printf("Enter the number of rows: "); 29 | scanf("%d", &rows); 30 | 31 | printf("Enter the number of columns: "); 32 | scanf("%d", &cols); 33 | 34 | int matrix[rows][cols]; 35 | int result[cols][rows]; 36 | 37 | // yaha humlog matrix ke elements input krva rahe hai 38 | printf("Enter matrix elements:\n"); 39 | for (int i = 0; i < rows; i++) { 40 | for (int j = 0; j < cols; j++) { 41 | printf("Enter element at position (%d, %d): ", i + 1, j + 1); 42 | scanf("%d", &matrix[i][j]); 43 | } 44 | } 45 | 46 | // functions jo banaye they ups uski help se hum transpose wala operation krva ke dikhayenge 47 | transposeMatrix(rows, cols, matrix, result); 48 | 49 | // yaha jo original ( jo humlog enter kiye they input me ) woh wala matrix dikhayenge 50 | printf("\nOriginal Matrix:\n"); 51 | displayMatrix(rows, cols, matrix); 52 | 53 | // yaha se matrix display krvayenge 54 | printf("\nTranspose of Matrix:\n"); 55 | displayMatrix(cols, rows, result); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /Assignments/assignment_3_p3.c: -------------------------------------------------------------------------------- 1 | // assignmemnt 03 - p3 - Add Two Matrix Using Multi-dimensional Arrays 2 | 3 | 4 | #include 5 | 6 | // Function to add two matrices 7 | void addMatrices(int rows, int cols, int mat1[rows][cols], int mat2[rows][cols], int result[rows][cols]) { 8 | for (int i = 0; i < rows; i++) { 9 | for (int j = 0; j < cols; j++) { 10 | result[i][j] = mat1[i][j] + mat2[i][j]; 11 | } 12 | } 13 | } 14 | 15 | // Function to display a matrix 16 | void displayMatrix(int rows, int cols, int mat[rows][cols]) { 17 | for (int i = 0; i < rows; i++) { 18 | for (int j = 0; j < cols; j++) { 19 | printf("%d\t", mat[i][j]); 20 | } 21 | printf("\n"); 22 | } 23 | } 24 | 25 | int main() { 26 | int rows, cols; 27 | 28 | // Input matrix dimensions 29 | printf("Enter the number of rows: "); 30 | scanf("%d", &rows); 31 | 32 | printf("Enter the number of columns: "); 33 | scanf("%d", &cols); 34 | 35 | int matrix1[rows][cols], matrix2[rows][cols], result[rows][cols]; 36 | 37 | // Input elements for the first matrix 38 | printf("Enter elements for the first matrix:\n"); 39 | for (int i = 0; i < rows; i++) { 40 | for (int j = 0; j < cols; j++) { 41 | printf("Enter element at position (%d, %d): ", i + 1, j + 1); 42 | scanf("%d", &matrix1[i][j]); 43 | } 44 | } 45 | 46 | // Input elements for the second matrix 47 | printf("Enter elements for the second matrix:\n"); 48 | for (int i = 0; i < rows; i++) { 49 | for (int j = 0; j < cols; j++) { 50 | printf("Enter element at position (%d, %d): ", i + 1, j + 1); 51 | scanf("%d", &matrix2[i][j]); 52 | } 53 | } 54 | 55 | // Add the matrices 56 | addMatrices(rows, cols, matrix1, matrix2, result); 57 | 58 | // Display the matrices 59 | printf("\nFirst Matrix:\n"); 60 | displayMatrix(rows, cols, matrix1); 61 | 62 | printf("\nSecond Matrix:\n"); 63 | displayMatrix(rows, cols, matrix2); 64 | 65 | printf("\nSum of Matrices:\n"); 66 | displayMatrix(rows, cols, result); 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /Assignments/assignment_3_p4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Function to multiply two matrices 4 | void multiplyMatrices(int rows1, int cols1, int mat1[rows1][cols1], int rows2, int cols2, int mat2[rows2][cols2], int result[rows1][cols2]) { 5 | for (int i = 0; i < rows1; i++) { 6 | for (int j = 0; j < cols2; j++) { 7 | result[i][j] = 0; 8 | for (int k = 0; k < cols1; k++) { 9 | result[i][j] += mat1[i][k] * mat2[k][j]; 10 | } 11 | } 12 | } 13 | } 14 | 15 | // Function to display a matrix 16 | void displayMatrix(int rows, int cols, int mat[rows][cols]) { 17 | for (int i = 0; i < rows; i++) { 18 | for (int j = 0; j < cols; j++) { 19 | printf("%d\t", mat[i][j]); 20 | } 21 | printf("\n"); 22 | } 23 | } 24 | 25 | int main() { 26 | int rows1, cols1, rows2, cols2; 27 | 28 | // Input dimensions for the first matrix 29 | printf("Enter the number of rows for the first matrix: "); 30 | scanf("%d", &rows1); 31 | 32 | printf("Enter the number of columns for the first matrix: "); 33 | scanf("%d", &cols1); 34 | 35 | // Input dimensions for the second matrix 36 | printf("Enter the number of rows for the second matrix: "); 37 | scanf("%d", &rows2); 38 | 39 | printf("Enter the number of columns for the second matrix: "); 40 | scanf("%d", &cols2); 41 | 42 | // Check if matrices can be multiplied 43 | if (cols1 != rows2) { 44 | printf("Matrices cannot be multiplied. Columns of the first matrix must be equal to rows of the second matrix.\n"); 45 | return 1; 46 | } 47 | 48 | int matrix1[rows1][cols1], matrix2[rows2][cols2], result[rows1][cols2]; 49 | 50 | // yaha se 1st matrix ke elemnts ko input karvayenge 51 | printf("Enter elements for the first matrix:\n"); 52 | for (int i = 0; i < rows1; i++) { 53 | for (int j = 0; j < cols1; j++) { 54 | printf("Enter element at position (%d, %d): ", i + 1, j + 1); 55 | scanf("%d", &matrix1[i][j]); 56 | } 57 | } 58 | 59 | // yaha se 2nd matrix ke elements ko input krvayenge 60 | printf("Enter elements for the second matrix:\n"); 61 | for (int i = 0; i < rows2; i++) { 62 | for (int j = 0; j < cols2; j++) { 63 | printf("Enter element at position (%d, %d): ", i + 1, j + 1); 64 | scanf("%d", &matrix2[i][j]); 65 | } 66 | } 67 | 68 | ?? matrix multiply krvayenge 69 | multiplyMatrices(rows1, cols1, matrix1, rows2, cols2, matrix2, result); 70 | 71 | // yaha se matrix display krvayenge 72 | printf("\nFirst Matrix:\n"); 73 | displayMatrix(rows1, cols1, matrix1); 74 | 75 | printf("\nSecond Matrix:\n"); 76 | displayMatrix(rows2, cols2, matrix2); 77 | 78 | printf("\nProduct of Matrices:\n"); 79 | displayMatrix(rows1, cols2, result); 80 | 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /C: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /In class codes/arrays/counting_arr.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int arr[] = {1, 2, 3, 4, 5}; 5 | int length = sizeof(arr)/sizeof(arr[0]); 6 | printf("Number of elements present in given array: %d", length); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /In class codes/arrays/reversing_arr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int a[9] = {34,56,35,323,65,667,24,31,46}; 6 | int i; 7 | //original order 8 | for(i = 0 ; i < 9 ;i++) 9 | { 10 | printf("%d",a[i]); 11 | } 12 | printf("\n"); 13 | //reverse order 14 | for(i = 8 ; i >= 0; i--) 15 | { 16 | printf("%d",a[i]); 17 | } 18 | 19 | return 0; 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /In class codes/arrays/scan_n_print_2d_arr.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int arr[3][4]; 5 | int i, j, k; 6 | printf("Enter array element"); 7 | for(i = 0; i < 3;i++) 8 | { 9 | for(j = 0; j < 4; j++) 10 | { 11 | scanf("%d", &arr[i][j]); 12 | } 13 | } 14 | printf("Accessing Individual Elements of Two Dimensional Array : \n"); 15 | for(i = 0; i < 3; i++) 16 | { 17 | for(j = 0; j < 4; j++) 18 | { 19 | printf("%d", arr[i][j]); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /In class codes/arrays/taking_input_arr.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int arr[4]; 5 | int i, j; 6 | printf("Enter array element : "); 7 | for(i = 0; i < 4; i++) 8 | { 9 | scanf("%d", &arr[i]); //Run time array initialization 10 | } 11 | printf("Printing array element : "); 12 | for(j = 0; j < 4; j++) 13 | { 14 | printf("%d\n", arr[j]); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Interesting problems/Interesting_P2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int n; 6 | for(n = 7 ; n!=0 ; n--); 7 | printf("n = %d", n--); 8 | 9 | getchar(); 10 | 11 | return 0; 12 | } -------------------------------------------------------------------------------- /Interesting problems/Interesting_p1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define scanf "%s Geeks For Geeks" 4 | 5 | main () { 6 | printf(scanf,scanf); 7 | getchar(); 8 | return 0; 9 | 10 | } -------------------------------------------------------------------------------- /Interesting problems/Mem_Location_arr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a; 5 | printf("Enter the number of elements you want in array : "); 6 | scanf("%d",&a); 7 | 8 | int arr[a]; 9 | 10 | for(int i = 0 ; i < a ; i++) 11 | { 12 | printf("Memory location for the index number %d is : %d ", i , &arr[i]); 13 | printf("\n"); 14 | } 15 | 16 | printf("The size of the given array is %d bytes.\n The size of each array unit is %d", sizeof(arr[a])*a,sizeof(arr[a])); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Interesting problems/counting_whitespaces.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int count_whitespace(char *string) 5 | { 6 | 7 | int length = strlen(string); 8 | int count = 0; 9 | for (int i = 0; i < length; i++) 10 | { 11 | 12 | if (isspace(string[i])) 13 | { 14 | 15 | count++; 16 | } 17 | } 18 | return count; 19 | } 20 | int main() 21 | { 22 | char string[] = "line 1\n 2\n\tline 3"; 23 | int count = count_whitespace(string); 24 | 25 | printf("Total whitespace characters :%d\n", count); 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Interesting problems/interesting_p3.c: -------------------------------------------------------------------------------- 1 | // problem statement - counting the number of occurences in an array 2 | 3 | #include 4 | int occurrences( int array[] , int length, int to_find) 5 | { 6 | 7 | int count = 0; 8 | 9 | 10 | for (int i = 0; i < length; i++) 11 | { 12 | if (abhi[i] == to_find) 13 | count++; 14 | } 15 | } 16 | int main() 17 | { 18 | 19 | int abhi[] = {4, 9, 7, 6, 5, 8, 3, 2, 1, 5}; 20 | 21 | printf("# of 5s found : %d \n", count); 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Interesting problems/str_repeat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | char *repeat(char *string, int repeats); 6 | 7 | int main() 8 | { 9 | char str[100]; 10 | gets(str); 11 | 12 | int length = strlen(str)/4; 13 | 14 | int itr; 15 | printf("How many times you want to repeat the string : "); 16 | scanf("%d", &itr); 17 | 18 | int f_length = length * itr; 19 | 20 | char repeat_string[f_length]; 21 | 22 | sprintf(repeat_string, "%s%s", str); 23 | 24 | for (int i = 0; i < itr; i++) 25 | { 26 | 27 | printf("%s", repeat_string); 28 | } 29 | 30 | return 0; 31 | } 32 | 33 | 34 | char *repeat(char *string, int repeats) 35 | { 36 | 37 | } -------------------------------------------------------------------------------- /Interesting problems/this also works.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int arr[8]={1,2,3,4,5,6,7,0}; 5 | 6 | for(int i = 0 ; i < 8 ; i++) 7 | { 8 | printf("%s : %d \n","Okay here it is ", i[arr]); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Lab Files/Array sorting with xor.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int arr[100],i,j,n; 5 | printf("Enter the number of element in array you want:"); 6 | scanf("%d",&n); 7 | for(i=0;iarr[j]){ 17 | arr[i]=arr[i]^arr[j]; 18 | arr[j]=arr[i]^arr[j]; 19 | arr[i]=arr[i]^arr[j]; 20 | } 21 | } 22 | } 23 | printf("The given array is sorted in ascending order as follows : "); 24 | for(i=0;i 4 | 5 | int main () { 6 | 7 | int row ; 8 | int column; 9 | 10 | printf(" Enter row size : "); 11 | scanf("%d", &row); 12 | 13 | printf("Enter column size : "); 14 | scanf("%d", &column); 15 | 16 | int arr[row][column]; 17 | 18 | for (int i = 0; i < row; i++) 19 | { 20 | for (int j = 0; j < column; j++) 21 | { 22 | printf(" enter arr[%d][%d] : ",i,j); 23 | scanf(" %d ", &arr[i][j]); 24 | 25 | } 26 | printf("\n"); 27 | } 28 | 29 | printf(" THe elements of array elemets are : \n"); 30 | for (int i = 0; i < row; i++) 31 | { 32 | for ( int j = 0; j < column; j++) 33 | { 34 | printf("%d \t", arr[i][j]); 35 | } 36 | printf("\n"); 37 | } 38 | return 0; 39 | 40 | } -------------------------------------------------------------------------------- /Lab Files/Check_upper_lower.c: -------------------------------------------------------------------------------- 1 | // To check if the given string is upper or lower case 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main() 8 | { 9 | char s[] = " This IS tHe WaY"; 10 | 11 | int length = strlen(s); 12 | 13 | for (int i = 0; i < length; i++) 14 | { 15 | printf("%c", s[i]); 16 | if(isupper(s[i])) printf("\tupper\n"); 17 | else if(islower(s[i])) 18 | printf("\tlower\n"); 19 | 20 | else printf("\n"); 21 | } 22 | 23 | 24 | return 0; 25 | 26 | } -------------------------------------------------------------------------------- /Lab Files/Factorial.c: -------------------------------------------------------------------------------- 1 | //factorial 2 | 3 | #include 4 | 5 | int main() { 6 | 7 | int a; 8 | scanf("%d",&a); 9 | 10 | for (int i = a-1; i > 0; i--) 11 | { 12 | a = a*i; 13 | 14 | } 15 | printf("%d",a); 16 | return 0; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Lab Files/Float_limits.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("Minimum float value = %e\n", FLT_MIN); 6 | printf("Maximum float value = %e\n", FLT_MAX); 7 | printf("Size of float in bytes = %zu\n", sizeof(float)); 8 | 9 | printf("Minimum double value = %e\n", DBL_MIN); 10 | printf("Maximum double value = %e\n", DBL_MAX); 11 | printf("Size of double in bytes = %zu\n \t", sizeof(double)); 12 | 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /Lab Files/Matrix_mul.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void multiplyMatrices(int a[3][3], int b[3][3], int result[3][3]) { 4 | for(int i=0; i<3; i++) 5 | for(int j=0; j<3; j++) 6 | for(int k=0; k<3; k++) 7 | result[i][j] += a[i][k] * b[k][j]; 8 | } 9 | 10 | int main() { 11 | int matrixA[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 12 | int matrixB[3][3] = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}; 13 | int result[3][3] = {{0}}; 14 | 15 | multiplyMatrices(matrixA, matrixB, result); 16 | 17 | printf("Resultant Matrix:\n"); 18 | for(int i=0; i<3; i++) { 19 | for(int j=0; j<3; j++) 20 | printf("%d\t", result[i][j]); 21 | printf("\n"); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Lab Files/Pattern_Printing.c: -------------------------------------------------------------------------------- 1 | //Printing Right angle triangle with star 2 | #include 3 | int main() 4 | { 5 | int a,b,i; 6 | printf("Enter the no. of rows of triangle="); 7 | scanf("%d",&i); 8 | for(a=1;a<=i;a++) 9 | { 10 | for(b=1;b<=a;b++) 11 | { 12 | printf("* "); 13 | } 14 | 15 | printf("\n"); 16 | } 17 | } -------------------------------------------------------------------------------- /Lab Files/PnC_nCr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int fact(int n) 4 | { 5 | int f = 1; 6 | for (int i = 1; i <= n; i++) 7 | { 8 | 9 | f *= i; 10 | } 11 | return f; 12 | } 13 | int ncr(int n, int r) 14 | { 15 | return fact(n) / (fact(r) * fact(n - r)); 16 | } 17 | 18 | int main() 19 | { 20 | 21 | int n; 22 | printf("enter n : "); 23 | scanf("%d", &n); 24 | int r; 25 | printf("enter r : "); 26 | scanf("%d", &r); 27 | int ans = ncr(n, r); 28 | printf("%d", ans); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Lab Files/Prime_num.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main () { 5 | 6 | int a; 7 | 8 | printf("Enter the number"); 9 | scanf("%d",&a); 10 | 11 | if(a == 1 || a == 0 || a < 0) 12 | printf("not defined"); 13 | else 14 | { 15 | for( int i = sqrt(a) ; i >=2 ; i--) { 16 | if(a % i == 0 ){ 17 | printf("Given Number is not prime ."); 18 | break; 19 | } 20 | else{ 21 | printf("Given number is prime."); 22 | break; 23 | } 24 | } 25 | } 26 | return 0; 27 | } 28 | 29 | // happy new year 🎊 -------------------------------------------------------------------------------- /Lab Files/Swapping_With_Pointers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void swap(int *x, int *y) 4 | { 5 | int temp = *x; 6 | *x = *y; 7 | *y = temp; 8 | } 9 | 10 | int main() 11 | { 12 | int x; 13 | printf("Give the number x : "); 14 | scanf("%d", &x); 15 | int y; 16 | printf("Give the number y : "); 17 | scanf("%d", &y); 18 | printf("Here are the number you entered : %d , %d\n", x, y); 19 | swap(&x, &y); 20 | printf("Here are the swapped values of x & y : %d , %d\n ", x, y); 21 | } 22 | -------------------------------------------------------------------------------- /Lab Files/addition_in_arr.c: -------------------------------------------------------------------------------- 1 | #include 2 | void add_one(int array[] , int length); 3 | 4 | int main(void) 5 | 6 | { 7 | int arr[] = {2,3,4,5,6,7}; 8 | add_one(arr,6); 9 | for (int i = 0; i < 6; i++) 10 | { 11 | printf("a[%d] = %d\n", i ,arr[i]); 12 | } 13 | 14 | 15 | return 0; 16 | } 17 | 18 | void add_one(int array[] , int length) 19 | { 20 | for (int i = 0 ; i < length ; i++) 21 | array[i]++; 22 | } -------------------------------------------------------------------------------- /Lab Files/area_of_circle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define PI 3.14 3 | int main() 4 | { 5 | float a,r,p; 6 | printf("enter the value of radius :"); 7 | scanf("%f",&r); 8 | a = PI*r*r; 9 | p = 2*PI*r; 10 | printf("The area of circle is %f and perimeter is %f",a,p); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /Lab Files/area_of_triangle.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | float a,b,h; 5 | printf("Enter the value of base : "); 6 | scanf("%f",&b); 7 | printf("enter the value of height :"); 8 | scanf("%f",&h); 9 | a=0.5*b*h; 10 | printf("The area of the triangle is : %f",a); 11 | 12 | return 0; 13 | } -------------------------------------------------------------------------------- /Lab Files/armstrong_number.c: -------------------------------------------------------------------------------- 1 | /* #include> 2 | 3 | int main(){ 4 | 5 | int num,r,sum = 0 , temp ; 6 | 7 | printf("enter any number : "); 8 | scanf("%d",&num); 9 | 10 | for ( temp = num ; num != 0; num = num/10) 11 | { 12 | r = num % 10 ; 13 | sum = sum + (r*r*r); 14 | 15 | } 16 | 17 | if (sum == temp) 18 | printf("%d is an armstrong number "); 19 | else 20 | printf("%d is not an armstrong number"); 21 | 22 | return 0; 23 | 24 | 25 | } */ 26 | 27 | #include 28 | #include 29 | 30 | int main() { 31 | int num, originalNum, remainder, n = 0; 32 | float result = 0.0; 33 | 34 | printf("Enter an integer: "); 35 | scanf("%d", &num); 36 | 37 | originalNum = num; 38 | 39 | // store the number of digits of num in n 40 | for (originalNum = num; originalNum != 0; ++n) { 41 | originalNum /= 10; 42 | } 43 | 44 | for (originalNum = num; originalNum != 0; originalNum /= 10) { 45 | remainder = originalNum % 10; 46 | 47 | // store the sum of the power of individual digits in result 48 | result += pow(remainder, n); 49 | } 50 | 51 | // if num is equal to result, the number is an Armstrong number 52 | if ((int)result == num) 53 | printf("%d is an Armstrong number.", num); 54 | else 55 | printf("%d is not an Armstrong number.", num); 56 | return 0; 57 | } -------------------------------------------------------------------------------- /Lab Files/array_P1.c: -------------------------------------------------------------------------------- 1 | //WAP to represent an array of 10 integers value from the user and print the sum of each elements in the array. 2 | 3 | #include 4 | 5 | int main () { 6 | 7 | int a[10],i,s=0; 8 | 9 | for(i = 1 ; i <= 10 ; i++) { 10 | 11 | printf("enter the no. %d ", i); 12 | scanf("%d",&a[i]); 13 | s = s + a[i]; 14 | } 15 | printf(" \nSum of the integer number is : %d",s); 16 | 17 | return 0; 18 | 19 | } -------------------------------------------------------------------------------- /Lab Files/array_of_strings.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | char *days[7]; 5 | char TheDay[10]; 6 | int day; 7 | days[0] = "Sunday"; 8 | days[1] = "Monday"; 9 | days[2] = "Tuesday"; 10 | days[3] = "Wednesday"; 11 | days[4] = "Thursday"; 12 | days[5] = "Friday"; 13 | days[6] = "Saturday"; 14 | printf("Please enter a day: "); 15 | scanf("%9s", TheDay); 16 | day = 0; 17 | while ((day < 7) && (!samestring(TheDay, days[day]))) 18 | day++; 19 | if (day < 7) 20 | printf("%s is day %d.\n", TheDay, day); 21 | else 22 | printf("No day %s!\n", TheDay); 23 | } 24 | int samestring(char *s1, char *s2) { 25 | int i; 26 | if (strlen(s1) !=strlen(s2)) 27 | return 0; 28 | for (i = 0;i< strlen(s1); i++) 29 | if (s1[i] != s2[i]) 30 | return 0; 31 | return 1; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Lab Files/average_testing.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main (){ 3 | int a , b , c , sum , avg; 4 | printf("Give the input for number a :"); 5 | scanf("%d",&a); 6 | printf("give the input for number b : "); 7 | scanf("%d",&b); 8 | printf("give the input for number c :"); 9 | scanf("%d",&c); 10 | sum = a+b+c; 11 | avg=(a+b+c)/3; 12 | printf("The sum of the given numbers are : %d\n",sum); 13 | printf("\nthe average of the given numbers are : %d", avg); 14 | printf("\nthank you"); 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Lab Files/converting_string_lowerC.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | char s[] = " This IS tHe WaY"; 8 | int count = strlen(s); 9 | for(int i = 0 ; i < count ; i++ ) { 10 | s[i] = tolower(s[i]); 11 | } 12 | 13 | printf("Your given string is now converted into lowercase :- \n\t %s",s); 14 | /* 15 | int length = strlen(s); 16 | 17 | for (int i = 0; i < length; i++) 18 | { 19 | printf("%c", s[i]); 20 | if(isupper(s[i])) printf("\tupper\n"); 21 | else if(islower(s[i])) 22 | printf("\tlower\n"); 23 | 24 | else printf("\n"); 25 | } 26 | */ 27 | 28 | return 0; 29 | 30 | } -------------------------------------------------------------------------------- /Lab Files/even_odd.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main () { 4 | int n; 5 | printf(" Enter the number :"); 6 | scanf("%d",&n); 7 | if (n==0 || n==1 || n<0) 8 | { 9 | printf("This is invalid input , kindly dont give negative/zero/unity "); 10 | 11 | } 12 | 13 | 14 | else if (n%2==0) 15 | { 16 | printf("this is even"); 17 | } 18 | else 19 | printf("This is odd"); 20 | 21 | 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Lab Files/factorial_recursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fact(int n) { 3 | if(n == 1 || n == 0){return 1;} 4 | int fact1 = fact(n-1); 5 | int FactN = fact1 * n; 6 | 7 | return FactN; 8 | 9 | } 10 | int main() 11 | { 12 | int x; 13 | scanf("%d",&x); 14 | printf("factorial is : %d", fact(x)); 15 | } -------------------------------------------------------------------------------- /Lab Files/faren_to_celc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | float c,f; 5 | printf("enter the value of celcius :"); 6 | scanf("%f", &c); 7 | f = (c*0.5555)+32; 8 | printf("Here is the result in fahrenheit : %f",f); 9 | 10 | 11 | return 0; 12 | } -------------------------------------------------------------------------------- /Lab Files/fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int n1= 0 , n2 = 1 , n3 , i , number; 5 | printf("%s ","Enter the number of terms you want : "); 6 | scanf("%d",&number); 7 | for ( i = 2; i < number; i++) 8 | { 9 | n3 = n1+n2; 10 | printf("%s : %d ","here it is ", n3); 11 | n1 = n2; 12 | n2 = n3; 13 | } 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Lab Files/fibonaci_recursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | void printFibonacci(int n){ 3 | static int n1=0,n2=1,n3; 4 | if(n>0){ 5 | n3 = n1 + n2; 6 | n1 = n2; 7 | n2 = n3; 8 | printf("%d ",n3); 9 | printFibonacci(n-1); 10 | } 11 | } 12 | int main(){ 13 | int n; 14 | printf("Enter the number of elements: "); 15 | scanf("%d",&n); 16 | printf("Fibonacci Series: "); 17 | printf("%d %d ",0,1); 18 | printFibonacci(n-2);//n-2 because 2 numbers are already printed 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Lab Files/just_another_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a=9,b=-9,c= 89U; 6 | long int d= 99998L; 7 | printf("Integer value with positive data : %d\nInteger value with negative data : %d\nInteger value with an unsigned int data : %u\nInteger value with an long int data : %ld",a,b,c,d); 8 | 9 | 10 | return 0; 11 | } -------------------------------------------------------------------------------- /Lab Files/malloc_basics.c: -------------------------------------------------------------------------------- 1 | // WAP to dynamically allocate a memory and then access each element and assign a value and then print them. 2 | 3 | #include 4 | #include 5 | int main() { 6 | int *a; 7 | a = malloc(sizeof(int)*5); 8 | for (int i = 0; i < 5; i++) 9 | { 10 | printf(" Enter the element at the index no.[%d] \n",i); 11 | scanf("%d",&a[i]); 12 | } 13 | for (int i = 0; i < 5; i++) 14 | { 15 | printf("The element at the index no.[%d] is : %d \n", i , a[i]); 16 | } 17 | 18 | 19 | free(a); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Lab Files/ok.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | float a,b; 5 | int ch,c,d; 6 | printf("1.Sum\n2.Subtraction\n3.Division\n4.Remainder\nEnter your choice:"); 7 | scanf("%d",&ch); 8 | if(ch==1) 9 | { 10 | printf("Enter 1st no. to add:"); 11 | scanf("%f",&a); 12 | printf("Enter 2nd no. to add:"); 13 | scanf("%f",&b); 14 | printf("yor required sum is:%f",a+b); 15 | } 16 | else if(ch==2) 17 | { 18 | printf("Enter 1st no. to subtract:"); 19 | scanf("%f",&a); 20 | printf("Enter 2nd no. to subtract:"); 21 | scanf("%f",&b); 22 | printf("yor required sum is:%f",a-b); 23 | 24 | } 25 | else if(ch==3) 26 | { 27 | printf("Enter 1st no. :"); 28 | scanf("%f",&a); 29 | printf("Enter 2nd no. :"); 30 | scanf("%f",&b); 31 | if(b==0){ 32 | printf("Division not possible"); 33 | } 34 | else{ 35 | printf("yor required division is:%f",a/b); 36 | } 37 | } 38 | else if(ch==4) 39 | { 40 | printf("Enter 1st no. :"); 41 | scanf("%d",&c); 42 | printf("Enter 2nd no. :"); 43 | scanf("%d",&d); 44 | if(b==0){ 45 | printf("Division not possible"); 46 | } 47 | else{ 48 | printf("yor required remainder is:%d",c%d); 49 | } 50 | } 51 | else{ 52 | printf("Invalid number"); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /Lab Files/pyramid.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a, b, r, c = 0; 5 | printf("Enter no. of rows = "); 6 | scanf("%d", &r); 7 | for (a = 1; a <= r; ++a, c = 0) 8 | { 9 | for (b = 1; b <= (r - a); ++b) 10 | { 11 | printf(" "); 12 | } 13 | while (c != (2 * a) - 1) 14 | { 15 | printf("*"); 16 | ++c; 17 | } 18 | printf("\n"); 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Lab Files/simple_interest.c: -------------------------------------------------------------------------------- 1 | /* A simple SI program in the lab*/ 2 | 3 | #include 4 | 5 | int main() { 6 | 7 | float principal,ror,time,si, amount; 8 | 9 | printf(" Enter the principal amount :"); 10 | scanf("%f",&principal); 11 | 12 | printf(" Enter the rate of interest:"); 13 | scanf("%f",&ror); 14 | 15 | printf(" Enter the time required :"); 16 | scanf("%f",&time); 17 | 18 | si = (principal*ror*time)/100; 19 | amount = si + principal; 20 | 21 | printf("The simple interest of for the given data is %f and the final amount would be %f",si,amount); 22 | 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Lab Files/string_Arr.c: -------------------------------------------------------------------------------- 1 | /*Problem Statement :- 2 | Input a string or sentence and then find the number of characters in it including whitespaces and hence thake input to find a specific number of occurences in that sentence of a particular character 3 | */ 4 | #include 5 | #include 6 | 7 | int main() 8 | { 9 | char s1[100] ; 10 | puts("Give the required string :-"); 11 | gets(s1); 12 | 13 | int length = strlen(s1); 14 | int num_is = 0; 15 | 16 | char k; 17 | printf("Give the character of which you want the occurences : "); 18 | scanf("%c",&k); 19 | 20 | for (int i = 0; i < length; i++) 21 | if(s1[i] == k) num_is++; 22 | 23 | printf("The length is : %d\n",length); 24 | printf("Number of i in the string is : %d\n ", num_is); 25 | 26 | return 0; 27 | 28 | } -------------------------------------------------------------------------------- /Lab Files/string_concat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char s1[50] = "The first sentence\t"; 7 | 8 | char s2[] = " the second sentence\t"; 9 | 10 | strcat(s1,s2); // strcat = string concatenation 11 | 12 | printf("s1 : %s\n", s1); 13 | 14 | printf("s2 : %s\n", s2); 15 | 16 | 17 | return 0; 18 | 19 | } -------------------------------------------------------------------------------- /Lab Files/string_length.c: -------------------------------------------------------------------------------- 1 | // FIND THE LENGTH OF THE STRING USING THE POINTER. 2 | #include 3 | int main() 4 | { 5 | int strlen(char *); 6 | char str[100]; 7 | char *p; 8 | p=str; 9 | printf("Enter the string..?\n"); 10 | gets(str); 11 | int x=strlen(p); 12 | printf("Length of string is=%d\n",x); 13 | 14 | 15 | } 16 | int strlen(char *p) 17 | { 18 | int c=0; 19 | while(*p!='\0') 20 | { 21 | c++; 22 | *p++; 23 | } 24 | return(c); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Lab Files/string_rev_cmp.c: -------------------------------------------------------------------------------- 1 | // WAP to check f the given string is pallindrome or not 2 | 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | char s1[] = "madam"; 9 | 10 | char s2[] = "madam"; 11 | 12 | if (strcmp(s1, strrev(s2)) == 0) 13 | { 14 | printf("Yes they are pallindrome"); 15 | } 16 | 17 | else 18 | printf("No they are not"); 19 | 20 | 21 | 22 | return 0; 23 | 24 | } -------------------------------------------------------------------------------- /Lab Files/swapping.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main () { 4 | 5 | int x,y; 6 | printf("enter the number x :"); 7 | scanf("%d",&x); 8 | printf("enter the number y :"); 9 | scanf("%d",&y); 10 | x = x + y; 11 | y = x - y; 12 | x = x - y; 13 | 14 | printf(" The swapped values of x is : %d \n The swapped values of y is : %d", x , y); 15 | 16 | } -------------------------------------------------------------------------------- /Lab Files/table.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i,j,num; 6 | for(i=1; i<=10; i++) 7 | { 8 | 9 | num= i; 10 | for(j=1; j<=10; j++) 11 | { 12 | printf("%3d\t",(num*j)); 13 | } 14 | 15 | printf("\n"); 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Problems from Dietel book/chap_2_p2.16.c: -------------------------------------------------------------------------------- 1 | /* Problem statement 2 | Write a program that asks the user to enter two numbers, obtains them from 3 | the user and prints their sum, product, difference, quotient and remainder. 4 | */ 5 | 6 | #include 7 | 8 | int main () { 9 | int a , b; 10 | puts("Enter the first number : "); 11 | scanf("%d",&a); 12 | puts("Enter the second number : "); 13 | scanf("%d",&b); 14 | printf("%s %d\n%s %d\n%s %d\n%s %d\n%s %d\n","The Sum is : ",a+b,"The product is :",a*b,"The difference is",a-b,"The quotient is :",a/b,"The remainder is :",a%b); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Problems from Dietel book/chap_2_p2.17.c: -------------------------------------------------------------------------------- 1 | /*Problem statement 2 | Write a program than asks the user to enter the initial velocity and acceleration of an object, and the time that has elapsed, places them in the variables u, a, and t, and prints 3 | the final velocity, v, and distance traversed, s, using the following equations. 4 | a) v = u + at 5 | b) s = ut + (1/2)at^2 */ 6 | 7 | #include 8 | 9 | int main() 10 | { 11 | float v, u, a, t, s; 12 | puts("Enter the value of inital velocity :"); 13 | scanf("%f", &u); 14 | puts("Enter the value of final velocity"); 15 | scanf("%f", &v); 16 | puts("Enter the value of time taken"); 17 | scanf("%f", &t); 18 | puts("Enter the value of accln. :"); 19 | scanf("%f", &a); 20 | v = u + a * t; 21 | s = u * t + (1 / 2) * a * t * t; 22 | printf("Here is the value of final velocity : %f\n", v); 23 | printf("Here is the value of ditance travelled : %f", s); 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Problems from Dietel book/chap_2_p2.18.c: -------------------------------------------------------------------------------- 1 | /* problem statement - 2 | Write a program that asks the user to enter the highest rainfall ever in 3 | one season for a country, and the rainfall in the current year for that country, obtains the values from 4 | the user, checks if the current rainfall exceed the highest rainfall and prints an appropriate message 5 | on the screen. If the current rainfall is higher, it assigns that value as the highest rainfall ever. Use 6 | only the single-selection form of the if statement you learned in this chapter 7 | */ 8 | 9 | #include 10 | 11 | int main () { 12 | int max_rf , max_crf; // max_rf = maximum rainfall ever and max_crf = maximum rainfall in the current season 13 | puts("Enter the highest rainfall ever recorded : "); 14 | scanf("%d",&max_rf); 15 | puts("Enter the current highest rainfall recorded this season :"); 16 | scanf("%d",&max_crf); 17 | if (max_crf > max_rf) 18 | { 19 | printf("%s","This year the highest ever rainfall has been recorded breaking all the previous records"); 20 | } 21 | else 22 | printf("%s","This was yet another season the records are still on "); 23 | 24 | return 0; 25 | 26 | } -------------------------------------------------------------------------------- /Problems from Dietel book/chap_2_p2.19.c: -------------------------------------------------------------------------------- 1 | /*problem statement - 2 | Write a program that inputs three different 3 | integers from the keyboard, then prints the sum, the average, the product, the smallest and the largest of these numbers. 4 | Use only the single-selection form of the if statement you learned in this chapter. The screen dialogue should appear as follows: 5 | Enter three different integers: 13 27 14 6 | Sum is 54 7 | Average is 18 8 | Product is 4914 9 | Smallest is 13 10 | Largest is 27 11 | */ 12 | 13 | #include 14 | 15 | int main() { 16 | int num1 , num2 , num3 ; 17 | 18 | puts("Enter the first number :"); 19 | scanf("%d",&num1); 20 | puts("Enter the second number :"); 21 | scanf("%d",&num2); 22 | puts("Enter the third number :"); 23 | scanf("%d",&num3); 24 | 25 | printf("%s %d","The sum of all three numbers is :",num1 + num2 + num3); 26 | printf("\n"); 27 | printf("%s %d","The average of three numbers :",(num1 + num2 + num3)/3); 28 | printf("\n"); 29 | printf("%s %d","The product of all three number is :",(num1*num2*num3)); 30 | printf("\n"); 31 | 32 | int sml = 0 , lrg = 0; 33 | if (num1 > num2 && num1 > num3) 34 | lrg = num1; 35 | else if (num2 > num1 && num2 > num3) 36 | lrg = num2; 37 | else 38 | lrg = num3; 39 | 40 | if(num1 < num2 && num1 < num3) 41 | sml = num1; 42 | else if(num2 < num1 && num2 < num3) 43 | sml = num2; 44 | else 45 | sml = num3; 46 | 47 | printf("%s %d","The smallest of all three is :",sml); 48 | printf("\n"); 49 | printf("%s %d","The largest of all three is :",lrg); 50 | printf("\n"); 51 | 52 | return 0; 53 | } -------------------------------------------------------------------------------- /Problems from Dietel book/chap_2_p2.20.c: -------------------------------------------------------------------------------- 1 | /* problem statement - 2 | Write a program that asks the 3 | user to enter the total time elapsed, in seconds, since an event and converts the time to hours, 4 | minutes and seconds. The time should be displayed as hours:minutes:seconds. [Hint: Use the 5 | remainder operator] 6 | */ 7 | 8 | #include 9 | 10 | int main () { 11 | int hours , min , sec , a ,b ,c ,d ,e; 12 | 13 | puts("Enter the time elapsed in seconds"); 14 | scanf("%d",&a); 15 | min = a/60; 16 | sec =(int) a % 60 ; 17 | 18 | 19 | 20 | if( min >= 60){ 21 | hours = min / 60 ; 22 | min = 0; 23 | 24 | } 25 | printf("%d : %d : %d", hours , min , sec); 26 | return 0; 27 | 28 | } -------------------------------------------------------------------------------- /Problems from Dietel book/chap_2_p2.23.c: -------------------------------------------------------------------------------- 1 | /* problem statement - 2 | Write a program that reads an integer and determines and prints whether 3 | it’s odd or even. [Hint: Use the remainder operator. An even number is a multiple of two. 4 | Any multiple of two leaves a remainder of zero when divided by 2.] 5 | */ 6 | 7 | #include 8 | 9 | int main() { 10 | int num1; 11 | puts("Enter any number you want to check : "); 12 | scanf("%d",&num1); 13 | 14 | if(num1 % 2 == 0) 15 | puts("The given number is even"); 16 | else 17 | puts("The given number is not even"); 18 | 19 | return 0; 20 | 21 | } -------------------------------------------------------------------------------- /Problems from Dietel book/chap_2_p2.26.c: -------------------------------------------------------------------------------- 1 | /* problem statement - 2 | 3 | Write a program that reads in two integers and determines and prints whether 4 | the first is a multiple of the second. [Hint: Use the remainder operator. 5 | */ 6 | 7 | #include 8 | 9 | int main() { 10 | int a , b ; 11 | 12 | puts("Enter the first number :"); 13 | scanf("%d",&a); 14 | 15 | puts("Enter the second number :"); 16 | scanf("%d",&b); 17 | 18 | if(a % b == 0) 19 | printf("The first number is multiple of second number"); 20 | else 21 | printf("The given set of number are not multiple"); 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Problems from Dietel book/chap_2_p2.27.c: -------------------------------------------------------------------------------- 1 | #include 2 | void pattern(); 3 | 4 | int main () { 5 | for(int i=0;i<3;i++){pattern();} 6 | } 7 | void pattern() 8 | { 9 | for(int i=0;i<8;i++){printf("*");} 10 | printf("\n"); 11 | printf(" "); 12 | for(int i=0;i<8;i++){printf("*");} 13 | printf("\n"); 14 | } 15 | 16 | // credits - Harsh Sharma -------------------------------------------------------------------------------- /Problems from Dietel book/chap_2_p2.3.c: -------------------------------------------------------------------------------- 1 | /* problem statement :- 2 | Write a single C statement to accomplish each of the following: 3 | a) Define the variables c, thisVariable, q76354 and number to be of type int. 4 | b) Prompt the user to enter an integer. End your prompting message with a colon (:) followed by a space and leave the cursor positioned after the space. 5 | c) Read an integer from the keyboard and store the value entered in integer variable c. 6 | d) If number is not equal to 7, print "The variable number is not equal to 7." 7 | e) Print the message "This is a C program." on one line. 8 | f) Print the message "This is a C program." on two lines so that the first line ends with C. 9 | g) Print the message "This is a C program." with each word on a separate line. 10 | h) Print the message "This is a C program." with the words separated by tabs. */ 11 | 12 | //solution 13 | 14 | #include 15 | 16 | int main() { 17 | int c,thisVariable,q76354,number; 18 | printf("Enter any integer : "); 19 | scanf("%d",&c); 20 | if(number != 7){ printf("%s","The Variable is not equal to 7\n");} 21 | puts("This is a C program"); 22 | puts("This is C"); 23 | puts("Program"); 24 | printf("This\n is\n a\n C\n program\n"); 25 | printf("This\t is\t a\t c\t program\t "); 26 | 27 | } -------------------------------------------------------------------------------- /Problems from Dietel book/chap_2_p2.30.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main () { 5 | int num , arr[5] ; 6 | puts("Enter the five digit number :"); 7 | scanf("%d",&num); 8 | int r; 9 | for(int i=0;i<5;i++){ 10 | r=num%10; 11 | arr[i]=r; 12 | num = num / 10; 13 | 14 | } 15 | for(int i=4;i>=0;i--){ 16 | printf("%d ",arr[i]); 17 | } 18 | 19 | 20 | 21 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LPCC-CSVTU-sem-1 2 | I am storing all the programs which i did during LPCC course in my 1st sem at CSVTU 3 | -------------------------------------------------------------------------------- /abhinav.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void sum(int a , int b ) 8 | { 9 | printf("\nAddition of two numbers given by you is : %d\n", a + b); 10 | } 11 | 12 | void multiply(int a , int b) 13 | { 14 | printf("\nMultiplication of the two numbers given by you is : %d\n", a*b); 15 | } 16 | 17 | void divide(int a , int b) 18 | { 19 | printf("\nWhen you will divide %d by %d then the output will be %d\n",a,b,a/b); 20 | } 21 | 22 | void subtract( int a , int b) 23 | { 24 | printf("\nWhen you will subtract %d from %d then the result will be : %d\n",b,a,a-b); 25 | } 26 | 27 | void array_sort_xor() { 28 | int arr[100], i, n; 29 | 30 | printf("Enter the number of elements in the array: "); 31 | scanf("%d", &n); 32 | 33 | for (i = 0; i < n; ++i) { 34 | printf("Enter %d element of the array: ", i + 1); 35 | scanf("%d", &arr[i]); 36 | } 37 | for (int i = 0; i < n - 1; ++i) { 38 | for (int j = 0; j < n - i - 1; ++j) { 39 | if (arr[j] > arr[j + 1]) { 40 | // Swap arr[j] and arr[j+1] 41 | int temp = arr[j]; 42 | arr[j] = arr[j + 1]; 43 | arr[j + 1] = temp; 44 | } 45 | } 46 | } 47 | printf("The given array is sorted in ascending order as follows: "); 48 | for (i = 0; i < n; ++i) { 49 | printf("%d\t", arr[i]); 50 | } 51 | } 52 | 53 | 54 | void array_2d_printing() { 55 | int row; 56 | int column; 57 | 58 | // Input: Number of Rows 59 | printf("\nEnter row size: \n"); 60 | scanf("%d", &row); 61 | 62 | // Input: Number of Columns 63 | printf("\nEnter column size: \n"); 64 | scanf("%d", &column); 65 | 66 | int arr[row][column]; 67 | 68 | // Input: Elements of the Array 69 | for (int i = 0; i < row; i++) { 70 | for (int j = 0; j < column; j++) { 71 | printf("Enter arr[%d][%d]: ", i, j); 72 | scanf("%d", &arr[i][j]); 73 | } 74 | printf("\n"); 75 | } 76 | 77 | // Output: Display Elements of the Array 78 | printf("The elements of the array are:\n"); 79 | for (int i = 0; i < row; i++) { 80 | for (int j = 0; j < column; j++) { 81 | printf("%d\t", arr[i][j]); 82 | } 83 | printf("\n"); 84 | } 85 | } 86 | 87 | 88 | void factorial() { 89 | int a, result = 1; 90 | 91 | // Input: Number to calculate factorial 92 | printf("Enter a number: "); 93 | scanf("%d", &a); 94 | 95 | // Calculate Factorial 96 | for (int i = a; i > 0; i--) { 97 | result *= i; 98 | } 99 | 100 | // Output: Display the factorial 101 | printf("Factorial of %d is: %d\n", a, result); 102 | 103 | 104 | } 105 | 106 | //Printing Right angle triangle with star 107 | 108 | void right_triangle() 109 | { 110 | int a,b,i; 111 | printf("Enter the no. of rows of triangle="); 112 | scanf("%d",&i); 113 | for(a=1;a<=i;a++) 114 | { 115 | for(b=1;b<=a;b++) 116 | { 117 | printf("* "); 118 | } 119 | 120 | printf("\n"); 121 | } 122 | } 123 | 124 | void pnc_ncr() { 125 | int n, r; 126 | printf("Enter n: "); 127 | scanf("%d", &n); 128 | 129 | printf("Enter r: "); 130 | scanf("%d", &r); 131 | 132 | int factN = 1; 133 | for (int i = 1; i <= n; i++) { 134 | factN *= i; 135 | } 136 | 137 | int factR = 1; 138 | for (int i = 1; i <= r; i++) { 139 | factR *= i; 140 | } 141 | 142 | int factNR = 1; 143 | for (int i = 1; i <= (n - r); i++) { 144 | factNR *= i; 145 | } 146 | 147 | int ans = factN / (factR * factNR); 148 | 149 | printf("The result of nCr(%d, %d) is: %d\n", n, r, ans); 150 | 151 | 152 | } 153 | 154 | void pnc_npr() { 155 | int n, r; 156 | printf("Enter n: "); 157 | scanf("%d", &n); 158 | 159 | printf("Enter r: "); 160 | scanf("%d", &r); 161 | 162 | int factN = 1; 163 | for (int i = 1; i <= n; i++) { 164 | factN *= i; 165 | } 166 | 167 | int factNR = 1; 168 | for (int i = 1; i <= (n - r); i++) { 169 | factNR *= i; 170 | } 171 | 172 | int ans = factN / factNR; 173 | 174 | printf("The result of nPr(%d, %d) is: %d\n", n, r, ans); 175 | 176 | 177 | } 178 | 179 | 180 | void prime_num() { 181 | int num; 182 | 183 | printf("Enter the number: "); 184 | scanf("%d", &num); 185 | 186 | if (num <= 1) { 187 | printf("Not defined for numbers less than or equal to 1.\n"); 188 | } else { 189 | int isPrime = 1; // Assume the number is prime initially 190 | 191 | for (int i = 2; i <= sqrt(num); i++) { 192 | if (num % i == 0) { 193 | isPrime = 0; // Set isPrime to 0 if a factor is found 194 | break; 195 | } 196 | } 197 | 198 | if (isPrime) { 199 | printf("%d is a prime number.\n", num); 200 | } else { 201 | printf("%d is not a prime number.\n", num); 202 | } 203 | } 204 | } 205 | --------------------------------------------------------------------------------