├── .vscode ├── c_cpp_properties.json ├── launch.json └── settings.json ├── AlphaTriangle.c ├── Anagram.c ├── BankersAlgorithm.c ├── Calculator.c ├── EqualOccurance.c ├── EvenorOddusingBitwise.c ├── FIFO.c ├── Factorial.c ├── Fibonacci.c ├── FindCharacter.c ├── FindSubString.c ├── FirstFit.c ├── FloydsTriangle.c ├── FrequencyOfString.c ├── Function.c ├── GCD.c ├── InsertionSort.c ├── LRU.c ├── LargestNum.c ├── LargestNum.exe ├── LeapYear.c ├── LeftRotation.c ├── LengthofString.c ├── LuckyNumber.c ├── MatrixAdd.c ├── MatrixMultiplication.c ├── MultiplicationTable.c ├── NaturalNumSum.c ├── Numtriangle.c ├── Palindrome.c ├── PascalTriangle.c ├── Pointer.c ├── PointerFunction.c ├── Prime.c ├── PrintPattern.c ├── Priority.c ├── PyramidPattern.c ├── README.md ├── RightRotation.c ├── SecondLargestNumber.c ├── Sexyprime.c ├── ShiftOperator.c ├── Simple.c ├── SinglelevelDirectory.c ├── SmallestNum.c ├── StackOperation.c ├── StringPalindrome.c ├── StudentInformation.c ├── StudentInformation.exe ├── Swap.c ├── TwoLevelDirectory.c ├── UniqueElement.c ├── WriteandReadFile.c ├── WriteandReadFile.exe ├── armsrtong.c ├── bubblesort.c ├── build └── Debug │ ├── Palindrome.o │ ├── outDebug.exe │ └── sliding_window.o ├── frequency.c ├── output ├── AlphaTriangle.exe ├── BankersAlgorithm.c ├── BankersAlgorithm.exe ├── BestFit.c ├── BoundedBuffer.c ├── C-ScanDiskScheduling.c ├── Calculator.exe ├── CelsiustoFarenheit.c ├── CheckEqualMatrix.c ├── DecimaltoBinary.c ├── EvenorOddusingBitwise.exe ├── FCFS.c ├── FIFO.exe ├── FactorialUsingRecursion.c ├── Fibonacci.exe ├── FirstFit.exe ├── FloydsTriangle.exe ├── GCD.exe ├── HashTable.c ├── LRU.exe ├── LargestNum.exe ├── LeapYear.exe ├── LinkedFileAllocation.c ├── MatrixAdd.c ├── MatrixAdd.exe ├── MatrixMultiplication.exe ├── MergeArrays.c ├── MultiplicationTable.exe ├── NaturalNumSum.exe ├── Numtriangle.exe ├── Palindrome.exe ├── ParentId.c ├── PascalTriangle.exe ├── PerfectNumber.c ├── PrintPattern.exe ├── Priority.c ├── Priority.exe ├── ProducerConsumer.c ├── PyramidPattern.exe ├── Reader.c ├── RoundRobin.c ├── SJF.c ├── ShiftOperator.exe ├── Simple.c ├── SinglelevelDirectory.exe ├── SmallestNum.exe ├── StackOperation.exe ├── StringPalindrome.exe ├── StudentInformation.exe ├── SumofDigits.c ├── SumofDigits.exe ├── SumofNaturalNum.c ├── TranspoeMatrix.c ├── TransposeMatrix.c ├── TwoLevelDirectory.exe ├── WorstFit.c ├── Writer.c ├── armsrtong.exe ├── matrixSub.c ├── output │ ├── BestFit.exe │ ├── C-ScanDiskScheduling.exe │ ├── CelsiustoFarenheit.exe │ ├── CheckEualMatrix.exe │ ├── DecimaltoBinary.exe │ ├── FactorialUsingRecursion.exe │ ├── LinkedFileAllocation.exe │ ├── MatrixAdd.exe │ ├── MergeArrays.exe │ ├── PerfectNumber.exe │ ├── Priority.exe │ ├── ProducerConsumer.exe │ ├── RoundRobin.exe │ ├── SJF.exe │ ├── Simple.exe │ ├── SumofDigits.exe │ ├── SumofNaturalNum.exe │ ├── TranspoeMatrix.exe │ ├── TransposeMatrix.exe │ ├── WorstFit.exe │ └── matrixSub.exe ├── reverse_string.exe ├── selection.exe ├── sliding_window.exe ├── sum_of_triplet.exe ├── swap_using_xor.exe └── swap_without_temp_var.exe ├── prime_between_range.c ├── prime_upto_n.c ├── reverse_string.c ├── sample.txt ├── selectionsort.c ├── sliding_window.c ├── sliding_window.exe ├── sort_till_k.c ├── sum_of_triplet.c ├── swap_using_xor.c └── swap_without_temp_var.c /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "windows-gcc-x64", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "compilerPath": "gcc", 9 | "cStandard": "${default}", 10 | "cppStandard": "${default}", 11 | "intelliSenseMode": "windows-gcc-x64", 12 | "compilerArgs": [ 13 | "" 14 | ] 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "C/C++ Runner: Debug Session", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "externalConsole": true, 11 | "cwd": "c:/Users/asus/Downloads/C_program", 12 | "program": "c:/Users/asus/Downloads/C_program/build/Debug/outDebug", 13 | "MIMode": "gdb", 14 | "miDebuggerPath": "gdb", 15 | "setupCommands": [ 16 | { 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | } 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp_Runner.cCompilerPath": "gcc", 3 | "C_Cpp_Runner.cppCompilerPath": "g++", 4 | "C_Cpp_Runner.debuggerPath": "gdb", 5 | "C_Cpp_Runner.cStandard": "", 6 | "C_Cpp_Runner.cppStandard": "", 7 | "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", 8 | "C_Cpp_Runner.useMsvc": false, 9 | "C_Cpp_Runner.warnings": [ 10 | "-Wall", 11 | "-Wextra", 12 | "-Wpedantic", 13 | "-Wshadow", 14 | "-Wformat=2", 15 | "-Wcast-align", 16 | "-Wconversion", 17 | "-Wsign-conversion", 18 | "-Wnull-dereference" 19 | ], 20 | "C_Cpp_Runner.msvcWarnings": [ 21 | "/W4", 22 | "/permissive-", 23 | "/w14242", 24 | "/w14287", 25 | "/w14296", 26 | "/w14311", 27 | "/w14826", 28 | "/w44062", 29 | "/w44242", 30 | "/w14905", 31 | "/w14906", 32 | "/w14263", 33 | "/w44265", 34 | "/w14928" 35 | ], 36 | "C_Cpp_Runner.enableWarnings": true, 37 | "C_Cpp_Runner.warningsAsError": false, 38 | "C_Cpp_Runner.compilerArgs": [], 39 | "C_Cpp_Runner.linkerArgs": [], 40 | "C_Cpp_Runner.includePaths": [], 41 | "C_Cpp_Runner.includeSearch": [ 42 | "*", 43 | "**/*" 44 | ], 45 | "C_Cpp_Runner.excludeSearch": [ 46 | "**/build", 47 | "**/build/**", 48 | "**/.*", 49 | "**/.*/**", 50 | "**/.vscode", 51 | "**/.vscode/**" 52 | ], 53 | "C_Cpp_Runner.useAddressSanitizer": false, 54 | "C_Cpp_Runner.useUndefinedSanitizer": false, 55 | "C_Cpp_Runner.useLeakSanitizer": false, 56 | "C_Cpp_Runner.showCompilationTime": false, 57 | "C_Cpp_Runner.useLinkTimeOptimization": false, 58 | "C_Cpp_Runner.msvcSecureNoWarnings": false 59 | } -------------------------------------------------------------------------------- /AlphaTriangle.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n; 4 | printf("Enter the number of rows: "); 5 | scanf("%d", &n); 6 | for (int i = 1; i <= n; i++) { 7 | for (int j = 1; j <= i; j++) { 8 | printf("%c ", 'A' + j - 1); 9 | } 10 | printf("\n"); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Anagram.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char str1[100], str2[100]; 7 | int count[100] = {0}; 8 | int i; 9 | printf("Enter the first string: "); 10 | scanf("%[^\n]s",str1); 11 | 12 | while( getchar() != '\n' ); 13 | 14 | printf("Enter the second string: "); 15 | scanf("%[^\n]s",str2); 16 | 17 | if(strlen(str1) != strlen(str2)){ 18 | printf("Not an Anagram"); 19 | return 0; 20 | } 21 | 22 | for( i=0; str1[i]; i++ ) 23 | { 24 | count[str1[i] - 'a']++; 25 | count[str2[i] - 'a']--; 26 | } 27 | 28 | for( i=0; i < 26; i++ ) 29 | { 30 | if( count[i] != 0 ){ 31 | printf("Not an Anagram"); 32 | return 0; 33 | } 34 | } 35 | 36 | printf("It is an anagram"); 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /BankersAlgorithm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() 4 | { 5 | int alloc[10][10],max[10][10]; 6 | int avail[10],work[10],total[10]; 7 | int i,j,k,n,need[10][10]; 8 | int m; 9 | int count=0,c=0; 10 | char finish[10]; 11 | printf("Enter the no. of processes and resources:"); 12 | scanf("%d%d",&n,&m); 13 | for(i=0;i<=n;i++) 14 | finish[i]='n'; 15 | printf("Enter the claim matrix:\n"); 16 | for(i=0;i 2 | 3 | int main() { 4 | char ch; 5 | float n1, n2; 6 | 7 | printf("Enter an operator (+, -, *, /): "); 8 | scanf("%c", &ch); 9 | 10 | printf("Enter two operands: "); 11 | scanf("%f %f", &n1, &n2); 12 | 13 | switch (ch) { 14 | case '+': 15 | printf("%.2f + %.2f = %.2f\n", n1, n2, n1 + n2); 16 | break; 17 | case '-': 18 | printf("%.2f - %.2f = %.2f\n", n1, n2, n1 - n2); 19 | break; 20 | case '*': 21 | printf("%.2f * %.2f = %.2f\n", n1, n2, n1 * n2); 22 | break; 23 | case '/': 24 | if (n2 != 0) { 25 | printf("%.2f / %.2f = %.2f\n", n1, n2, n1 / n2); 26 | } else { 27 | printf("Division by zero is not allowed\n"); 28 | } 29 | break; 30 | default: 31 | printf("Invalid operator\n"); 32 | break; 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /EqualOccurance.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define SIZE 26 3 | int main() 4 | { 5 | char str[100]; 6 | int count[SIZE] = {0}; 7 | int i, flag = 1, frequency = 0; 8 | 9 | printf("Enter a string: "); 10 | scanf("%[^\n]s", str); 11 | 12 | for (i = 0; str[i]; i++) 13 | { 14 | if (str[i] >= 65 && str[i] <= 90) 15 | count[str[i] - 'A']++; 16 | 17 | else if (str[i] >= 97 && str[i] <= 122) 18 | count[str[i] - 'a']++; 19 | } 20 | 21 | for (i = 0; i < SIZE; i++) 22 | { 23 | if (count[i] > 0) 24 | { 25 | if (frequency == 0) 26 | frequency = count[i]; 27 | else if (count[i] != frequency) 28 | { 29 | flag = 0; 30 | break; 31 | } 32 | } 33 | } 34 | 35 | if (flag) 36 | printf("Equal Occurence"); 37 | else 38 | printf("Unequal Occurence"); 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /EvenorOddusingBitwise.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int num; 4 | printf("Enter an integer: "); 5 | scanf("%d", &num); 6 | if (num & 1) 7 | printf("%d is odd.\n", num); 8 | else 9 | printf("%d is even.\n", num); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /FIFO.c: -------------------------------------------------------------------------------- 1 | /*FIRST IN FIRST OUT*/ 2 | 3 | #include 4 | /*#include */ 5 | int fr[3]; 6 | void main() 7 | { 8 | void display(); 9 | int i,j,page[12]={2,3,2,1,5,2,4,5,3,2,5,2}; 10 | int 11 | flag1=0,flag2=0,pf=0,frsize=3,top=0; 12 | 13 | for(i=0;i<3;i++) 14 | { 15 | fr[i]=-1; 16 | } 17 | for(j=0;j<12;j++) 18 | { 19 | flag1=0; 20 | flag2=0; 21 | for(i=0;i<12;i++) 22 | { 23 | if(fr[i]==page[j]) 24 | { 25 | flag1=1; 26 | flag2=1; 27 | break; 28 | } 29 | } 30 | if(flag1==0) 31 | { 32 | for(i=0;i=frsize) 46 | top=0; 47 | } 48 | display(); 49 | } 50 | printf("Number of page faults : %d ",pf+frsize); 51 | 52 | } 53 | void display() 54 | { 55 | int i; 56 | printf("\n"); 57 | for(i=0;i<3;i++) 58 | printf("%d\t",fr[i]); 59 | } 60 | -------------------------------------------------------------------------------- /Factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int factorial( int n ) 4 | { 5 | if( n == 1 ) 6 | return 1; 7 | 8 | else return n * factorial(n-1); 9 | } 10 | 11 | int main() 12 | { 13 | int n; 14 | printf("The factorial is: %d",factorial(4)); 15 | } -------------------------------------------------------------------------------- /Fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n, fib1 = 0, fib2 = 1, temp; 5 | printf("Enter the number of steps: "); 6 | scanf("%d", &n); 7 | 8 | printf("Fibonacci Sequence: %d, %d", fib1, fib2); 9 | for (int i = 3; i <= n; i++) { 10 | temp = fib1 + fib2; 11 | printf(", %d", temp); 12 | fib1 = fib2; 13 | fib2 = temp; 14 | } 15 | printf("\n"); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /FindCharacter.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int FindChar(char str[], char chr, int i ) 4 | { 5 | 6 | if(str[i] == '\0') 7 | return -1; 8 | 9 | if( str[i] == chr ) 10 | return i; 11 | 12 | return FindChar(str, chr, i+1); 13 | } 14 | 15 | int main() 16 | { 17 | 18 | char str[100]; 19 | char chr; 20 | int i=0; 21 | 22 | printf("Enter a string: "); 23 | scanf("%[^\n]s",str); 24 | 25 | while( getchar() != '\n' ); 26 | 27 | printf("Enter a character "); 28 | scanf("%c",&chr); 29 | 30 | int index = FindChar( str, chr, i ); 31 | 32 | if( index != -1 ) 33 | printf("Character found at index %d",index); 34 | else 35 | printf("String Not found"); 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /FindSubString.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int main() 5 | { 6 | char str1[100], str2[100]; 7 | int i, j,n; 8 | int res[10]={0}; 9 | 10 | printf("Enter a string: "); 11 | scanf("%[^\n]s",str1); 12 | 13 | while( getchar() != '\n' ); 14 | 15 | printf("Enter a sub string: "); 16 | scanf("%[^\n]s",str2); 17 | 18 | for( i = 0; str1[i]; i++ ) 19 | { 20 | for( j=i; str1[j]; j++ ) 21 | { 22 | if( str1[i] == str2[j] ) 23 | res[i] = i; 24 | 25 | } 26 | } 27 | for( i=0; i 3 | /*#include*/ 4 | #define max 25 5 | void main() 6 | { 7 | int 8 | frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0; 9 | static int bf[max],ff[max]; 10 | 11 | printf("\n\tMemory Management Scheme - Worst Fit"); 12 | printf("\nEnter the number of blocks:"); 13 | scanf("%d",&nb); 14 | printf("Enter the number of files:"); 15 | scanf("%d",&nf); 16 | printf("\nEnter the size of the blocks:-\n"); 17 | for(i=1;i<=nb;i++) 18 | { 19 | printf("Block %d:",i); 20 | scanf("%d",&b[i]); 21 | } 22 | printf("Enter the size of the files :-\n"); 23 | for(i=1;i<=nf;i++) 24 | { 25 | printf("File %d:",i); 26 | scanf("%d",&f[i]); 27 | } 28 | for(i=1;i<=nf;i++) 29 | { 30 | for(j=1;j<=nb;j++) 31 | { 32 | if(bf[j]!=1) //if bf[j] is not allocated 33 | { 34 | temp=b[j]-f[i]; 35 | if(temp>=0) 36 | if(highest 2 | int main() { 3 | int n, num = 1; 4 | printf("Enter the number of rows: "); 5 | scanf("%d", &n); 6 | for (int i = 1; i <= n; i++) { 7 | for (int j = 1; j <= i; j++) { 8 | printf("%d ", num++); 9 | } 10 | printf("\n"); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /FrequencyOfString.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char str[100]; 5 | int count[26] = {0}; 6 | int i; 7 | 8 | printf("Enter a string: "); 9 | scanf("%[^\n]s",str); 10 | 11 | for( i=0; str[i]; i++ ) 12 | { 13 | if( str[i] >= 65 && str[i] <= 90 ) 14 | count[str[i] - 'A']++; 15 | 16 | else if( str[i] >= 97 && str[i] <= 122 ) 17 | count[str[i] - 'a']++; 18 | 19 | } 20 | 21 | for( i=0; i<26; i++ ) 22 | { 23 | if( count[i] > 0 ) 24 | printf(" %c ( %d )... ", i + 'a', count[i]); 25 | } 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Function.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void callByValue( int a, int b ){ 4 | a = a + 10; 5 | b = b + 10; 6 | printf("Inside function: a=%d and b=%d",a,b); 7 | } 8 | 9 | int main() { 10 | int x = 10,y = 20; 11 | printf("\nBefore Calling: x=%d and y=%d\n",x,y); 12 | callByValue(x,y); 13 | printf("\nAfter Calling: x=%d and y=%d",x,y); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /GCD.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int a, b, gcd; 4 | printf("Enter two integers: "); 5 | scanf("%d %d", &a, &b); 6 | for (int i = 1; i <= a && i <= b; i++) { 7 | if (a % i == 0 && b % i == 0) { 8 | gcd = i; 9 | } 10 | } 11 | printf("GCD of %d and %d is: %d\n", a, b, gcd); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /InsertionSort.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | void readArray(int arr[], int n) { 5 | for( int i=0; i=0 && arr[j]>key){ 21 | arr[j+1]=arr[j]; 22 | j--; 23 | } 24 | 25 | arr[j+1]=key; 26 | } 27 | } 28 | 29 | int main() { 30 | int n, arr[100]; 31 | 32 | printf("Enter the size of the array:"); 33 | scanf("%d",&n); 34 | 35 | printf("Enter the elements of the array:"); 36 | readArray( arr, n); 37 | 38 | 39 | printf("Before Sorting:"); 40 | printArray( arr , n); 41 | 42 | insertionSort( arr , n); 43 | 44 | printf("\nAfter Sorting:"); 45 | printArray(arr , n); 46 | 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /LRU.c: -------------------------------------------------------------------------------- 1 | /*LEAST RECENTLY USED*/ 2 | #include 3 | /*#include*/ 4 | int fr[3]; 5 | void main() 6 | { 7 | void display(); 8 | int p[12]={2,3,2,1,5,2,4,5,3,2,5,2},i,j,fs[3]; 9 | int index,k,l,flag1=0,flag2=0,pf=0,frsize=3; 10 | 11 | for(i=0;i<3;i++) 12 | { 13 | fr[i]=-1; 14 | } 15 | for(j=0;j<12;j++) 16 | { 17 | flag1=0,flag2=0; 18 | for(i=0;i<3;i++) 19 | { 20 | if(fr[i]==p[j]) 21 | { 22 | flag1=1; 23 | flag2=1; 24 | break; 25 | } 26 | } 27 | if(flag1==0) 28 | { 29 | for(i=0;i<3;i++) 30 | { 31 | if(fr[i]==-1) 32 | { 33 | fr[i]=p[j]; 34 | flag2=1; 35 | break; 36 | }}} 37 | if(flag2==0) 38 | { 39 | for(i=0;i<3;i++) 40 | fs[i]=0; 41 | for(k=j-1,l=1;l<=frsize-1;l++,k--) 42 | 43 | { 44 | for(i=0;i<3;i++) 45 | { 46 | if(fr[i]==p[k]) fs[i]=1; 47 | }} 48 | for(i=0;i<3;i++) 49 | { 50 | if(fs[i]==0) 51 | index=i; 52 | } 53 | fr[index]=p[j]; 54 | pf++; 55 | } 56 | display(); 57 | } 58 | printf("\n no of page faults :%d",pf+frsize); 59 | 60 | } 61 | void display() 62 | { 63 | int i; 64 | printf("\n"); 65 | for(i=0;i<3;i++) 66 | printf("\t%d",fr[i]); 67 | } 68 | -------------------------------------------------------------------------------- /LargestNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n, i; 5 | int arr[100],largest; 6 | printf("Enter the number of elements in the array: "); 7 | scanf("%d", &n); 8 | printf("Enter elements:\n"); 9 | for(i = 0; i < n; i++) { 10 | scanf("%d", &arr[i]); 11 | } 12 | largest = arr[0]; 13 | 14 | for(i = 1; i < n; i++) { 15 | if(arr[i] > largest) { 16 | largest = arr[i]; 17 | } 18 | } 19 | printf("The largest number in the array is %d\n", largest); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /LargestNum.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/LargestNum.exe -------------------------------------------------------------------------------- /LeapYear.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int year; 4 | printf("Enter a year:"); 5 | scanf("%d", &year); 6 | if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { 7 | printf("%d is a leap year\n", year); 8 | } else { 9 | printf("%d is not a leap year\n", year); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /LeftRotation.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int arr[10]; 6 | int i, j,temp = 0, k, n; 7 | 8 | printf("Enter the size of the array: "); 9 | scanf("%d",&n); 10 | 11 | printf("Enter the Elemenets of the array: "); 12 | for( i=0; i 2 | 3 | int lengthOfString( char *p ) 4 | { 5 | if( *p == '\0' ) 6 | return 0; 7 | else 8 | return 1 + lengthOfString(p+1); 9 | } 10 | 11 | int main() 12 | { 13 | char str[100]; 14 | printf("Enter String: "); 15 | scanf("%[^\n]s",str); 16 | 17 | printf("%d",lengthOfString(str)); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /LuckyNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int num, rem , rev = 0, sum = 0; 6 | 7 | printf("Enter a number:"); 8 | scanf("%d", &num); 9 | 10 | 11 | while ( num > 9 ){ 12 | sum = 0; 13 | 14 | while ( num > 0 ) { 15 | rem = num % 10; 16 | num = num / 10; 17 | sum = sum + rem; 18 | } 19 | 20 | if ( sum > 1 ){ 21 | num = sum; 22 | } 23 | } 24 | 25 | printf("Your Lucky number is: %d",num); 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /MatrixAdd.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int r, c; 4 | printf("Enter the number of rows and columns: "); 5 | scanf("%d %d", &r, &c); 6 | int m1[r][c], m2[r][c], sum[r][c]; 7 | printf("Enter elements of the first matrix:\n"); 8 | for (int i = 0; i < r; i++) { 9 | for (int j = 0; j < c; j++) { 10 | scanf("%d", &m1[i][j]); 11 | } 12 | } 13 | printf("Enter elements of the second matrix:\n"); 14 | for (int i = 0; i < r; i++) { 15 | for (int j = 0; j < c; j++) { 16 | scanf("%d", &m2[i][j]); 17 | } 18 | } 19 | for (int i = 0; i < r; i++) { 20 | for (int j = 0; j < c; j++) { 21 | sum[i][j] = m1[i][j] + m2[i][j]; 22 | } 23 | } 24 | printf("Sum of the matrices:\n"); 25 | for (int i = 0; i < r; i++) { 26 | for (int j = 0; j < c; j++) { 27 | printf("%d ", sum[i][j]); 28 | } 29 | printf("\n"); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /MatrixMultiplication.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int a[10][10], b[10][10], result[10][10], r1, c1, r2, c2; 4 | printf("Enter rows and columns of first matrix: "); 5 | scanf("%d %d", &r1, &c1); 6 | printf("Enter rows and columns of second matrix: "); 7 | scanf("%d %d", &r2, &c2); 8 | if (c1 != r2) { 9 | printf("Matrix multiplication not possible.\n"); 10 | return 0; 11 | } 12 | printf("Enter elements of first matrix:\n"); 13 | for (int i = 0; i < r1; i++) { 14 | for (int j = 0; j < c1; j++) { 15 | scanf("%d", &a[i][j]); 16 | } 17 | } 18 | printf("Enter elements of second matrix:\n"); 19 | for (int i = 0; i < r2; i++) { 20 | for (int j = 0; j < c2; j++) { 21 | scanf("%d", &b[i][j]); 22 | } 23 | } 24 | for (int i = 0; i < r1; i++) { 25 | for (int j = 0; j < c2; j++) { 26 | result[i][j] = 0; 27 | for (int k = 0; k < c1; k++) { 28 | result[i][j] += a[i][k] * b[k][j]; 29 | } 30 | } 31 | } 32 | printf("Resultant matrix:\n"); 33 | for (int i = 0; i < r1; i++) { 34 | for (int j = 0; j < c2; j++) { 35 | printf("%d ", result[i][j]); 36 | } 37 | printf("\n"); 38 | } 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /MultiplicationTable.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int num, i; 5 | printf("Enter the number: "); 6 | scanf("%d", &num); 7 | printf("Multiplication table of %d:\n",num); 8 | for (i = 1; i <= 10; i++) { 9 | printf("%d x %d = %d\n", num, i, num * i); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /NaturalNumSum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n, sum = 0; 4 | printf("Enter a positive integer: "); 5 | scanf("%d", &n); 6 | for (int i = 1; i <= n; i++) { 7 | sum += i; 8 | } 9 | printf("Sum of first %d natural numbers is: %d\n", n, sum); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Numtriangle.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n; 4 | printf("Enter the number of rows: "); 5 | scanf("%d", &n); 6 | for (int i = 1; i <= n; i++) { 7 | for (int j = 1; j <= i; j++) { 8 | printf("%d ", j); 9 | } 10 | printf("\n"); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Palindrome.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int num, inum, rem, rev = 0; 6 | 7 | printf("Enter a number:"); 8 | scanf("%d",&num); 9 | inum = num; 10 | 11 | while(num > 0) { 12 | rem = num % 10; 13 | num = num / 10; 14 | rev = rev * 10 + rem; 15 | } 16 | 17 | rev==inum ? printf("It is a palindrome") : printf("It is not a palindrome"); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /PascalTriangle.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n, coeff; 4 | printf("Enter the number of rows: "); 5 | scanf("%d", &n); 6 | for (int i = 0; i < n; i++) { 7 | for (int j = 0; j < n - i - 1; j++) { 8 | printf(" "); 9 | } 10 | coeff = 1; 11 | for (int k = 0; k <= i; k++) { 12 | printf("%d ", coeff); 13 | coeff = coeff * (i - k) / (k + 1); 14 | } 15 | printf("\n"); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Pointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int num; 5 | int *p; 6 | 7 | num = 10; 8 | p = # 9 | 10 | 11 | printf("%d",*p); 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /PointerFunction.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void callByValue( int a, int b ){ 4 | a = a + 10; 5 | b = b + 10; 6 | printf("Inside function: a=%d and b=%d",a,b); 7 | } 8 | 9 | int main() { 10 | int x = 10,y = 20; 11 | printf("\nBefore Calling: x=%d and y=%d\n",x,y); 12 | callByValue(x,y); 13 | printf("\nAfter Calling: x=%d and y=%d",x,y); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Prime.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int isPrime(int n) { 5 | int i; 6 | if( n == 0 || n == 1 ) 7 | return 0; 8 | if (n <= 3) { 9 | return 1; 10 | } 11 | 12 | if( n%2 == 0 || n%3 == 0 ) 13 | return 0; 14 | 15 | for ( i = 5; i*i<=n ; i=i+6 ){ 16 | if ( n%i == 0 || n%(i+2)==0) 17 | return 0; 18 | } 19 | return 1; 20 | } 21 | 22 | int main() { 23 | int num; 24 | printf("Enter n:"); 25 | scanf("%d",&num); 26 | if( isPrime(num)) { 27 | printf("Prime"); 28 | } 29 | else { 30 | printf("Not Prime"); 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /PrintPattern.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n; 5 | printf("Enter the number of rows: "); 6 | scanf("%d", &n); 7 | 8 | for (int i = 1; i <= n; i++) { 9 | for (int j = 1; j <= i; j++) { 10 | printf("* "); 11 | } 12 | printf("\n"); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Priority.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int p[20],bt[20],pri[20], wt[20],tat[20],i,k,n,temp; 5 | float wtavg,tatavg; 6 | printf("Enter the number of processes --- "); 7 | scanf("%d",&n); 8 | for(i=0;ipri[k]){ 16 | temp=p[i]; 17 | p[i]=p[k]; 18 | p[k]=temp; 19 | temp=bt[i]; 20 | bt[i]=bt[k]; 21 | bt[k]=temp; 22 | temp=pri[i]; 23 | pri[i]=pri[k]; 24 | pri[k]=temp; 25 | } 26 | wtavg=wt[0]=0; 27 | tatavg=tat[0]=bt[0]; 28 | for(i=1;i 2 | 3 | int main() { 4 | int n,i,j; 5 | printf("Enter the number of rows: "); 6 | scanf("%d", &n); 7 | for (i = 1; i <= n; i++) { 8 | for (j = 1; j <= n - i; j++) { 9 | printf(" "); 10 | } 11 | for (int k = 1; k <= i; k++) { 12 | printf("* "); 13 | } 14 | printf("\n"); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # c-programming 2 | -------------------------------------------------------------------------------- /RightRotation.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | 6 | int arr[10]; 7 | int i, j, temp = 0, k, n; 8 | 9 | printf("Enter the size of the array: "); 10 | scanf("%d", &n); 11 | 12 | printf("Enter the Elemenets of the array: "); 13 | for (i = 0; i < n; i++) 14 | { 15 | scanf("%d", &arr[i]); 16 | } 17 | 18 | printf("Enter k: "); 19 | scanf("%d", &k); 20 | 21 | for (j = 0; j < k; j++) 22 | { 23 | temp = arr[n - 1]; 24 | for (i = n - 1; i > 0; i--) 25 | { 26 | arr[i] = arr[i - 1]; 27 | } 28 | arr[0] = temp; 29 | } 30 | 31 | printf("Rotated Element is:"); 32 | for (i = 0; i < n; i++) 33 | { 34 | printf(" %d ", arr[i]); 35 | } 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /SecondLargestNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int arr[10],n, i, largest, secondLargest; 6 | 7 | printf("Enter the size of the array:"); 8 | scanf("%d",&n); 9 | 10 | printf("Enter the array elements:"); 11 | for( i = 0; i< n ; i++ ) 12 | scanf("%d",&arr[i]); 13 | 14 | largest = arr[0]; 15 | secondLargest = arr[0]; 16 | 17 | for ( i=1 ; i largest ){ 19 | secondLargest = largest; 20 | largest = arr[i]; 21 | } 22 | else if ( arr[i] > secondLargest && arr[i] != largest ){ 23 | secondLargest = arr[i]; 24 | } 25 | } 26 | 27 | printf("The Second Largest Element is:"); 28 | printf(" %d ",secondLargest); 29 | 30 | } -------------------------------------------------------------------------------- /Sexyprime.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int i, j, n,flag, size; 5 | int arr[10], k = 0, l = 0; 6 | 7 | printf("Enter range:"); 8 | scanf("%d",&n); 9 | 10 | for ( j = 2; j <= n ; j++ ){ 11 | flag = 0; 12 | for( i = 2; i*i <= j; i++ ){ 13 | if( j%i == 0 ){ 14 | flag = 1; 15 | break; 16 | } 17 | } 18 | if( flag == 0 ){ 19 | arr[k] = j; 20 | k++; 21 | } 22 | 23 | size = k; 24 | } 25 | 26 | for(k=0; k< size ; k++){ 27 | printf("%d\t",arr[k]); 28 | } 29 | 30 | for( k=0; k 3 | 4 | int main() 5 | { 6 | int a,b,res=0; 7 | printf("Enter value of a and b:"); 8 | scanf("%d%d",&a,&b); 9 | while(b>0) 10 | { 11 | if(b & 1==1) 12 | res=res+a; 13 | a=a<<1; 14 | b=b>>1; 15 | } 16 | printf( "%d",res); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Simple.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | printf("Hello World"); 5 | } -------------------------------------------------------------------------------- /SinglelevelDirectory.c: -------------------------------------------------------------------------------- 1 | /*SINGLE LEVEL DIRECTORY*/ 2 | #include 3 | #include 4 | #include 5 | 6 | struct 7 | { 8 | char dname[10],fname[10][10]; 9 | int fcnt; 10 | } 11 | dir; 12 | void main() 13 | { 14 | int i,ch; 15 | char f[30]; 16 | 17 | dir.fcnt=0; 18 | printf("\nEnter name of directory -- "); 19 | scanf("%s",dir.dname); 20 | while(1) 21 | { 22 | printf("\n\n1. Create File\t2. Delete File\t3. Search File \n4. Display Files\t5. Exit\nEnter your choice -- "); 23 | scanf("%d",&ch); 24 | switch(ch) 25 | { 26 | case 1:printf("\nEnter the name of the file -- "); 27 | scanf("%s",dir.fname[dir.fcnt]); 28 | dir.fcnt++; 29 | break; 30 | case 2:printf("\nEnter the name of the file -- "); 31 | scanf("%s",f); 32 | for(i=0;i 2 | 3 | int main() { 4 | 5 | int num, rem, small = 10; 6 | 7 | printf("Enter numbers:"); 8 | scanf("%d",&num); 9 | 10 | while ( num > 0 ){ 11 | rem = num % 10; 12 | if ( rem < small ){ 13 | small = rem; 14 | } 15 | num = num / 10; 16 | } 17 | printf("The Smallest NUmber is: %d", small); 18 | 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /StackOperation.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX 5 3 | 4 | int stack[MAX], top = -1; 5 | 6 | void push(int value) { 7 | if (top == MAX - 1) 8 | printf("Stack Overflow\n"); 9 | else 10 | stack[++top] = value; 11 | } 12 | 13 | void pop() { 14 | if (top == -1) 15 | printf("Stack Underflow\n"); 16 | else 17 | printf("Popped: %d\n", stack[top--]); 18 | } 19 | 20 | void display() { 21 | if (top == -1) 22 | printf("Stack is empty\n"); 23 | else { 24 | printf("Stack: "); 25 | for (int i = 0; i <= top; i++) 26 | printf("%d ", stack[i]); 27 | printf("\n"); 28 | } 29 | } 30 | 31 | int main() { 32 | int choice, value; 33 | 34 | while (1) { 35 | printf("1. Push 2. Pop 3. Display 4. Exit\n"); 36 | printf("Enter your choice: "); 37 | scanf("%d", &choice); 38 | 39 | if (choice == 1) { 40 | printf("Enter value : "); 41 | scanf("%d", &value); 42 | push(value); 43 | } else if (choice == 2) { 44 | pop(); 45 | } else if (choice == 3) { 46 | display(); 47 | } else { 48 | break; 49 | } 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /StringPalindrome.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | char str[100]; 6 | int length=0, i, flag=0; 7 | 8 | printf("Enter a string: "); 9 | scanf("%s",str); 10 | 11 | for( i=0; str[i]; i++ ) 12 | length++; 13 | 14 | // printf("%d",length); 15 | 16 | for( i=0; i 2 | struct Student { 3 | char name[50]; 4 | int roll; 5 | float marks; 6 | }; 7 | int main() { 8 | struct Student s; 9 | printf("Enter name: "); 10 | scanf("%s", s.name); 11 | printf("Enter roll number: "); 12 | scanf("%d", &s.roll); 13 | printf("Enter marks: "); 14 | scanf("%f", &s.marks); 15 | 16 | printf("\nStudent Details:\n"); 17 | printf("Name: %s\n", s.name); 18 | printf("Roll Number: %d\n", s.roll); 19 | printf("Marks: %.2f\n", s.marks); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /StudentInformation.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/StudentInformation.exe -------------------------------------------------------------------------------- /Swap.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int a,b; 6 | 7 | printf("Enter a: "); 8 | scanf("%d",&a); 9 | 10 | printf("Enter b: "); 11 | scanf("%d",&b); 12 | 13 | a^= b^= a^= b; 14 | 15 | printf("Swapped Element is a: %d and b: %d ",a,b); 16 | 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /TwoLevelDirectory.c: -------------------------------------------------------------------------------- 1 | /*TWO LEVEL DIRECTORY*/ 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | struct 8 | { 9 | char dname[10],fname[10][10]; 10 | int fcnt; 11 | } 12 | dir[10]; 13 | void main() 14 | { 15 | int i,ch,dcnt,k; 16 | char f[30], d[30]; 17 | 18 | dcnt=0; 19 | while(1) 20 | { 21 | printf("\n\n1. Create Directory\t2. Create File\t3. Delete File"); 22 | printf("\n4. Search File\t\t5. Display\t6. Exit\t Enter your choice --"); 23 | scanf("%d",&ch); 24 | switch(ch) 25 | { 26 | case 1:printf("\nEnter name of directory -- "); 27 | scanf("%s",dir[dcnt].dname); 28 | dir[dcnt].fcnt=0; 29 | dcnt++; 30 | printf("Directory created"); 31 | break; 32 | case 2:printf("\nEnter name of the directory -- "); 33 | scanf("%s",d); 34 | for(i=0;i 2 | 3 | int main() { 4 | int arr[10], i, j, n, k=0, unique[10], flag; 5 | 6 | printf("Enter the size of the array:"); 7 | scanf("%d",&n); 8 | 9 | printf("Enter the array elements:"); 10 | for( i = 0; i< n ; i++ ) 11 | scanf("%d",&arr[i]); 12 | 13 | for ( i=0; i 2 | 3 | int main() { 4 | FILE *file; 5 | char text[100]; 6 | 7 | file = fopen("sample.txt", "w"); 8 | if (file == NULL) { 9 | printf("Error opening file.\n"); 10 | return 1; 11 | } 12 | 13 | printf("Enter text to write to the file: "); 14 | scanf(" %[^\n]", text); 15 | fprintf(file, "%s", text); 16 | fclose(file); 17 | 18 | file = fopen("sample.txt", "r"); 19 | if (file == NULL) { 20 | printf("Error opening file.\n"); 21 | return 1; 22 | } 23 | 24 | printf("\nReading from file:\n"); 25 | while (fgets(text, sizeof(text), file)) { 26 | printf("%s", text); 27 | } 28 | 29 | fclose(file); 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /WriteandReadFile.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/WriteandReadFile.exe -------------------------------------------------------------------------------- /armsrtong.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | 6 | int num, power = 0 , rem = 0, res = 0; 7 | 8 | printf("Enter a number:"); 9 | scanf("%d", &num); 10 | int X = num; 11 | 12 | while ( num > 0 ) { 13 | rem = num % 10; 14 | num = num / 10; 15 | power++; 16 | } 17 | 18 | num = X; 19 | res = 0; 20 | 21 | while ( num > 0) { 22 | rem = num % 10; 23 | num = num / 10; 24 | res = res + (int)pow(rem, power); 25 | } 26 | 27 | if ( X == res ){ 28 | printf("It is a Armstrong number"); 29 | } else { 30 | printf("It is not a Armstrong number"); 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /bubblesort.c: -------------------------------------------------------------------------------- 1 | #include 2 | void readArray(int a[],int n) 3 | { 4 | int i; 5 | for(i=0;ia[j+1]){ 27 | swap(&a[j],&a[j+1]); 28 | status=1; 29 | } 30 | } 31 | if(status==0) 32 | break; 33 | } 34 | 35 | } 36 | int main() 37 | { 38 | int a[100],n; 39 | printf("enter the size:"); 40 | scanf("%d",&n); 41 | printf("enter the element:"); 42 | readArray(a, n); 43 | 44 | printf("the elements are:"); 45 | printArray(a, n); 46 | 47 | bubblesort(a, n); 48 | printf("\nsorted array is:"); 49 | printArray(a, n); 50 | 51 | return 0; 52 | } -------------------------------------------------------------------------------- /build/Debug/Palindrome.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/build/Debug/Palindrome.o -------------------------------------------------------------------------------- /build/Debug/outDebug.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/build/Debug/outDebug.exe -------------------------------------------------------------------------------- /build/Debug/sliding_window.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/build/Debug/sliding_window.o -------------------------------------------------------------------------------- /frequency.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int arr[10],n ,i, j, frequency, count; 6 | 7 | printf("Enter the size of the array:"); 8 | scanf("%d", &n); 9 | 10 | printf("Enter the elements of the array:"); 11 | for (i = 0; i < n; i++) 12 | scanf("%d", &arr[i]); 13 | for( i=0 ; i 2 | #include 3 | void main() 4 | { 5 | int alloc[10][10],max[10][10]; 6 | int avail[10],work[10],total[10]; 7 | int i,j,k,n,need[10][10]; 8 | int m; 9 | int count=0,c=0; 10 | char finish[10]; 11 | printf("Enter the no. of processes and resources:"); 12 | scanf("%d%d",&n,&m); 13 | for(i=0;i<=n;i++) 14 | finish[i]='n'; 15 | printf("Enter the claim matrix:\n"); 16 | for(i=0;i 3 | /*#include*/ 4 | #define max 25 5 | void main() 6 | { 7 | int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000; 8 | static int bf[max],ff[max]; 9 | 10 | printf("\nEnter the number of blocks:"); 11 | scanf("%d",&nb); 12 | printf("Enter the number of files:"); 13 | scanf("%d",&nf); 14 | printf("\nEnter the size of the blocks:-\n"); 15 | for(i=1;i<=nb;i++) 16 | printf("Block %d:",i); 17 | scanf("%d",&b[i]); 18 | printf("Enter the size of the files :-\n"); 19 | for(i=1;i<=nf;i++) 20 | { 21 | printf("File %d:",i); 22 | scanf("%d",&f[i]); 23 | } 24 | for(i=1;i<=nf;i++) 25 | { 26 | for(j=1;j<=nb;j++) 27 | { 28 | if(bf[j]!=1) 29 | { 30 | temp=b[j]-f[i]; 31 | if(temp>=0) 32 | if(lowest>temp) 33 | { 34 | ff[i]=j; 35 | lowest=temp; 36 | } 37 | 38 | }} 39 | frag[i]=lowest; 40 | bf[ff[i]]=1; 41 | lowest=10000; 42 | } 43 | printf("\nFile No\tFile Size \tBlock No\tBlockSize\tFragment"); 44 | for(i=1;i<=nf && ff[i]!=0;i++) 45 | printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /output/BoundedBuffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define BUFFER_SIZE 5 7 | #define MAX_ITEMS 20 8 | 9 | int buffer[BUFFER_SIZE]; 10 | int in=0; 11 | int out=0; 12 | int produced_count=0; 13 | int consumed_count=0; 14 | 15 | sem_t mutex; 16 | sem_t full; 17 | sem_t empty; 18 | 19 | void* producer(void* arg) { 20 | int item = 1; 21 | 22 | while(produced_count < MAX_ITEMS) { 23 | sem_wait(&empty); 24 | sem_wait(&mutex); 25 | 26 | buffer[in]=item; 27 | printf("Produced: %d\n", item); 28 | item++; 29 | in=(in+1)%BUFFER_SIZE; 30 | 31 | produced_count++; 32 | 33 | sem_post(&mutex); 34 | sem_post(&full); 35 | } 36 | 37 | pthread_exit(NULL); 38 | } 39 | 40 | void* consumer(void* arg) { 41 | while(consumed_count 3 | void main() 4 | { 5 | int t[20], d[20], h, i, j, n, temp, k, atr[20], tot, p, sum=0; 6 | printf("enter the no of tracks to be traveresed"); 7 | scanf("%d'",&n); 8 | printf("enter the position of head"); 9 | scanf("%d",&h); 10 | t[0]=0;t[1]=h; 11 | printf("enter total tracks"); 12 | scanf("%d",&tot); 13 | t[2]=tot-1; 14 | printf("enter the tracks"); 15 | for(i=3;i<=n+2;i++) 16 | scanf("%d",&t[i]); 17 | for(i=0;i<=n+2;i++) 18 | for(j=0;j<=(n+2)-i-1;j++) 19 | if(t[j]>t[j+1]) 20 | { 21 | } 22 | for(i=0;i<=n+2;i++) 23 | if(t[i]==h) 24 | temp=t[j]; 25 | t[j]=t[j+1]; 26 | t[j+1]=temp; 27 | p=0; 28 | while(t[j]!=tot-1) 29 | { 30 | j=i;break; 31 | atr[p]=t[j]; 32 | j++; 33 | p++; 34 | } 35 | atr[p]=t[j]; 36 | p++; 37 | i=0; 38 | while(p!=(n+3) && t[i]!=t[h]) 39 | { 40 | atr[p]=t[i]; 41 | i++; 42 | p++; 43 | } 44 | for(j=0;jatr[j+1]) 47 | d[j]=atr[j]-atr[j+1]; 48 | else 49 | d[j]=atr[j+1]-atr[j]; 50 | sum+=d[j]; 51 | } 52 | printf("total header movements%d",sum); 53 | printf("avg is %f",(float)sum/n); 54 | } -------------------------------------------------------------------------------- /output/Calculator.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/Calculator.exe -------------------------------------------------------------------------------- /output/CelsiustoFarenheit.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | float celsius, fahrenheit; 5 | printf("Enter temperature in Celsius: "); 6 | scanf("%f", &celsius); 7 | 8 | fahrenheit = (celsius * 9/5) + 32; 9 | printf("Temperature in Fahrenheit: %.2f\n", fahrenheit); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /output/CheckEqualMatrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int r, c, a[10][10], b[10][10], same = 1; 4 | printf("Enter the number of rows and columns: "); 5 | scanf("%d %d", &r, &c); 6 | printf("Enter elements of the first matrix:\n"); 7 | for (int i = 0; i < r; i++) { 8 | for (int j = 0; j < c; j++) { 9 | scanf("%d", &a[i][j]); 10 | } 11 | } 12 | printf("Enter elements of the second matrix:\n"); 13 | for (int i = 0; i < r; i++) { 14 | for (int j = 0; j < c; j++) { 15 | scanf("%d", &b[i][j]); 16 | if (a[i][j] != b[i][j]) { 17 | same = 0; 18 | } 19 | } 20 | } 21 | if (same) { 22 | printf("The matrices are equal.\n"); 23 | } else { 24 | printf("The matrices are not equal.\n"); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /output/DecimaltoBinary.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void decimalToBinary(int n) { 4 | if (n == 0) 5 | return; 6 | decimalToBinary(n / 2); 7 | printf("%d", n % 2); 8 | } 9 | 10 | int main() { 11 | int num; 12 | printf("Enter a decimal number: "); 13 | scanf("%d", &num); 14 | 15 | printf("Binary representation: "); 16 | if (num == 0) { 17 | printf("0"); 18 | } else { 19 | decimalToBinary(num); 20 | } 21 | printf("\n"); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /output/EvenorOddusingBitwise.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/EvenorOddusingBitwise.exe -------------------------------------------------------------------------------- /output/FCFS.c: -------------------------------------------------------------------------------- 1 | #include 2 | /*#include*/ 3 | 4 | void main() 5 | { 6 | int bt[20], wt[20], tat[20], i, n; 7 | float wtavg, tatavg; 8 | printf("\nEnter the number of processes -- "); 9 | scanf("%d", &n); 10 | for(i=0;i 2 | 3 | int factorial(int n) { 4 | if (n == 0 || n == 1) { 5 | return 1; 6 | } 7 | return n * factorial(n - 1); 8 | } 9 | 10 | int main() { 11 | int num; 12 | printf("Enter a number: "); 13 | scanf("%d", &num); 14 | 15 | printf("Factorial of %d is %d\n", num, factorial(num)); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /output/Fibonacci.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/Fibonacci.exe -------------------------------------------------------------------------------- /output/FirstFit.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/FirstFit.exe -------------------------------------------------------------------------------- /output/FloydsTriangle.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/FloydsTriangle.exe -------------------------------------------------------------------------------- /output/GCD.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/GCD.exe -------------------------------------------------------------------------------- /output/HashTable.c: -------------------------------------------------------------------------------- 1 | """Given a File of N employee records with a set K of Keys (4-digit) which uniquely 2 | determine the records in file F. Assume that file F is maintained in memory by a Hash 3 | Table (HT) of m memory locations with L as the set of memory addresses (2-digit) of 4 | locations in HT. Let the keys in K and addresses in L are Integers. Develop a Program in C 5 | that uses Hash function H: K →L as H(K)=K mod m (remainder method), and implement 6 | hashing technique to map a given key K to the address space L. Resolve the collision (if 7 | any) using linear probing.""" 8 | 9 | #include 10 | #include 11 | int key[20], n, m; 12 | int * ht, ind; 13 | int count = 0; 14 | void insert(int key) 15 | { 16 | ind = key % m; 17 | while (ht[ind] != -1) { 18 | ind = (ind + 1) % m; 19 | } 20 | ht[ind] = key; 21 | count++; 22 | } 23 | void display() 24 | { 25 | int i; 26 | if (count == 0) { 27 | printf("\nHash Table is empty"); 28 | return ; 29 | } 30 | printf("\nHash Table contents are:\n "); 31 | for (i = 0; i < m; i++) 32 | printf("\n T[%d] --> %d ", i, ht[i]); 33 | 34 | } 35 | void main() 36 | { 37 | int i; 38 | printf("\nEnter the number of employee records (N) :"); 39 | scanf("%d", & n); 40 | printf("\nEnter the two digit memory locations (m) for hash table:"); 41 | scanf("%d", & m); 42 | ht = (int * ) malloc(m * sizeof(int)); 43 | for (i = 0; i < m; i++) 44 | ht[i] = -1; 45 | printf("\nEnter the four digit key values (K) for N Employee Records:\n "); 46 | for (i = 0; i < n; i++){ 47 | scanf("%d", & key[i]); 48 | for (i = 0; i < n; i++) { 49 | if (count == m) { 50 | 51 | printf("\n~~~Hash table is full. Cannot insert the record %d key~~~", i + 1); 52 | break; 53 | } 54 | insert(key[i]); 55 | } 56 | display(); 57 | } 58 | } -------------------------------------------------------------------------------- /output/LRU.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/LRU.exe -------------------------------------------------------------------------------- /output/LargestNum.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/LargestNum.exe -------------------------------------------------------------------------------- /output/LeapYear.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/LeapYear.exe -------------------------------------------------------------------------------- /output/LinkedFileAllocation.c: -------------------------------------------------------------------------------- 1 | //LINKED FILE ALLOCATION 2 | #include 3 | #include 4 | #include 5 | //#include 6 | struct fileTable 7 | { 8 | char name[20]; 9 | int nob; 10 | struct block*sb; 11 | } 12 | ft[30]; 13 | struct block 14 | { 15 | int bno; 16 | struct block*next; 17 | }; 18 | int main() 19 | { 20 | int i,j,n; 21 | char s[20]; 22 | struct block*temp; 23 | printf("Enter no of files :"); 24 | scanf("%d",&n); 25 | for(i=0;ibno); 35 | temp->next=NULL; 36 | for(j=1;jnext=(struct block*)malloc(sizeof(struct block)); 39 | temp=temp->next; 40 | scanf("%d",&temp->bno); 41 | } 42 | temp->next = NULL; 43 | } 44 | printf("\nEnter the file name to be searched -- "); 45 | scanf("%s",s); 46 | for(i=0;i",temp->bno); 59 | temp=temp->next; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /output/MatrixAdd.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int r, c, a[10][10], b[10][10], sum[10][10]; 4 | printf("Enter the number of rows and columns : "); 5 | scanf("%d %d", &r, &c); 6 | printf("Enter elements of first matrix:\n"); 7 | for (int i = 0; i < r; i++) { 8 | for (int j = 0; j < c; j++) { 9 | scanf("%d", &a[i][j]); 10 | } 11 | } 12 | printf("Enter elements of second matrix:\n"); 13 | for (int i = 0; i < r; i++) { 14 | for (int j = 0; j < c; j++) { 15 | scanf("%d", &b[i][j]); 16 | } 17 | } 18 | for (int i = 0; i < r; i++) { 19 | for (int j = 0; j < c; j++) { 20 | sum[i][j] = a[i][j] + b[i][j]; 21 | } 22 | } 23 | printf("Sum of matrices:\n"); 24 | for (int i = 0; i < r; i++) { 25 | for (int j = 0; j < c; j++) { 26 | printf("%d ", sum[i][j]); 27 | } 28 | printf("\n"); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /output/MatrixAdd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/MatrixAdd.exe -------------------------------------------------------------------------------- /output/MatrixMultiplication.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/MatrixMultiplication.exe -------------------------------------------------------------------------------- /output/MergeArrays.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void mergeArrays(int arr1[], int n1, int arr2[], int n2, int result[]) { 4 | int i = 0, j = 0, k = 0; 5 | 6 | while (i < n1 && j < n2) { 7 | if (arr1[i] < arr2[j]) { 8 | result[k++] = arr1[i++]; 9 | } else { 10 | result[k++] = arr2[j++]; 11 | } 12 | } 13 | 14 | while (i < n1) { 15 | result[k++] = arr1[i++]; 16 | } 17 | 18 | while (j < n2) { 19 | result[k++] = arr2[j++]; 20 | } 21 | } 22 | 23 | int main() { 24 | int n1, n2; 25 | printf("Enter the size of the first array: "); 26 | scanf("%d", &n1); 27 | int arr1[n1]; 28 | printf("Enter the elements of the first array (sorted): "); 29 | for (int i = 0; i < n1; i++) { 30 | scanf("%d", &arr1[i]); 31 | } 32 | 33 | printf("Enter the size of the second array: "); 34 | scanf("%d", &n2); 35 | int arr2[n2]; 36 | printf("Enter the elements of the second array (sorted): "); 37 | for (int i = 0; i < n2; i++) { 38 | scanf("%d", &arr2[i]); 39 | } 40 | 41 | int result[n1 + n2]; 42 | mergeArrays(arr1, n1, arr2, n2, result); 43 | 44 | printf("Merged array: "); 45 | for (int i = 0; i < n1 + n2; i++) { 46 | printf("%d ", result[i]); 47 | } 48 | printf("\n"); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /output/MultiplicationTable.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/MultiplicationTable.exe -------------------------------------------------------------------------------- /output/NaturalNumSum.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/NaturalNumSum.exe -------------------------------------------------------------------------------- /output/Numtriangle.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/Numtriangle.exe -------------------------------------------------------------------------------- /output/Palindrome.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/Palindrome.exe -------------------------------------------------------------------------------- /output/ParentId.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | pid_t pid; 7 | pid=fork(); 8 | 9 | printf("Parent pid=%d\n",getppid()); 10 | printf("child pid=%d\n",getpid()); 11 | if(pid<0) 12 | { 13 | fprintf(stderr,"Fork Failed"); 14 | return 1; 15 | } 16 | else if(pid==0) 17 | { 18 | execlp("/bin/ls","ls",NULL); 19 | 20 | } 21 | 22 | else 23 | { 24 | wait(NULL); 25 | printf("Child Complete"); 26 | } 27 | 28 | return 0; 29 | 30 | } -------------------------------------------------------------------------------- /output/PascalTriangle.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/PascalTriangle.exe -------------------------------------------------------------------------------- /output/PerfectNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int num, sum = 0; 5 | printf("Enter a number: "); 6 | scanf("%d", &num); 7 | 8 | for (int i = 1; i <= num / 2; i++) { 9 | if (num % i == 0) { 10 | sum += i; 11 | } 12 | } 13 | 14 | if (sum == num) { 15 | printf("%d is a perfect number.\n", num); 16 | } else { 17 | printf("%d is not a perfect number.\n", num); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /output/PrintPattern.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/PrintPattern.exe -------------------------------------------------------------------------------- /output/Priority.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int p[20],bt[20],pri[20], wt[20],tat[20],i,k,n,temp; 5 | float wtavg,tatavg; 6 | printf("Enter the number of processes --- "); 7 | scanf("%d",&n); 8 | for(i=0;ipri[k]){ 16 | temp=p[i]; 17 | p[i]=p[k]; 18 | p[k]=temp; 19 | temp=bt[i]; 20 | bt[i]=bt[k]; 21 | bt[k]=temp; 22 | temp=pri[i]; 23 | pri[i]=pri[k]; 24 | pri[k]=temp; 25 | } 26 | wtavg=wt[0]=0; 27 | tatavg=tat[0]=bt[0]; 28 | for(i=1;i 2 | void main() 3 | { 4 | int buffer[10],bufsize,in,out,produce,consume,choice=0;in=0; 5 | out=0; 6 | bufsize=10; 7 | while(choice!=3) 8 | { 9 | printf("\n1.Produce\t2.Consume\t3.Exit"); 10 | printf("\nEnter your choice: "); 11 | scanf("%d",&choice); 12 | switch(choice) 13 | { 14 | case 1:if((in+1)%bufsize==out) 15 | printf("\nBuffer is Full"); 16 | else 17 | { 18 | 19 | } 20 | break;;; 21 | printf("\nEnter the value:"); 22 | scanf("%d",&produce); 23 | buffer[in]=produce; 24 | in=(in+1)%bufsize; 25 | case 2:if(in == out) 26 | printf("\nBuffer is Empty"); 27 | else 28 | { 29 | consume=buffer[out]; 30 | printf("\nThe consumed value is %d",consume); 31 | out=(out+1)%bufsize; 32 | } 33 | break; 34 | } } } 35 | -------------------------------------------------------------------------------- /output/PyramidPattern.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/PyramidPattern.exe -------------------------------------------------------------------------------- /output/Reader.c: -------------------------------------------------------------------------------- 1 | /* Reader Process */ 2 | /*reader_process.c*/ 3 | 4 | #include; 5 | #include; 6 | #include; 7 | #include; 8 | #include; 9 | #define MAX_BUF 1024 10 | int main() 11 | { 12 | int fd; 13 | /* A temp FIFO file is not created in reader */ 14 | char *myfifo=&"/tmp/myfifo"; 15 | char buf[MAX_BUF]; 16 | /* open, read, and display the message from the FIFO */ 17 | fd=open(myfifo, O_RDONLY); 18 | read(fd,buf,MAX_BUF); 19 | printf("Writer: %s\n",buf); 20 | close(fd); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /output/RoundRobin.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int i,j,n,bu[10],wa[10],tat[10],t,ct[10],max; 5 | float awt=0,att=0,temp=0; 6 | 7 | printf("Enter the no of processes -- "); 8 | scanf("%d",&n); 9 | for(i=0;i 2 | /*#include*/ 3 | void main() 4 | { 5 | int p[20], bt[20], wt[20], tat[20], i, k, n, temp; 6 | float wtavg,tatavg; 7 | printf("\nEnter the number of processes -- "); 8 | scanf("%d", &n); 9 | for(i=0;ibt[k]) 18 | { 19 | temp=bt[i]; 20 | bt[i]=bt[k]; 21 | bt[k]=temp; 22 | temp=p[i]; 23 | p[i]=p[k]; 24 | p[k]=temp; 25 | } 26 | wt[0]=wtavg=0; 27 | tat[0]=tatavg=bt[0]; 28 | for(i=1;i 2 | void main() 3 | { 4 | printf("Hello World!"); 5 | printf("Hello wolrd!"); 6 | } -------------------------------------------------------------------------------- /output/SinglelevelDirectory.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/SinglelevelDirectory.exe -------------------------------------------------------------------------------- /output/SmallestNum.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/SmallestNum.exe -------------------------------------------------------------------------------- /output/StackOperation.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/StackOperation.exe -------------------------------------------------------------------------------- /output/StringPalindrome.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/StringPalindrome.exe -------------------------------------------------------------------------------- /output/StudentInformation.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/StudentInformation.exe -------------------------------------------------------------------------------- /output/SumofDigits.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int num, sum = 0; 5 | printf("Enter a number: "); 6 | scanf("%d", &num); 7 | 8 | while (num != 0) { 9 | sum += num % 10; 10 | num /= 10; 11 | } 12 | 13 | printf("Sum of digits: %d\n", sum); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /output/SumofDigits.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/SumofDigits.exe -------------------------------------------------------------------------------- /output/SumofNaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n, sum = 0; 5 | printf("Enter a number: "); 6 | scanf("%d", &n); 7 | 8 | for (int i = 1; i <= n; i++) { 9 | sum += i; 10 | } 11 | 12 | printf("Sum of first %d natural numbers is: %d\n", n, sum); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /output/TranspoeMatrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int r, c, matrix[10][10], t[10][10]; 4 | printf("Enter the number of rows and columns: "); 5 | scanf("%d %d", &r, &c); 6 | printf("Enter elements of the matrix:\n"); 7 | for (int i = 0; i < r; i++) { 8 | for (int j = 0; j < c; j++) { 9 | scanf("%d", &matrix[i][j]); 10 | } 11 | } 12 | for (int i = 0; i < r; i++) { 13 | for (int j = 0; j < c; j++) { 14 | t[j][i] = matrix[i][j]; 15 | } 16 | } 17 | printf("Transpose of the matrix:\n"); 18 | for (int i = 0; i < c; i++) { 19 | for (int j = 0; j < r; j++) { 20 | printf("%d ", t[i][j]); 21 | } 22 | printf("\n"); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /output/TransposeMatrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int r, c; 4 | printf("Enter the number of rows and columns: "); 5 | scanf("%d %d", &r, &c); 6 | int matrix[r][c], t[c][r]; 7 | printf("Enter elements of the matrix:\n"); 8 | for (int i = 0; i < r; i++) { 9 | for (int j = 0; j < c; j++) { 10 | scanf("%d", &matrix[i][j]); 11 | } 12 | } 13 | for (int i = 0; i < r; i++) { 14 | for (int j = 0; j < c; j++) { 15 | t[j][i] = matrix[i][j]; 16 | } 17 | } 18 | printf("Transpose of the matrix:\n"); 19 | for (int i = 0; i < c; i++) { 20 | for (int j = 0; j < r; j++) { 21 | printf("%d ", t[i][j]); 22 | } 23 | printf("\n"); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /output/TwoLevelDirectory.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/TwoLevelDirectory.exe -------------------------------------------------------------------------------- /output/WorstFit.c: -------------------------------------------------------------------------------- 1 | /*WORST-FIT*/ 2 | #include 3 | /*#include*/ 4 | #define max 25 5 | void main() 6 | { 7 | int frag[max],b[max],f[max],i,j,nb,nf,temp; 8 | static int bf[max],ff[max]; 9 | 10 | printf("\n\tMemory Management Scheme - First Fit"); 11 | printf("\nEnter the number of blocks:"); 12 | scanf("%d",&nb); 13 | printf("Enter the number of files:"); 14 | scanf("%d",&nf); 15 | printf("\nEnter the size of the blocks:-\n"); 16 | for(i=1;i<=nb;i++) 17 | { 18 | printf("Block %d:",i); 19 | scanf("%d",&b[i]); 20 | } 21 | printf("Enter the size of the files :-\n"); 22 | for(i=1;i<=nf;i++) 23 | { 24 | printf("File %d:",i); 25 | scanf("%d",&f[i]); 26 | } 27 | for(i=1;i<=nf;i++) 28 | { 29 | for(j=1;j<=nb;j++) 30 | { 31 | if(bf[j]!=1) 32 | { 33 | temp=b[j]-f[i]; 34 | if(temp>=0) 35 | { 36 | ff[i]=j; 37 | break; 38 | } 39 | } 40 | } 41 | frag[i]=temp; 42 | bf[ff[i]]=1; 43 | } 44 | printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement"); 45 | for(i=1;i<=nf;i++) 46 | printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /output/Writer.c: -------------------------------------------------------------------------------- 1 | #include; 2 | #include; 3 | #include; 4 | #include; 5 | #include; 6 | int main() 7 | { 8 | int fd; 9 | char buf[1024]; 10 | /* create the FIFO (named pipe) */ 11 | char * myfifo="/tmp/myfifo"; 12 | mkfifo(myfifo,0666); 13 | printf("Run Reader process to read the FIFO File\n"); 14 | fd=open(myfifo, O_WRONLY); 15 | write(fd,"Hi",sizeof("Hi")); 16 | /* write "Hi" to the FIFO */ 17 | close(fd); 18 | unlink(myfifo); /* remove the FIFO */ 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /output/armsrtong.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/armsrtong.exe -------------------------------------------------------------------------------- /output/matrixSub.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int r, c, a[10][10], b[10][10], diff[10][10]; 4 | printf("Enter the number of rows and columns : "); 5 | scanf("%d %d", &r, &c); 6 | printf("Enter elements of first matrix:\n"); 7 | for (int i = 0; i < r; i++) { 8 | for (int j = 0; j < c; j++) { 9 | scanf("%d", &a[i][j]); 10 | } 11 | } 12 | printf("Enter elements of second matrix:\n"); 13 | for (int i = 0; i < r; i++) { 14 | for (int j = 0; j < c; j++) { 15 | scanf("%d", &b[i][j]); 16 | } 17 | } 18 | for (int i = 0; i < r; i++) { 19 | for (int j = 0; j < c; j++) { 20 | diff[i][j] = a[i][j] - b[i][j]; 21 | } 22 | } 23 | printf("Difference of matrices:\n"); 24 | for (int i = 0; i < r; i++) { 25 | for (int j = 0; j < c; j++) { 26 | printf("%d ", diff[i][j]); 27 | } 28 | printf("\n"); 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /output/output/BestFit.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/BestFit.exe -------------------------------------------------------------------------------- /output/output/C-ScanDiskScheduling.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/C-ScanDiskScheduling.exe -------------------------------------------------------------------------------- /output/output/CelsiustoFarenheit.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/CelsiustoFarenheit.exe -------------------------------------------------------------------------------- /output/output/CheckEualMatrix.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/CheckEualMatrix.exe -------------------------------------------------------------------------------- /output/output/DecimaltoBinary.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/DecimaltoBinary.exe -------------------------------------------------------------------------------- /output/output/FactorialUsingRecursion.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/FactorialUsingRecursion.exe -------------------------------------------------------------------------------- /output/output/LinkedFileAllocation.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/LinkedFileAllocation.exe -------------------------------------------------------------------------------- /output/output/MatrixAdd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/MatrixAdd.exe -------------------------------------------------------------------------------- /output/output/MergeArrays.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/MergeArrays.exe -------------------------------------------------------------------------------- /output/output/PerfectNumber.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/PerfectNumber.exe -------------------------------------------------------------------------------- /output/output/Priority.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/Priority.exe -------------------------------------------------------------------------------- /output/output/ProducerConsumer.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/ProducerConsumer.exe -------------------------------------------------------------------------------- /output/output/RoundRobin.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/RoundRobin.exe -------------------------------------------------------------------------------- /output/output/SJF.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/SJF.exe -------------------------------------------------------------------------------- /output/output/Simple.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/Simple.exe -------------------------------------------------------------------------------- /output/output/SumofDigits.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/SumofDigits.exe -------------------------------------------------------------------------------- /output/output/SumofNaturalNum.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/SumofNaturalNum.exe -------------------------------------------------------------------------------- /output/output/TranspoeMatrix.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/TranspoeMatrix.exe -------------------------------------------------------------------------------- /output/output/TransposeMatrix.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/TransposeMatrix.exe -------------------------------------------------------------------------------- /output/output/WorstFit.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/WorstFit.exe -------------------------------------------------------------------------------- /output/output/matrixSub.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/output/matrixSub.exe -------------------------------------------------------------------------------- /output/reverse_string.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/reverse_string.exe -------------------------------------------------------------------------------- /output/selection.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/selection.exe -------------------------------------------------------------------------------- /output/sliding_window.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/sliding_window.exe -------------------------------------------------------------------------------- /output/sum_of_triplet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/sum_of_triplet.exe -------------------------------------------------------------------------------- /output/swap_using_xor.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/swap_using_xor.exe -------------------------------------------------------------------------------- /output/swap_without_temp_var.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/output/swap_without_temp_var.exe -------------------------------------------------------------------------------- /prime_between_range.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int j,i,n,m,flag=0; 5 | printf("Enter starting range: "); 6 | scanf("%d",&m); 7 | printf("Enter ending range: "); 8 | scanf("%d",&n); 9 | for(j = m;j<=n;j++){ 10 | flag = 0; 11 | for(i=2;i*i<=j;i++){ 12 | if(j % i==0){ 13 | flag=1; 14 | break; 15 | } 16 | } 17 | 18 | if(flag==0) 19 | printf("%d\t",j); 20 | } 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /prime_upto_n.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int j,i,n,flag=0; 5 | printf("Enter a range: "); 6 | scanf("%d",&n); 7 | for(j = 2;j<=n;j++){ 8 | flag = 0; 9 | for(i=2;i<=j/2;i++){ 10 | if(j % i==0){ 11 | flag=1; 12 | break; 13 | } 14 | } 15 | 16 | if(flag==0) 17 | printf("%d ",j); 18 | } 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /reverse_string.c: -------------------------------------------------------------------------------- 1 | #include 2 | int *rev(char *p) 3 | { 4 | static char a[100]; 5 | static int i; 6 | 7 | if(*p) 8 | { 9 | rev(p+1); 10 | a[i++]=*p; 11 | } 12 | 13 | return a; 14 | } 15 | void main() 16 | { 17 | char str[100]; 18 | printf("Enter a string:"); 19 | scanf("%[^\n]s",str); 20 | printf("Reversed string is:%s",rev(str)); 21 | } 22 | -------------------------------------------------------------------------------- /sample.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/sample.txt -------------------------------------------------------------------------------- /selectionsort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void readArray(int arr[], int n) { 4 | for( int i=0; iarr[j]){ 26 | min=j; 27 | } 28 | } 29 | swap( &arr[min], &arr[i] ); 30 | } 31 | } 32 | 33 | int main() { 34 | int n, arr[10]; 35 | 36 | printf("Enter the size of the array:"); 37 | scanf("%d",&n); 38 | 39 | printf("Enter the elements of the array:"); 40 | readArray( arr, n); 41 | 42 | 43 | printf("Before Sorting:"); 44 | printArray( arr , n); 45 | 46 | insertionSort( arr , n); 47 | 48 | printf("\nAfter Sorting:"); 49 | printArray(arr , n); 50 | 51 | 52 | return 0; 53 | } -------------------------------------------------------------------------------- /sliding_window.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void readArray(int arr[], int n) 4 | { 5 | for (int i = 0; i < n; i++) 6 | { 7 | scanf("%d", &arr[i]); 8 | } 9 | } 10 | 11 | void printArray(int arr[], int n) 12 | { 13 | for (int i = 0; i < n; i++) 14 | printf(" %d ", arr[i]); 15 | } 16 | void SubArray(int arr[], int n, int k) 17 | { 18 | int i, j, curr_sum, max_sum; 19 | curr_sum = 0; 20 | for( i=0; i max_sum ) 27 | max_sum = curr_sum; 28 | } 29 | 30 | printf("sum=%d",max_sum); 31 | } 32 | 33 | int main() 34 | { 35 | int n, k, arr[10]; 36 | 37 | printf("Enter the size of the array:"); 38 | scanf("%d", &n); 39 | 40 | printf("Enter the elements of the array:"); 41 | readArray(arr, n); 42 | 43 | printf("Enter k:"); 44 | scanf("%d", &k); 45 | 46 | SubArray(arr, n, k); 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /sliding_window.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pavanraj07/C_programming/5ae73a772b017fc1846ac52d027a654fa9a001af/sliding_window.exe -------------------------------------------------------------------------------- /sort_till_k.c: -------------------------------------------------------------------------------- 1 | //sort array till k in ascending and remaining in descending 2 | #include 3 | 4 | void readArray(int arr[], int n) { 5 | for( int i=0; iarr[j+1]){ 28 | swap( &arr[j], &arr[j+1] ); 29 | status = 1; 30 | } 31 | } 32 | if( status == 0 ) 33 | break; 34 | } 35 | for( k; k 2 | 3 | void readArray(int arr[], int n) { 4 | for( int i=0; i 2 | 3 | int main() 4 | { 5 | int a,b; 6 | printf("Enter value of a and b:"); 7 | scanf("%d%d",&a,&b); 8 | a=a^b; 9 | b=a^b; 10 | a=a^b; 11 | printf(" value of a and b after swapping:%d %d",a,b); 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /swap_without_temp_var.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a,b; 6 | printf("Enter value of a and b:"); 7 | scanf("%d%d",&a,&b); 8 | a=a+b; 9 | b=a-b; 10 | a=a-b; 11 | printf(" value of a and b after swapping:%d %d",a,b); 12 | 13 | return 0; 14 | } --------------------------------------------------------------------------------