├── .DS_Store ├── .gitignore ├── 2nd largest (pointer) ├── Algorithms ├── Assignment.c ├── BinaryTree.c ├── Comb-Sort.c ├── Counting Sort.c ├── KnapSack.c ├── SlidingWindowAlgorithm.cpp ├── Ternary_Search.c ├── binary_search.c ├── bubblesort.c ├── counting_sort.c ├── heapsort.c ├── hypotenuse.c ├── insertionsort.c ├── lcs.c ├── linear_search.c ├── mergesort.c ├── quicksort.c ├── selectionsort.c ├── selectionsort_recursive.c └── sieve-of-eratosthenes.c ├── Arrays ├── addmatrix.c ├── addmatrix.exe ├── addmatrix.o ├── ascendingorder.c ├── averageandsum.c ├── averageandsum.exe ├── averageandsum.o ├── biggestnumber.c ├── biggestnumber.exe ├── biggestnumber.o ├── copyonearraytoanother.c ├── copyonearraytoanother.exe ├── copyonearraytoanother.o ├── countposnegzero.c ├── countposnegzero.exe ├── countposnegzero.o ├── countrepeatedletter.c ├── countrepeatedletter.exe ├── countrepeatedletter.o ├── dectobin.c ├── dectobin.exe ├── dectobin.o └── descendingorder.c ├── Bubble Sorting with pointers ├── CONTRIBUTING.md ├── Conditional statements ├── Data Science.pdf ├── a.exe ├── ab.c ├── ab.exe ├── age.c ├── age.exe ├── assignment1.c ├── assignment1.exe ├── custom.c └── custom.exe ├── Dynamic memory allocation ├── Functions ├── areaofcircle.c ├── areaofcircle.exe ├── areaofcircle.o ├── dectobin.c ├── dectobin.exe ├── dectobin.o ├── factorial.c ├── factorial.exe ├── factorial.o ├── factors.c ├── factors.exe ├── factors.o ├── functions.c ├── functions.exe ├── functions.o ├── functions1.c ├── functions1.exe ├── functions1.o ├── lcm.c ├── lcm.exe ├── lcm.o ├── multiply2values.c ├── multiply2values.exe ├── multiply2values.o ├── oddoreven.c ├── oddoreven.exe ├── oddoreven.o ├── primeornot.c ├── primeornot.exe ├── primeornot.o └── printnaturalnos.c ├── LICENSE ├── Programs ├── Adding_Time.c ├── Areas of Different Geometrical Figures ├── BinaryToDecimal.c ├── Character_Classification.c ├── DecToBinary.c ├── DiceRoll.c ├── Factorial.c ├── Factorial_Recursion.c ├── Fibonacci_Recursion.c ├── Fibonachi.c ├── Insertion_sort.c ├── LARGEfactorial.c ├── LeapYear.c ├── Partition_Set.c ├── Populating_array_and_finding_time_taken.c ├── Prime Number.c ├── Pythagorean Triplet.c ├── Square_if_multiple_of_5_else_Circle.c ├── Sum_of_series.c ├── TowerofHanoi.c ├── armstrongNumber.c ├── babylonian_method.c ├── calculator.c ├── concentric-rectangles.c ├── decimalToBinary.c ├── dectobin.c ├── factor_of_number.c ├── findingChar.c ├── game.c ├── gcd.c ├── generate_random_numbers_finding_prime.c ├── largeelementarray.c ├── largefactorial.c ├── mastermind.c ├── matrix_multiply.c ├── merge sort.c ├── minmax.c ├── nThRoot.c ├── palindrom.c ├── perfectno.c ├── power_)recur.c ├── qsort.c ├── queuearray.c ├── random.c ├── reverse_a_number.c ├── reverse_string.c ├── selectionsort.c ├── sqrt.c ├── sum_of_digit.c ├── sumdiag.c ├── swapNumbersWithoutThirdVariable.c ├── swap_numbers.c └── writefile.c ├── README.md ├── Recursion ├── factorial.c ├── factorial.exe ├── factorial.o ├── gcd.c ├── gcd.exe ├── gcd.o ├── lcm.c ├── lcm.exe ├── lcm.o ├── lcm1.c ├── lcm1.exe ├── lcm1.o ├── power.c ├── power.exe ├── power.o ├── sumofn.c ├── sumofn.exe └── sumofn.o ├── STACK IMPLEMENTATION ├── Stack Linked list.c ├── basic practice ├── area_of_circle.c ├── area_of_rectangle.c └── celsius_to_fahrenheit.c ├── calloc.c ├── calloc.exe ├── calloc.o ├── find_leap_year.c ├── insert_sort.c ├── malloc.c ├── malloc.exe ├── malloc.o ├── pointer ├── Address.c ├── Address.exe ├── Address.o ├── address2.c ├── address2.exe ├── address2.o ├── call by reference.c ├── call by reference.exe ├── call by reference.o ├── call by value.c ├── call by value.exe ├── call by value.o ├── display structure.c ├── display structure.exe ├── display structure.o ├── exchange variable.c ├── exchange variable.exe └── exchange variable.o ├── queueprogram.c ├── rock_paper_scissor.c ├── selection_sort.c ├── stringwithoutfunctions ├── comparestring.c ├── comparestring.exe ├── comparestring.o ├── copystring.c ├── copystring.exe ├── copystring.o ├── copystring2.c ├── lengthofstrings.c ├── lengthofstrings.exe ├── lengthofstrings.o ├── lowertoupper.c ├── lowertoupper.exe ├── lowertoupper.o ├── reversethestring.c ├── reversethestring.exe ├── reversethestring.o ├── uppertolower.c ├── uppertolower.exe └── uppertolower.o ├── ternaryoperator ├── useofdma.c ├── useofdma.exe └── useofdma.o /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/.DS_Store -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /2nd largest (pointer): -------------------------------------------------------------------------------- 1 | #include 2 | void fun(int,int*); 3 | int main() 4 | { 5 | int n; 6 | scanf("%d",&n); 7 | int a[n]; 8 | int *ptr=a; 9 | 10 | for(int i = 0; i < n; i++) 11 | scanf("%d",&a[i]); 12 | 13 | 14 | 15 | fun(n,ptr); 16 | 17 | printf("%d",a[1]); 18 | 19 | } 20 | 21 | void fun(int n, int* ptr) 22 | { 23 | int i, j, t; 24 | for (i = 0; i < n; i++) { 25 | 26 | for (j = i + 1; j < n; j++) { 27 | 28 | if (*(ptr + j) > *(ptr + i)) { 29 | 30 | t = *(ptr + i); 31 | *(ptr + i) = *(ptr + j); 32 | *(ptr + j) = t; 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Algorithms/Assignment.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int size, minCost = 100, **mat, *sol; 5 | 6 | /*int fact(int n){ 7 | int fact = 0; 8 | for(int i=2;i<=n;i++){ 9 | fact *= i; 10 | } 11 | return fact; 12 | }*/ 13 | 14 | void swap(int *x, int *y){ 15 | int temp; 16 | temp = *x; 17 | *x = *y; 18 | *y = temp; 19 | } 20 | 21 | void permute(int *a, int l, int r){ 22 | int i, cost = 0; 23 | if (l == r){ 24 | for(int j=0;j 2 | #include 3 | 4 | //Structure definitions... 5 | struct Node{ 6 | int data; 7 | struct Node *left,*right; 8 | }; 9 | typedef struct Node *Nodeptr; 10 | 11 | //Function declarations... 12 | void inorder_rec(Nodeptr root); 13 | void preorder_rec(Nodeptr root); 14 | void postorder_rec(Nodeptr root); 15 | void insert_iter(Nodeptr* root_ref, int data); 16 | 17 | 18 | //main() starts here... 19 | int main(){ 20 | 21 | Nodeptr root = NULL; 22 | int data; 23 | int choice; 24 | 25 | do{ 26 | printf("\n===================================MENU=========================================\n\n"); 27 | printf("1. Search/Add Key Value in the binary tree\n"); 28 | printf("2. Display pre-order traversal of the binary tree\n"); 29 | printf("3. Display in-order traversal of the binary tree\n"); 30 | printf("4. Display post-order traversal of the binary tree\n"); 31 | printf("5. Exit program\n"); 32 | printf("\nEnter your Choice:\t"); 33 | 34 | scanf("%d",&choice); 35 | 36 | switch(choice){ 37 | 38 | case 1:{ 39 | printf("\nEnter the node value:\t"); 40 | scanf("%d",&data); 41 | insert_iter(&root,data); 42 | } 43 | break; 44 | 45 | case 2:{ 46 | printf("Printing the pre-order traversal of the binary tree...\n"); 47 | preorder_rec(root); 48 | } 49 | break; 50 | 51 | case 3:{ 52 | printf("Printing the in-order traversal of the binary tree...\n"); 53 | inorder_rec(root); 54 | } 55 | break; 56 | 57 | case 4:{ 58 | printf("Printing the post-order traversal of the binary tree...\n"); 59 | postorder_rec(root); 60 | } 61 | break; 62 | 63 | case 5:{ 64 | printf("\nGoodbye...\n"); 65 | } 66 | break; 67 | 68 | default:{ 69 | printf("\nInvalide choice. Please enter a different choice next time...\n"); 70 | } 71 | break; 72 | } 73 | }while(choice!=5); 74 | 75 | return 0; 76 | } 77 | //End of main()... 78 | 79 | //Function definitions start here... 80 | void inorder_rec(Nodeptr root){ //This function recursively prints the in-order traversal from the given node of a tree... 81 | if(root){ 82 | inorder_rec(root->left); 83 | printf("%d ",root->data); 84 | inorder_rec(root->right); 85 | } 86 | } 87 | 88 | void preorder_rec(Nodeptr root){ //This function recursively prints the pre-order traversal from the given node of a tree... 89 | if(root){ 90 | printf("%d ",root->data); 91 | preorder_rec(root->left); 92 | preorder_rec(root->right); 93 | } 94 | } 95 | 96 | void postorder_rec(Nodeptr root){ //This function recursively prints the post-order traversal from the given node of a tree... 97 | if(root){ 98 | postorder_rec(root->left); 99 | postorder_rec(root->right); 100 | printf("%d ",root->data); 101 | } 102 | } 103 | 104 | void insert_iter(Nodeptr *root_ref, int data){ //This function searches for a key value in a BST, and inserts the value if it is not present... 105 | 106 | Nodeptr cur = *root_ref; 107 | Nodeptr temp = (struct Node*)malloc(sizeof(struct Node)); 108 | temp->data = data; 109 | temp->left = temp->right = NULL; 110 | 111 | if( (*root_ref) == NULL){ 112 | *root_ref = temp; 113 | return; 114 | } 115 | 116 | while(cur){ 117 | if(cur->data == data){ 118 | printf("Key found in the binary tree\n"); 119 | free(temp); 120 | return; 121 | } 122 | if(data < cur->data){ 123 | if(cur->left){ 124 | cur = cur->left; 125 | } 126 | else{ 127 | cur->left = temp; 128 | break; 129 | } 130 | } 131 | else{ 132 | if(cur->right){ 133 | cur = cur->right; 134 | } 135 | else{ 136 | cur->right = temp; 137 | break; 138 | } 139 | } 140 | } 141 | } 142 | //End of function definitions... 143 | 144 | //End of code... -------------------------------------------------------------------------------- /Algorithms/Comb-Sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Program to perform comb sort on an integer with a gap factor of 1.3 5 | // Time Complexity: Best case O(n), Worst case O(n^2) 6 | // Performs better than bubble sort on average 7 | 8 | void combsort(int* arr, int size) { 9 | int gap = (int)(size / 1.3); 10 | 11 | int sorted = 0; 12 | while (!sorted) { 13 | 14 | sorted = 1; 15 | 16 | for (int i = 0; i + gap < size; i++) { 17 | 18 | if (arr[i] > arr[i+gap]) 19 | { 20 | int temp = arr[i]; 21 | arr[i] = arr[i+gap]; 22 | arr[i+gap] = temp; 23 | sorted = 0; 24 | } 25 | 26 | } 27 | gap = (int)(gap / 1.3); 28 | } 29 | 30 | } 31 | int main() 32 | { 33 | int n; 34 | printf("Enter the size of the array:\n"); 35 | scanf("%d", &n); 36 | 37 | int* arr = (int*)malloc(n * sizeof(int)); 38 | 39 | printf("\nEnter the elements in the array:\n"); 40 | for (int i = 0; i < n; i++) 41 | scanf("%d", arr + i); 42 | 43 | combsort(arr, n); 44 | 45 | printf("Sorted array: \n"); 46 | for (int i = 0; i < n; i++) 47 | printf("%d ", arr[i]); 48 | 49 | printf("\n"); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Algorithms/Counting Sort.c: -------------------------------------------------------------------------------- 1 | 2 | filter_none 3 | 4 | edit 5 | 6 | play_arrow 7 | 8 | brightness_4 9 | // C Program for counting sort 10 | #include 11 | #include 12 | #define RANGE 255 13 | 14 | // The main function that sort the given string arr[] in 15 | // alphabatical order 16 | void countSort(char arr[]) 17 | { 18 | // The output character array that will have sorted arr 19 | char output[strlen(arr)]; 20 | 21 | // Create a count array to store count of inidividul 22 | // characters and initialize count array as 0 23 | int count[RANGE + 1], i; 24 | memset(count, 0, sizeof(count)); 25 | 26 | // Store count of each character 27 | for(i = 0; arr[i]; ++i) 28 | ++count[arr[i]]; 29 | 30 | // Change count[i] so that count[i] now contains actual 31 | // position of this character in output array 32 | for (i = 1; i <= RANGE; ++i) 33 | count[i] += count[i-1]; 34 | 35 | // Build the output character array 36 | for (i = 0; arr[i]; ++i) 37 | { 38 | output[count[arr[i]]-1] = arr[i]; 39 | --count[arr[i]]; 40 | } 41 | 42 | /* 43 | For Stable algorithm 44 | for (i = sizeof(arr)-1; i>=0; --i) 45 | { 46 | output[count[arr[i]]-1] = arr[i]; 47 | --count[arr[i]]; 48 | } 49 | 50 | For Logic : See implementation 51 | */ 52 | 53 | // Copy the output array to arr, so that arr now 54 | // contains sorted characters 55 | for (i = 0; arr[i]; ++i) 56 | arr[i] = output[i]; 57 | } 58 | 59 | // Driver program to test above function 60 | int main() 61 | { 62 | char arr[] = "geeksforgeeks";//"applepp"; 63 | 64 | countSort(arr); 65 | 66 | printf("Sorted character array is %sn", arr); 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /Algorithms/KnapSack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int knapsack(unsigned int* w, unsigned int *val, int size, int capacity, int *maxVal, int *finalWeight); 6 | 7 | int main(){ 8 | 9 | unsigned int *w, *val, size, capacity, knaps, index, value, weight; 10 | 11 | printf("Enter the number of items: "); 12 | scanf("%d",&size); 13 | w = (unsigned int*)calloc(size, sizeof(unsigned int)); 14 | val = (unsigned int*)calloc(size, sizeof(unsigned int)); 15 | 16 | printf("Enter the weights of the items: "); 17 | for(int i=0;i> 1; 41 | } 42 | 43 | printf("Total Value: %u\tTotal Weight: %u\n", value, weight); 44 | 45 | return 0; 46 | } 47 | 48 | int knapsack(unsigned int* w, unsigned int *val, int size, int capacity, int *maxVal, int *finalWeight){ 49 | 50 | int maxSequence = 0, opCount = 0; 51 | *maxVal = *finalWeight = 0; 52 | unsigned int totalWeight, totalValue, temp, index; 53 | 54 | for(int i=1; i> 1; 66 | } 67 | if(totalWeight <= capacity && totalValue > *maxVal){ 68 | *maxVal = totalValue; 69 | maxSequence = i; 70 | *finalWeight = totalWeight; 71 | } 72 | } 73 | printf("\nOperation Count is %d\n",opCount); 74 | return maxSequence; 75 | } -------------------------------------------------------------------------------- /Algorithms/SlidingWindowAlgorithm.cpp: -------------------------------------------------------------------------------- 1 | // Sliding Window Algorithm -TO find maximum sub array sum of k numbers. 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | int arr[] = {1,2,-6,98,23}; 8 | int n = sizeof(arr)/sizeof(int); 9 | int k; 10 | 11 | cout<<"Enter value of k:"; 12 | cin>>k; 13 | 14 | int sum = 0; 15 | for(int i=0;i 2 | 3 | int ternary_search(int l,int r,int x,int arr[]) 4 | { 5 | if(r>=l){ 6 | int mid1=l+(r-l)/3; 7 | int mid2=r-(r-l)/3; 8 | if(arr[mid1]==x){ 9 | return mid1; 10 | } 11 | if(arr[mid2]==x){ 12 | return mid2; 13 | } 14 | if(xarr[mid2]){ 18 | return ternary_search(mid2+1,r,x,arr); 19 | } 20 | else{ 21 | return ternary_search(mid1+1,mid2-1,x,arr); 22 | } 23 | } 24 | return -1; 25 | } 26 | 27 | int main() 28 | { 29 | int x; 30 | int arr[]={2,3,6,7,8,9,12,16,24,53,64,99}; 31 | x=6; // key to search 32 | int l= 0; 33 | int r=11; 34 | int res = ternary_search(l,r,x,arr); 35 | if(res==-1){ 36 | printf("%d is not found\n",x); 37 | } 38 | else{ 39 | printf("%d is found at index %d\n",x,res); 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Algorithms/binary_search.c: -------------------------------------------------------------------------------- 1 | // C program to implement recursive Binary Search 2 | #include 3 | 4 | 5 | int binarySearch(int arr[], int l, int r, int x) 6 | { 7 | if (r >= l) { 8 | int mid = l + (r - l) / 2; 9 | 10 | // If the element is present at the middle 11 | // itself 12 | if (arr[mid] == x) 13 | return mid; 14 | 15 | // If element is smaller than mid, then 16 | // it can only be present in left subarray 17 | if (arr[mid] > x) 18 | return binarySearch(arr, l, mid - 1, x); 19 | 20 | // Else the element can only be present 21 | // in right subarray 22 | return binarySearch(arr, mid + 1, r, x); 23 | } 24 | 25 | // We reach here when element is not 26 | // present in array 27 | return -1; 28 | } 29 | 30 | int main(void) 31 | { 32 | int arr[] = { 2, 3, 4, 7, 10, 11, 40 }; 33 | int n = sizeof(arr) / sizeof(arr[0]); 34 | int x = 40; 35 | int result = binarySearch(arr, 0, n - 1, x); 36 | (result == -1) ? printf("Element is not present in array \n") : printf("Element is present at index %d \n", result); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Algorithms/bubblesort.c: -------------------------------------------------------------------------------- 1 | // C++ program for implementation of Bubble sort 2 | #include 3 | using namespace std; 4 | 5 | void swap(int *xp, int *yp) 6 | { 7 | int temp = *xp; 8 | *xp = *yp; 9 | *yp = temp; 10 | } 11 | 12 | // A function to implement bubble sort 13 | void bubbleSort(int arr[], int n) 14 | { 15 | int i, j; 16 | for (i = 0; i < n-1; i++) 17 | 18 | // Last i elements are already in place 19 | for (j = 0; j < n-i-1; j++) 20 | if (arr[j] > arr[j+1]) 21 | swap(&arr[j], &arr[j+1]); 22 | } 23 | 24 | /* Function to print an array */ 25 | void printArray(int arr[], int size) 26 | { 27 | int i; 28 | for (i = 0; i < size; i++) 29 | cout << arr[i] << " "; 30 | cout << endl; 31 | } 32 | 33 | // Driver code 34 | int main() 35 | { 36 | int arr[] = {64, 34, 25, 12, 22, 11, 90}; 37 | int n = sizeof(arr)/sizeof(arr[0]); 38 | bubbleSort(arr, n); 39 | cout<<"Sorted array: \n"; 40 | printArray(arr, n); 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Algorithms/counting_sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void counting_sort(int a[],int n,int max) 4 | { 5 | int count[50]={0},i,j; 6 | 7 | for(i=0;imax) 28 | max=a[i]; 29 | } 30 | 31 | counting_sort(a,n,max); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Algorithms/heapsort.c: -------------------------------------------------------------------------------- 1 | // C++ program for implementation of Heap Sort 2 | #include 3 | 4 | using namespace std; 5 | 6 | // To heapify a subtree rooted with node i which is 7 | // an index in arr[]. n is size of heap 8 | void heapify(int arr[], int n, int i) 9 | { 10 | int largest = i; // Initialize largest as root 11 | int l = 2*i + 1; // left = 2*i + 1 12 | int r = 2*i + 2; // right = 2*i + 2 13 | 14 | // If left child is larger than root 15 | if (l < n && arr[l] > arr[largest]) 16 | largest = l; 17 | 18 | // If right child is larger than largest so far 19 | if (r < n && arr[r] > arr[largest]) 20 | largest = r; 21 | 22 | // If largest is not root 23 | if (largest != i) 24 | { 25 | swap(arr[i], arr[largest]); 26 | 27 | // Recursively heapify the affected sub-tree 28 | heapify(arr, n, largest); 29 | } 30 | } 31 | 32 | // main function to do heap sort 33 | void heapSort(int arr[], int n) 34 | { 35 | // Build heap (rearrange array) 36 | for (int i = n / 2 - 1; i >= 0; i--) 37 | heapify(arr, n, i); 38 | 39 | // One by one extract an element from heap 40 | for (int i=n-1; i>=0; i--) 41 | { 42 | // Move current root to end 43 | swap(arr[0], arr[i]); 44 | 45 | // call max heapify on the reduced heap 46 | heapify(arr, i, 0); 47 | } 48 | } 49 | 50 | /* A utility function to print array of size n */ 51 | void printArray(int arr[], int n) 52 | { 53 | for (int i=0; i 17 | #include 18 | #include 19 | 20 | int main (int argc, char* argv[]) { 21 | if (argc <= 2) { 22 | printf("Not enough arguments!"); 23 | return 0; 24 | } 25 | else { 26 | double a = atof(argv[1]); 27 | double b = atof(argv[2]); 28 | double c = sqrt((a * a) + (b * b)); 29 | printf("The hypotenuse is: %lf\n", c); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Algorithms/insertionsort.c: -------------------------------------------------------------------------------- 1 | 2 | // C++ program for insertion sort 3 | #include 4 | using namespace std; 5 | 6 | /* Function to sort an array using insertion sort*/ 7 | void insertionSort(int arr[], int n) 8 | { 9 | int i, key, j; 10 | for (i = 1; i < n; i++) 11 | { 12 | key = arr[i]; 13 | j = i - 1; 14 | 15 | /* Move elements of arr[0..i-1], that are 16 | greater than key, to one position ahead 17 | of their current position */ 18 | while (j >= 0 && arr[j] > key) 19 | { 20 | arr[j + 1] = arr[j]; 21 | j = j - 1; 22 | } 23 | arr[j + 1] = key; 24 | } 25 | } 26 | 27 | // A utility function to print an array of size n 28 | void printArray(int arr[], int n) 29 | { 30 | int i; 31 | for (i = 0; i < n; i++) 32 | cout << arr[i] << " "; 33 | cout << endl; 34 | } 35 | 36 | /* Driver code */ 37 | int main() 38 | { 39 | int arr[] = { 12, 11, 13, 5, 6 }; 40 | int n = sizeof(arr) / sizeof(arr[0]); 41 | 42 | insertionSort(arr, n); 43 | printArray(arr, n); 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Algorithms/lcs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int i,j,m,n,c[20][20]; 5 | char x[20],y[20],b[20][20]; 6 | 7 | void print(int i,int j) 8 | { 9 | if(i==0 || j==0) 10 | return; 11 | if(b[i][j]=='c') 12 | { 13 | print(i-1,j-1); 14 | printf("%c",x[i-1]); 15 | } 16 | else if(b[i][j]=='u') 17 | print(i-1,j); 18 | else 19 | print(i,j-1); 20 | } 21 | 22 | void lcs() 23 | { 24 | m=strlen(x); 25 | n=strlen(y); 26 | for(i=0;i<=m;i++) 27 | c[i][0]=0; 28 | for(i=0;i<=n;i++) 29 | c[0][i]=0; 30 | 31 | //c, u and l denotes cross, upward and downward directions respectively 32 | for(i=1;i<=m;i++) 33 | for(j=1;j<=n;j++) 34 | { 35 | if(x[i-1]==y[j-1]) 36 | { 37 | c[i][j]=c[i-1][j-1]+1; 38 | b[i][j]='c'; 39 | } 40 | else if(c[i-1][j]>=c[i][j-1]) 41 | { 42 | c[i][j]=c[i-1][j]; 43 | b[i][j]='u'; 44 | } 45 | else 46 | { 47 | c[i][j]=c[i][j-1]; 48 | b[i][j]='l'; 49 | } 50 | } 51 | } 52 | 53 | int main() 54 | { 55 | printf("Enter 1st sequence:"); 56 | scanf("%s",x); 57 | printf("Enter 2nd sequence:"); 58 | scanf("%s",y); 59 | printf("\nThe Longest Common Subsequence is "); 60 | lcs(); 61 | print(m,n); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /Algorithms/linear_search.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int search(int arr[], int n, int x) 4 | { 5 | int i; 6 | for (i = 0; i < n; i++) 7 | if (arr[i] == x) 8 | return i; 9 | return -1; 10 | } 11 | 12 | int main(void) 13 | { 14 | int arr[] = { 2, 3, 4, 7, 10, 11, 40 }; 15 | int x = 10; 16 | int n = sizeof(arr) / sizeof(arr[0]); 17 | int result = search(arr, n, x); 18 | (result == -1) ? printf("Element is not present in array \n") : printf("Element is present at index %d \n", result); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Algorithms/mergesort.c: -------------------------------------------------------------------------------- 1 | /* C program for Merge Sort */ 2 | #include 3 | #include 4 | 5 | // Merges two subarrays of arr[]. 6 | // First subarray is arr[l..m] 7 | // Second subarray is arr[m+1..r] 8 | void merge(int arr[], int l, int m, int r) 9 | { 10 | int i, j, k; 11 | int n1 = m - l + 1; 12 | int n2 = r - m; 13 | 14 | /* create temp arrays */ 15 | int L[n1], R[n2]; 16 | 17 | /* Copy data to temp arrays L[] and R[] */ 18 | for (i = 0; i < n1; i++) 19 | L[i] = arr[l + i]; 20 | for (j = 0; j < n2; j++) 21 | R[j] = arr[m + 1+ j]; 22 | 23 | /* Merge the temp arrays back into arr[l..r]*/ 24 | i = 0; // Initial index of first subarray 25 | j = 0; // Initial index of second subarray 26 | k = l; // Initial index of merged subarray 27 | while (i < n1 && j < n2) 28 | { 29 | if (L[i] <= R[j]) 30 | { 31 | arr[k] = L[i]; 32 | i++; 33 | } 34 | else 35 | { 36 | arr[k] = R[j]; 37 | j++; 38 | } 39 | k++; 40 | } 41 | 42 | /* Copy the remaining elements of L[], if there 43 | are any */ 44 | while (i < n1) 45 | { 46 | arr[k] = L[i]; 47 | i++; 48 | k++; 49 | } 50 | 51 | /* Copy the remaining elements of R[], if there 52 | are any */ 53 | while (j < n2) 54 | { 55 | arr[k] = R[j]; 56 | j++; 57 | k++; 58 | } 59 | } 60 | 61 | /* l is for left index and r is right index of the 62 | sub-array of arr to be sorted */ 63 | void mergeSort(int arr[], int l, int r) 64 | { 65 | if (l < r) 66 | { 67 | // Same as (l+r)/2, but avoids overflow for 68 | // large l and h 69 | int m = l+(r-l)/2; 70 | 71 | // Sort first and second halves 72 | mergeSort(arr, l, m); 73 | mergeSort(arr, m+1, r); 74 | 75 | merge(arr, l, m, r); 76 | } 77 | } 78 | 79 | /* UTILITY FUNCTIONS */ 80 | /* Function to print an array */ 81 | void printArray(int A[], int size) 82 | { 83 | int i; 84 | for (i=0; i < size; i++) 85 | printf("%d ", A[i]); 86 | printf("\n"); 87 | } 88 | 89 | /* Driver program to test above functions */ 90 | int main() 91 | { 92 | int arr[] = {12, 11, 13, 5, 6, 7}; 93 | int arr_size = sizeof(arr)/sizeof(arr[0]); 94 | 95 | printf("Given array is \n"); 96 | printArray(arr, arr_size); 97 | 98 | mergeSort(arr, 0, arr_size - 1); 99 | 100 | printf("\nSorted array is \n"); 101 | printArray(arr, arr_size); 102 | return 0; 103 | } -------------------------------------------------------------------------------- /Algorithms/quicksort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void swap(int *a, int *b) 4 | { 5 | int temp = *a; 6 | *a = *b; 7 | *b = temp; 8 | } 9 | 10 | int arrPart(int *arr, int low, int high) 11 | { 12 | // Utility function for partitioning arrays 13 | // To be used with quicksort divide and conquer. 14 | int pivot = arr[high]; 15 | int sml = low - 1; 16 | 17 | for (int i = low; i <= high - 1; i++) 18 | { 19 | if (arr[i] <= pivot) 20 | { 21 | sml = sml + 1; 22 | swap(&arr[sml], &arr[i]); 23 | } 24 | } 25 | swap(&arr[sml + 1], &arr[high]); 26 | return (sml + 1); 27 | } 28 | 29 | void quicksort(int *arr, int low, int high) 30 | { 31 | if (low < high) 32 | { 33 | int part = arrPart(arr, low, high); 34 | quicksort(arr, low, part - 1); // sort from low to part 35 | quicksort(arr, part + 1, high); // sort from part to high 36 | } 37 | } 38 | 39 | void printArray(int arr[], int n) 40 | { 41 | printf("["); 42 | for (int i = 0; i < n; i++) 43 | { 44 | printf("%d, ", arr[i]); 45 | } 46 | printf("]\n"); 47 | } 48 | 49 | int main() 50 | { 51 | int arr1[] = {100, 55, 4, 98, 10, 18, 90, 95, 43, 11, 47, 67, 89, 42, 49, 79}; 52 | int n = sizeof(arr1) / sizeof(arr1[0]); 53 | 54 | printf("Original array: "); 55 | printArray(arr1, n); 56 | quicksort(arr1, 0, n - 1); 57 | printf("Sorted array: "); 58 | printArray(arr1, n); 59 | 60 | printf("\n"); 61 | 62 | return 0; 63 | } -------------------------------------------------------------------------------- /Algorithms/selectionsort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Utility function to swap values at two indices in the array 4 | void swap(int arr[], int i, int j) 5 | { 6 | int temp = arr[i]; 7 | arr[i] = arr[j]; 8 | arr[j] = temp; 9 | } 10 | 11 | // Function to perform selection sort on arr[] 12 | void selectionSort(int arr[], int n) 13 | { 14 | // run (n - 1) times 15 | for (int i = 0; i < n - 1; i++) 16 | { 17 | // find the minimum element in the unsorted subarray[i..n-1] 18 | // and swap it with arr[i] 19 | int min = i; 20 | 21 | for (int j = i + 1; j < n; j++) 22 | { 23 | // if arr[j] element is less, then it is the new minimum 24 | if (arr[j] < arr[min]) 25 | min = j; // update index of min element 26 | } 27 | 28 | // swap the minimum element in subarray[i..n-1] with arr[i] 29 | swap(arr, min, i); 30 | } 31 | } 32 | 33 | // Function to print n elements of the array arr 34 | void printArray(int arr[], int n) 35 | { 36 | for (int i = 0; i < n; i++) { 37 | printf("%d ", arr[i]); 38 | } 39 | } 40 | 41 | // main function 42 | int main(void) 43 | { 44 | int arr[] = { 3, 5, 8, 4, 1, 9, -2 }; 45 | int n = sizeof(arr) / sizeof(arr[0]); 46 | 47 | selectionSort(arr, n); 48 | printArray(arr, n); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Algorithms/selectionsort_recursive.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Utility function to swap values at two indices in the array 4 | void swap(int arr[], int i, int j) 5 | { 6 | int temp = arr[i]; 7 | arr[i] = arr[j]; 8 | arr[j] = temp; 9 | } 10 | 11 | // Recursive function to perform selection sort on subarray arr[i..n-1] 12 | void selectionSort(int arr[], int i, int n) 13 | { 14 | // find the minimum element in the unsorted subarray[i..n-1] 15 | // and swap it with arr[i] 16 | int min = i; 17 | for (int j = i + 1; j < n; j++) 18 | { 19 | // if arr[j] element is less, then it is the new minimum 20 | if (arr[j] < arr[min]) 21 | min = j; // update index of min element 22 | } 23 | 24 | // swap the minimum element in subarray[i..n-1] with arr[i] 25 | swap(arr, min, i); 26 | 27 | if (i + 1 < n) { 28 | selectionSort(arr, i + 1, n); 29 | } 30 | } 31 | 32 | // Function to print n elements of the array arr 33 | void printArray(int arr[], int n) 34 | { 35 | for (int i = 0; i < n; i++) { 36 | printf("%d ", arr[i]); 37 | } 38 | } 39 | 40 | // main function 41 | int main() 42 | { 43 | int arr[] = { 3, 5, 8, 4, 1, 9, -2 }; 44 | int n = sizeof(arr) / sizeof(arr[0]); 45 | 46 | selectionSort(arr, 0, n); 47 | printArray(arr, n); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /Algorithms/sieve-of-eratosthenes.c: -------------------------------------------------------------------------------- 1 | /* 2 | Author : MiKueen 3 | Algorithm : Sieve of Eratosthenes 4 | 5 | Given a number n, print all primes smaller than or equal to n. 6 | 7 | Example: 8 | Input : n =10 9 | Output : 2 3 5 7 10 | 11 | Input : n = 20 12 | Output: 2 3 5 7 11 13 17 19 13 | 14 | The Sieve of Eratosthenes is one of the most efficient ways to find all primes smaller than n when n is smaller than 10 million or so (Ref Wiki). 15 | 16 | Following is the algorithm to find all the prime numbers less than or equal to a given integer n by Eratosthenes’ method: 17 | 18 | 1) Create a list of consecutive integers from 2 to n: (2, 3, 4, …, n). 19 | 2) Initially, let p equal 2, the first prime number. 20 | 3) Starting from p^2, count up in increments of p and mark each of these numbers greater than or equal to p^2 itself in the list. These numbers will be p(p+1), p(p+2), p(p+3), etc.. 21 | 4) Find the first number greater than p in the list that is not marked. If there was no such number, stop. Otherwise, let p now equal this number (which is the next prime), and repeat from step 3. 22 | 23 | */ 24 | 25 | #include 26 | 27 | int main() { 28 | int n; 29 | scanf("%d", &n); 30 | int primes[n+1]; 31 | 32 | for(int i = 1; i <= n; i++) { 33 | primes[i] = i; 34 | } 35 | 36 | for(int i = 2; i*i <= n; i++) { 37 | if(primes[i] != 0) { 38 | for(int j = 2*i; j <= n ; j += i) 39 | primes[j] = 0; 40 | } 41 | } 42 | 43 | for(int i = 2; i <= n; i++) { 44 | if(primes[i] != 0) { 45 | printf("%d ", i); 46 | } 47 | } 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /Arrays/addmatrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int a[3][3],b[3][3],sum[3][3],i,j; 5 | printf("Enter the values of a:\n"); 6 | for(i=0;i<3;i++) 7 | { 8 | for(j=0;j<3;j++) 9 | { 10 | scanf("%d",&a[i][j]); 11 | } 12 | printf("\n"); 13 | 14 | } 15 | printf("Enter the values of b:\n"); 16 | for(i=0;i<3;i++) 17 | { 18 | for(j=0;j<3;j++) 19 | { 20 | scanf("%d",&b[i][j]); 21 | } 22 | printf("\n"); 23 | } 24 | for(i=0;i<3;i++) 25 | { 26 | for(j=0;j<3;j++) 27 | { 28 | sum[i][j]=a[i][j]+b[i][j]; 29 | } 30 | 31 | } 32 | printf("The sum is:\n"); 33 | for(i=0;i<3;i++) 34 | { 35 | for(j=0;j<3;j++) 36 | { 37 | printf("%d\n",sum[i][j]); 38 | } 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Arrays/addmatrix.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/addmatrix.exe -------------------------------------------------------------------------------- /Arrays/addmatrix.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/addmatrix.o -------------------------------------------------------------------------------- /Arrays/ascendingorder.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int x[4],i,j,z; 5 | printf("Enter the 4 numbers:\n"); 6 | for(i=0;i<4;i++) 7 | { 8 | scanf("%d",&x[i]); 9 | } 10 | for(i=0;i<4;i++) 11 | { 12 | for(j=i+1;j<4;j++) 13 | { 14 | if(x[j] 2 | main() 3 | { 4 | int x[10],sum=0,i; 5 | float avg; 6 | printf("Enter the array numbers:\n"); 7 | for(i=0;i<10;i++) 8 | { 9 | scanf("%d",&x[i]); 10 | sum+=x[i]; 11 | } 12 | avg=sum/10; 13 | printf("The sum is %d and average is %f.\n",sum,avg); 14 | } 15 | -------------------------------------------------------------------------------- /Arrays/averageandsum.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/averageandsum.exe -------------------------------------------------------------------------------- /Arrays/averageandsum.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/averageandsum.o -------------------------------------------------------------------------------- /Arrays/biggestnumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int x[10],i,max=0; 5 | printf("Enter the numbers:\n"); 6 | for(i=0;i<10;i++) 7 | { 8 | scanf("%d",&x[i]); 9 | if(x[i]>max) 10 | max=x[i]; 11 | } 12 | printf("The maximum among those numbers is %d.\n",max); 13 | } 14 | -------------------------------------------------------------------------------- /Arrays/biggestnumber.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/biggestnumber.exe -------------------------------------------------------------------------------- /Arrays/biggestnumber.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/biggestnumber.o -------------------------------------------------------------------------------- /Arrays/copyonearraytoanother.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int x[10],i,j,y[10]; 5 | printf("Enter the 10 elements:\n"); 6 | 7 | for(i=0;i<10;i++) 8 | { 9 | scanf("%d",&x[i]); 10 | y[i]=x[i]; 11 | } 12 | printf("The elements in y array are:\n"); 13 | for(i=0;i<10;i++) 14 | { 15 | printf("%d",y[i]); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Arrays/copyonearraytoanother.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/copyonearraytoanother.exe -------------------------------------------------------------------------------- /Arrays/copyonearraytoanother.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/copyonearraytoanother.o -------------------------------------------------------------------------------- /Arrays/countposnegzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int x[10],i,j,pos=0,neg=0,zero=0; 5 | printf("Enter those 10 numbers:\n"); 6 | 7 | for(i=0;i<10;i++) 8 | { 9 | scanf("%d",&x[i]); 10 | if(x[i]>0) 11 | pos++; 12 | else if(x[i]==0) 13 | zero++; 14 | else 15 | neg++; 16 | } 17 | printf("Total number of positive numbers:%d\n",pos); 18 | printf("Total number of negative numbers:%d\n",neg); 19 | printf("Total number of zeros:%d\n",zero); 20 | } 21 | -------------------------------------------------------------------------------- /Arrays/countposnegzero.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/countposnegzero.exe -------------------------------------------------------------------------------- /Arrays/countposnegzero.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/countposnegzero.o -------------------------------------------------------------------------------- /Arrays/countrepeatedletter.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | char x[20],ch; 5 | int i,j=0; 6 | printf("Enter the string:\n"); 7 | scanf("%s",&x); 8 | printf("Enter the Character you want to count:\n"); 9 | ch=getche(); 10 | 11 | for(i=0;x[i]!=0;i++) 12 | { 13 | if(x[i]==ch) 14 | j++; 15 | } 16 | printf("\nThe number of times %c is repeated is %d.\n",ch,j); 17 | } 18 | -------------------------------------------------------------------------------- /Arrays/countrepeatedletter.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/countrepeatedletter.exe -------------------------------------------------------------------------------- /Arrays/countrepeatedletter.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/countrepeatedletter.o -------------------------------------------------------------------------------- /Arrays/dectobin.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int dec,bin[10],i,j; 5 | printf("Enter the decimal value:\n"); 6 | scanf("%d",&dec); 7 | 8 | for(i=0;i<10;i++) 9 | { 10 | bin[i]=dec%2; 11 | dec=dec/2; 12 | } 13 | for(i=10;i>=0;i--) 14 | { 15 | printf("%d",bin[i]); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Arrays/dectobin.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/dectobin.exe -------------------------------------------------------------------------------- /Arrays/dectobin.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Arrays/dectobin.o -------------------------------------------------------------------------------- /Arrays/descendingorder.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int x[10],i,j,z; 5 | printf("Enter the value of x:\n"); 6 | 7 | for(i=0;i<10;i++) 8 | { 9 | scanf("%d",&x[i]); 10 | } 11 | for(i=0;i<10;i++) 12 | { 13 | for(j=i+1;j<10;j++) 14 | { 15 | if(x[j]>x[i]) 16 | { 17 | z=x[j]; 18 | x[j]=x[i]; 19 | x[i]=z; 20 | } 21 | } 22 | } 23 | printf("The number in descending order is :\n"); 24 | for(i=0;i<10;i++) 25 | { 26 | printf("%d\n",x[i]); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Bubble Sorting with pointers: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n,temp; 5 | scanf("%d",&n); 6 | int *p; 7 | p = (int*)malloc(n * sizeof(int)); 8 | for(int i=0;i<=n;i++) 9 | { 10 | scanf("%d",a[p+i]); 11 | } 12 | 13 | 14 | for(int i=0; i<(n-1); i++) 15 | { 16 | for(int j=0; j<(n-i-1); j++) 17 | { 18 | if(a[*(p+j)]>a[*(p+j+1)]) 19 | { 20 | temp=a[*(p+j)]; 21 | a[*(p+j)]=a[*(p+j+1)]; 22 | a[*(p+j+1)]=temp; 23 | } 24 | } 25 | } 26 | 27 | for(int i=0;i<=n;i++) 28 | { 29 | printf("%d",a[p+i]); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Conditional statements/Data Science.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Conditional statements/Data Science.pdf -------------------------------------------------------------------------------- /Conditional statements/a.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Conditional statements/a.exe -------------------------------------------------------------------------------- /Conditional statements/ab.c: -------------------------------------------------------------------------------- 1 | /* A simple scanset example */ 2 | #include 3 | 4 | int main(void) 5 | { 6 | char str[128]; 7 | 8 | printf("Enter a string: "); 9 | scanf("%[A-Z]s", str); //This will only store capital letters 10 | 11 | printf("You entered: %s\n", str); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Conditional statements/ab.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Conditional statements/ab.exe -------------------------------------------------------------------------------- /Conditional statements/age.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char const *argv[]) 4 | { 5 | int age; 6 | printf("Enter your age:\n"); 7 | scanf("%d",&age); 8 | 9 | if (age>=18) 10 | { 11 | printf("You are eligible to vote.\n"); 12 | 13 | } 14 | else 15 | { 16 | printf("You are not eligible to vote.\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Conditional statements/age.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Conditional statements/age.exe -------------------------------------------------------------------------------- /Conditional statements/assignment1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char const *argv[]) 4 | { 5 | int num1,num2; 6 | 7 | printf("Enter the first number:\n"); 8 | scanf("%d",&num1); 9 | 10 | printf("Enter the second number:\n"); 11 | scanf("%d",&num2); 12 | 13 | if (num1==num2) 14 | { 15 | printf("Both the numbers are same.\n"); 16 | } 17 | else 18 | { 19 | printf("Both the numbers are different.\n"); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Conditional statements/assignment1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Conditional statements/assignment1.exe -------------------------------------------------------------------------------- /Conditional statements/custom.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char const *argv[]) 4 | { 5 | int m,n; 6 | printf("Enter the value of m:\n"); 7 | scanf("%d",&m); 8 | 9 | if (m>0) 10 | { 11 | printf("The Value of n is 1.\n"); 12 | } 13 | 14 | else if (m<0) 15 | { 16 | printf("The value of n is -1.\n"); 17 | } 18 | 19 | else 20 | { 21 | printf("The value of n is 0.\n"); 22 | } 23 | 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Conditional statements/custom.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Conditional statements/custom.exe -------------------------------------------------------------------------------- /Dynamic memory allocation: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a[5]; 5 | 6 | for(int i=0;i<5;i++) 7 | { 8 | scanf("%d",&a[i]); 9 | } 10 | 11 | int n; 12 | scanf("%d",&n); 13 | int *p; 14 | 15 | p=(int*)malloc(sizeof(int)*n); 16 | 17 | for(int i=0;i 2 | #define PI 3.14 3 | float areac(float); 4 | int main() 5 | { 6 | float r; 7 | printf("Enter the radius of Circle:\n"); 8 | scanf("%f",&r); 9 | printf("The Area of the circle with radius %f is: %f",r,areac(r)); 10 | return 0; 11 | } 12 | float areac(float r) 13 | { 14 | float z; 15 | z=PI*r*r; 16 | return z; 17 | } 18 | -------------------------------------------------------------------------------- /Functions/areaofcircle.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/areaofcircle.exe -------------------------------------------------------------------------------- /Functions/areaofcircle.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/areaofcircle.o -------------------------------------------------------------------------------- /Functions/dectobin.c: -------------------------------------------------------------------------------- 1 | #include 2 | int dec(int); 3 | main() 4 | { 5 | int x,i; 6 | printf("Enter the value of x:\n"); 7 | scanf("%d",&x); 8 | dec(x); 9 | } 10 | int dec(x) 11 | { 12 | int i,bin[15]; 13 | for(i=0;i<15;i++) 14 | { 15 | bin[i]=x%2; 16 | x=x/2; 17 | } 18 | printf("The Binary value is:\n"); 19 | for(i=14;i>=0;i--) 20 | { 21 | printf("%d",bin[i]); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Functions/dectobin.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/dectobin.exe -------------------------------------------------------------------------------- /Functions/dectobin.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/dectobin.o -------------------------------------------------------------------------------- /Functions/factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fact(int x); 3 | int main() 4 | { 5 | int x; 6 | printf("Enter the value of x:\n"); 7 | scanf("%d",&x); 8 | //z=fact(x); 9 | printf("The factorial of x is :%d",fact(x)); 10 | return 0; 11 | } 12 | int fact(int x) 13 | { 14 | int i,fact=1; 15 | for(i=x;i>=1;i--) 16 | { 17 | fact*=i; 18 | } 19 | return fact; 20 | } 21 | -------------------------------------------------------------------------------- /Functions/factorial.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/factorial.exe -------------------------------------------------------------------------------- /Functions/factorial.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/factorial.o -------------------------------------------------------------------------------- /Functions/factors.c: -------------------------------------------------------------------------------- 1 | #include 2 | void factors(int); 3 | main() 4 | { 5 | int x; 6 | printf("Enter the value of x:\n"); 7 | scanf("%d",&x); 8 | factors(x); 9 | } 10 | void factors(int x) 11 | { 12 | int i; 13 | for(i=1;i<=x;i++) 14 | { 15 | if(x%i==0) 16 | { 17 | printf("%d",i); 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Functions/factors.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/factors.exe -------------------------------------------------------------------------------- /Functions/factors.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/factors.o -------------------------------------------------------------------------------- /Functions/functions.c: -------------------------------------------------------------------------------- 1 | #include 2 | void italy(); 3 | void germany(); 4 | void india(); 5 | 6 | main() 7 | { 8 | printf("I am in main.\n"); 9 | italy(); 10 | printf("I am back in main.\n"); 11 | } 12 | void italy() 13 | { 14 | printf("I am in ITALY.\n"); 15 | germany(); 16 | printf("I am back in ITALY.\n"); 17 | } 18 | void germany() 19 | { 20 | printf("I am in GERMANY.\n"); 21 | india(); 22 | printf("I am back in GERMANY.\n"); 23 | } 24 | void india() 25 | { 26 | printf("I am in INDIA.\n"); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Functions/functions.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/functions.exe -------------------------------------------------------------------------------- /Functions/functions.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/functions.o -------------------------------------------------------------------------------- /Functions/functions1.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int sum(int x,int y); 5 | int x,y,s; 6 | printf("Enter x:\n"); 7 | scanf("%d",&x); 8 | printf("Enter y:\n"); 9 | scanf("%d",&y); 10 | s=sum(x,y); 11 | printf("The sum is %d.\n",s); 12 | } 13 | sum(a,b) 14 | { 15 | int z; 16 | z=a+b; 17 | } 18 | -------------------------------------------------------------------------------- /Functions/functions1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/functions1.exe -------------------------------------------------------------------------------- /Functions/functions1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/functions1.o -------------------------------------------------------------------------------- /Functions/lcm.c: -------------------------------------------------------------------------------- 1 | #include 2 | int lcm(int,int); 3 | main() 4 | { 5 | int x,y; 6 | printf("Enter the value of x:\n"); 7 | scanf("%d",&x); 8 | printf("Enter the value of y:\n"); 9 | scanf("%d",&y); 10 | if(x 3 | int sum(int,int); 4 | main() 5 | { 6 | int x,y,a; 7 | printf("Enter the value of x:\n"); 8 | scanf("%d",&x); 9 | printf("Enter the value of y:\n"); 10 | scanf("%d",&y); 11 | a=sum(x,y); 12 | printf("The sum of x and y is %d.\n",a); 13 | } 14 | int sum(int x,int y) 15 | { 16 | int z; 17 | z=x*y; 18 | return z; 19 | } 20 | -------------------------------------------------------------------------------- /Functions/multiply2values.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/multiply2values.exe -------------------------------------------------------------------------------- /Functions/multiply2values.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/multiply2values.o -------------------------------------------------------------------------------- /Functions/oddoreven.c: -------------------------------------------------------------------------------- 1 | #include 2 | int check(int); 3 | int main() 4 | { 5 | int x; 6 | printf("Enter the number:\n"); 7 | scanf("%d",&x); 8 | return check(x); 9 | } 10 | int check(int x) 11 | { 12 | int i; 13 | if(x%2==0) 14 | return 1; 15 | else 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Functions/oddoreven.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/oddoreven.exe -------------------------------------------------------------------------------- /Functions/oddoreven.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/oddoreven.o -------------------------------------------------------------------------------- /Functions/primeornot.c: -------------------------------------------------------------------------------- 1 | #include 2 | int prime(int); 3 | main() 4 | { 5 | int x,z; 6 | printf("Enter the value of x:\n"); 7 | scanf("%d",&x); 8 | z=prime(x); 9 | if(z==1) 10 | printf("The number is not a prime number.\n"); 11 | else 12 | printf("The number is a prime number.\n"); 13 | } 14 | int prime(int x) 15 | { 16 | int num; 17 | for(int i=2;i<=x-1;i++) 18 | { 19 | if(x%i==0) 20 | return 1; 21 | else 22 | return 0; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Functions/primeornot.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/primeornot.exe -------------------------------------------------------------------------------- /Functions/primeornot.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Functions/primeornot.o -------------------------------------------------------------------------------- /Functions/printnaturalnos.c: -------------------------------------------------------------------------------- 1 | #include 2 | int numbers(int); 3 | int main() 4 | { 5 | int x; 6 | printf("Enter the number upto which you want to print the numbers from 1:\n"); 7 | scanf("%d",&x); 8 | numbers(x); 9 | return 0; 10 | } 11 | int numbers(int x) 12 | { 13 | int i; 14 | for(i=1;i<=x;i++) 15 | printf("%d\t",i); 16 | } 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Programs/Adding_Time.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | /* 5 | 6 | Program to add two different times in format Hour Minute Seconds 7 | 8 | Sample input: 9 | 11 59 59 10 | 3 2 5 11 | 12 | Sample Output: 13 | 15 2 4 14 | 15 | 16 | */ 17 | 18 | int main() 19 | { 20 | int hr1, min1, sec1, hr2, min2, sec2, hr3 = 0, min3 = 0, sec3 = 0; // ALternative is array 21 | scanf("%d %d %d %d %d %d", &hr1, &min1, &sec1, &hr2, &min2, &sec2); 22 | 23 | // Converting seconds to minutes of total seconds > 60 24 | sec3 = sec2 + sec1; 25 | if (sec3 > 59) { 26 | sec3 %=60; // The remainder would be the seconds according to clock 27 | min3++; // Incrementing minute 28 | } 29 | 30 | // Converting minutes to hours of total minutes > 60 31 | min3+=min1+min2; 32 | if(min3>59) { 33 | min3 %= 60; // The remainder would be the minutes according to clock 34 | hr3++; // Incrementing hour 35 | } 36 | 37 | // Reducing hours greater 23 according to the clock 38 | hr3+=hr1+hr2; 39 | if (hr3>23) hr3 %= 24; // The remainder would be the actual hour according to clock 40 | 41 | printf("%d %d %d", hr3, min3, sec3); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Programs/Areas of Different Geometrical Figures: -------------------------------------------------------------------------------- 1 | /* 2 | * C program to find the areas of different geometrical shapes such as 3 | * circle, square, rectangle etc using switch statements. 4 | */ 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int fig_code; 11 | float side, base, length, breadth, height, area, radius; 12 | 13 | printf("-------------------------\n"); 14 | printf(" 1 --> Circle\n"); 15 | printf(" 2 --> Rectangle\n"); 16 | printf(" 3 --> Triangle\n"); 17 | printf(" 4 --> Square\n"); 18 | printf("-------------------------\n"); 19 | printf("Enter the Figure code\n"); 20 | scanf("%d", &fig_code); 21 | switch(fig_code) 22 | { 23 | case 1: 24 | printf("Enter the radius\n"); 25 | scanf("%f", &radius); 26 | area = 3.142 * radius * radius; 27 | printf("Area of a circle = %f\n", area); 28 | break; 29 | case 2: 30 | printf("Enter the breadth and length\n"); 31 | scanf("%f %f", &breadth, &length); 32 | area = breadth * length; 33 | printf("Area of a Reactangle = %f\n", area); 34 | break; 35 | case 3: 36 | printf("Enter the base and height\n"); 37 | scanf("%f %f", &base, &height); 38 | area = 0.5 * base * height; 39 | printf("Area of a Triangle = %f\n", area); 40 | break; 41 | case 4: 42 | printf("Enter the side\n"); 43 | scanf("%f", &side); 44 | area = side * side; 45 | printf("Area of a Square=%f\n", area); 46 | break; 47 | default: 48 | printf("Error in figure code\n"); 49 | break; 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Programs/BinaryToDecimal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int convertBinaryToDecimal(long long n); 4 | int main() 5 | { 6 | long long n; 7 | printf("Enter a binary number: "); 8 | scanf("%lld", &n); 9 | printf("%lld in binary = %d in decimal", n, convertBinaryToDecimal(n)); 10 | return 0; 11 | } 12 | int convertBinaryToDecimal(long long n) 13 | { 14 | int decimalNumber = 0, i = 0, remainder; 15 | while (n!=0) 16 | { 17 | remainder = n%10; 18 | n /= 10; 19 | decimalNumber += remainder*pow(2,i); 20 | ++i; 21 | } 22 | return decimalNumber; 23 | } -------------------------------------------------------------------------------- /Programs/Character_Classification.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | 5 | Program to classify input character as 6 | > Digit (0-9) 7 | > Small/Lower case alphabet (a-z) 8 | > Capital/Upper case alphabet (A-z) 9 | > Special Character (anything other than above) 10 | 11 | +--------------------------------------+ 12 | |Sample Inputs | Sample Outputs | 13 | +--------------------------------------+ 14 | | 9 | digit | 15 | | x | Alphabet small case | 16 | | R | Alphabet capital case| 17 | | # | Special character | 18 | +--------------------------------------+ 19 | 20 | */ 21 | 22 | int main() { 23 | 24 | char ch; 25 | scanf("%c", &ch); 26 | 27 | // Start checking 28 | if(ch >= '0' && ch <= '9') printf("digit"); // Check if input character lies between 0 and 9 and print "digit" 29 | else if(ch >= 'a' && ch <= 'z') printf("Alphabet small case"); // Else check if input character lies between 'a' and 'z' and print "Alphabet small case" 30 | else if(ch >= 'A' && ch <= 'Z') printf("Alphabet capital case");// Else check if input character lies between 'A' and 'Z" and print "Alphabet capital case" 31 | else printf("Special Character"); // Else if none of above is true print "Special Character" 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Programs/DecToBinary.c: -------------------------------------------------------------------------------- 1 | // #include 2 | // #include 3 | 4 | // int main(){ 5 | 6 | // int a[10],n,i; 7 | // system ("cls"); 8 | // printf("Enter the number to convert: "); 9 | // scanf("%d",&n); 10 | 11 | // for(i=0;n>0;i++) 12 | // { 13 | // a[i]=n%2; 14 | // n=n/2; 15 | // } 16 | 17 | // printf("\nBinary of Given Number is="); 18 | // for(i=i-1;i>=0;i--) 19 | // { 20 | // printf("%d",a[i]); 21 | // } 22 | // return 0; 23 | // } 24 | #include 25 | 26 | int main() { 27 | int n; 28 | printf ("Enter the number to be coverted in binary : "); 29 | scanf ("%d", &n); 30 | int rem; 31 | int a[15]; 32 | int i = 0; 33 | 34 | while(n) 35 | { 36 | rem = n%2 ; 37 | n = n/2; 38 | a[i]= rem; 39 | i++; 40 | } 41 | for (int j = i - 1; j >=0; j--) 42 | { 43 | printf("%d", a[j]); 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Programs/DiceRoll.c: -------------------------------------------------------------------------------- 1 | //Simulate a diceroll with an adjustable number of sides using the rand() function. 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int Diceroll(int DiceSides) 8 | { 9 | srand(time(NULL)); 10 | int n = (DiceSides - 1) + 1; //n in this case is the range of the random int 11 | int DiceRoll = 1 + rand() % n; 12 | 13 | return DiceRoll; 14 | } 15 | 16 | int main(int argc, char argv) 17 | { 18 | int DiceSides; 19 | printf("Enter the number of sides your die has. \n"); 20 | scanf("%d",&DiceSides); 21 | 22 | int Dice = Diceroll(DiceSides); 23 | printf("you rolled a %d \n",Dice); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Programs/Factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | Program to print factorial of positive numbers 5 | 6 | Sample input 0: 7 | 5 8 | Sample output 0: 9 | 120 10 | 11 | Sample input 1: 12 | 0 13 | Sample Output 1; 14 | 1 15 | 16 | Sample input 2: 17 | -12 18 | Sample output 2: 19 | "Undefined" 20 | 21 | 22 | */ 23 | 24 | int main() { 25 | 26 | int n, fact=1; // Initialize fact with 1 for further multiplications 27 | scanf("%d", &n); 28 | if(n>=0) { // Work only if number is positive 29 | for(int i = 2; i <= n; i++) fact*=i; // Iterate as fact*2*3*.....*n 30 | printf("%d", fact); // At last print the factorial 31 | } 32 | else printf("Undefined"); // print undefined if number is negative 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Programs/Factorial_Recursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fact(num) 4 | { 5 | if(num <= 0) 6 | return 1; 7 | else 8 | return num * fact(num - 1); 9 | } 10 | 11 | main(int argc, char ** argv) 12 | { 13 | long num; 14 | printf("Enter a number: "); 15 | scanf("%d,\n",&num); 16 | printf("%d! is %d\n",num,fact(num)); 17 | } 18 | -------------------------------------------------------------------------------- /Programs/Fibonacci_Recursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fib(num) 4 | { 5 | if (num == 0) 6 | return 0; 7 | else if (num == 1) 8 | return 1; 9 | else 10 | return fib(num - 2) + fib(num - 1); 11 | } 12 | 13 | main(int argc, char ** argv) 14 | { 15 | int num; 16 | printf("Please input a number: "); 17 | scanf("%d, \n",&num); 18 | printf("Fibonacci of %d is %d\n",num,fib(num)); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Programs/Fibonachi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | This program will find sum of all uneven fobonachi numbers up until 40000000 6 | */ 7 | 8 | int main(void) { 9 | int i, sum = 0; 10 | int *fibonachi_sequence = calloc(2, sizeof(int)); 11 | 12 | fibonachi_sequence[0] = 0; 13 | fibonachi_sequence[1] = 1; 14 | 15 | i = 3; 16 | while (1) { 17 | realloc(fibonachi_sequence, i * sizeof(int)); 18 | fibonachi_sequence[i - 1] = fibonachi_sequence[i - 3] + fibonachi_sequence[i - 2]; 19 | printf("%d -> %d\n", i-2, fibonachi_sequence[i - 2]); 20 | if (!(fibonachi_sequence[i-1] % 2)) { 21 | sum += fibonachi_sequence[i-1]; 22 | } 23 | if (fibonachi_sequence[i - 1] > 40000000) { 24 | break; 25 | } 26 | i++; 27 | } 28 | 29 | printf("Final sum of all even fibonachi numbers is: %d\n", sum); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Programs/Insertion_sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void Insertion_Sort(int *arr,int *n){ 4 | for(int i = 1 ; i < *n ; i++){ 5 | int key = arr[i]; 6 | int j = i - 1; 7 | while(j >= 0 && arr[j] > key){ 8 | arr[j+1] = arr[j]; 9 | j--; 10 | } 11 | arr[j + 1] = key; 12 | } 13 | } 14 | 15 | int main(){ 16 | int n; 17 | scanf("%d",&n); 18 | int arr[n]; 19 | 20 | for(int i = 0 ; i < n ; i++){ 21 | scanf("%d",&arr[i]); 22 | } 23 | Insertion_Sort(arr, &n); 24 | for(int i = 0 ; i < n ; i++){ 25 | printf("%d\n",arr[i] ); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Programs/LARGEfactorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | long long int max=17000; 3 | int main() 4 | { 5 | long long int T,i; 6 | scanf("%lld",&T); 7 | for(i=0;i10) 23 | { 24 | c=a[w]; 25 | h=w; 26 | while(c/10>0) 27 | { 28 | a[h]=c%10; 29 | a[h+1]=a[h+1]+c/10; 30 | c=a[h+1]; 31 | h++; 32 | } 33 | 34 | } 35 | 36 | } 37 | } 38 | for(j=16999;j>=0;j--) 39 | { 40 | if(a[j]!=0) 41 | { 42 | h=j; 43 | break; 44 | } 45 | 46 | } 47 | for(j=h;j>=0;j--) 48 | { 49 | printf("%lld",a[j]); 50 | } 51 | 52 | printf("\n"); 53 | } 54 | return 0; 55 | } -------------------------------------------------------------------------------- /Programs/LeapYear.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int year; 5 | printf("Enter a year: "); 6 | scanf("%d",&year); 7 | if(year%4 == 0) 8 | { 9 | if( year%100 == 0) 10 | { 11 | // year is divisible by 400, hence the year is a leap year 12 | if ( year%400 == 0) 13 | printf("%d is a leap year.", year); 14 | else 15 | printf("%d is not a leap year.", year); 16 | } 17 | else 18 | printf("%d is a leap year.", year ); 19 | } 20 | else 21 | printf("%d is not a leap year.", year); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Programs/Partition_Set.c: -------------------------------------------------------------------------------- 1 | //This program partitions an integer array into two disjoint subsets 2 | //such that the sum of numbers in both of them is the same... 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | int main(){ 9 | 10 | int size, k, l; 11 | int arr[100], s1[100], s2[100]; 12 | int sum = 0, sum1 = 0, sum2 = 0; 13 | double num_set; 14 | 15 | printf("Enter the size of the array:\t"); 16 | scanf("%d", &size); 17 | 18 | printf("Enter the elements of the array:\t"); 19 | 20 | for(int i = 0; i 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | //function for finding out if a number is prime 8 | bool chkprime(int n){ 9 | //Here n is the integer to be checked. We are using the simplest yet least efficient way to compute prime numbers. 10 | //It divides the number by all numbers from 1 upto n-1 11 | //If any one of the division has as remainder "0", it means that the number is not prime 12 | //in this case, the function returns false, else it returns true 13 | 14 | bool prime = true; 15 | 16 | for (int i = 2 ; i < n ; i++){ 17 | if ((n%i) == 0){ 18 | prime = false; 19 | break; 20 | } 21 | } 22 | return prime; 23 | } 24 | 25 | void main(){ 26 | 27 | struct timeval t1,t2,t3,t4; //refer to manual : man 2 gettimeofday 28 | srand(time(0));////if this is not included, we'll get same values at each run 29 | 30 | int arr[100][100]; 31 | bool prime = true; 32 | 33 | gettimeofday(&t1,NULL);//Time at the start of generation of random numbers 34 | for(int i = 0 ; i < 100 ; i++){ 35 | for(int j = 0 ; j < 100 ; j++){ 36 | arr[i][j] = rand() % 100 + 1; 37 | } 38 | } 39 | gettimeofday(&t2,NULL);//getting time at the end of generation of random numbers 40 | 41 | gettimeofday(&t3, NULL);//Time before start of the finding prime numbers process 42 | for(int i = 0 ; i < 100 ; i++){ 43 | for(int j = 0 ; j < 100 ; j++){ 44 | prime = chkprime(arr[i][j]); 45 | if (prime == true) { 46 | printf("%d is a prime number\n",arr[i][j]); 47 | } 48 | } 49 | } 50 | gettimeofday(&t4,NULL);//time at the end of the finding prime numbers process 51 | 52 | double p1,p2; 53 | p1 = t2.tv_usec - t1.tv_usec;//calculating time for population of array with random nnumbers 54 | printf("The time taken for populating a 100x100 array is : %10.2fus\n", p1); 55 | 56 | p2 = t4.tv_usec - t3.tv_usec;//calculating time to find the prime numbers 57 | printf("The time taken to search for prime numbers in a 100x100 array is : %10.2fus\n", p2); 58 | 59 | 60 | 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Programs/Prime Number.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int n, i, m, flag = 0; 7 | printf("Enter the number to check prime: "); 8 | scanf("%d", &n); 9 | if (n < 2) 10 | { 11 | printf("Please enter a number larger than 1\n"); 12 | flag = 1; 13 | } 14 | // only have to go to square root of the number, not n/2 15 | m = sqrt(n); 16 | for (i = 2; i <= m; i++) 17 | { 18 | if (n % i == 0) 19 | { 20 | printf("Number is not prime\n"); 21 | flag = 1; 22 | break; 23 | } 24 | } 25 | if (flag == 0) 26 | printf("Number is prime\n"); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Programs/Pythagorean Triplet.c: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================ 3 | Name : Pythagorean.c 4 | Author : Shubham Bhandari 5 | Version : 6 | Copyright : Your copyright notice 7 | Description : Hello World in C, Ansi-style 8 | ============================================================================ 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | int main(void) 15 | { 16 | // n1 represents smallest number and n1>=n2>=n3 17 | int n1,n2,n3,no; 18 | scanf("%d",&no); 19 | 20 | for(n3=3;n3 2 | 3 | /* 4 | Program to input positive integer and if its a multiple of 5 print area of square else print area of circle 5 | 6 | Sample Input 0: 7 | 10 8 | 9 | Sample Output 0: 10 | Area of square: 100 11 | 12 | Explaination 0: 10 is a multiple of 5 hence printed the area of square i.e n*n 13 | 14 | Sample Input 1: 15 | 3 16 | 17 | Sample Output 1: 18 | Area of cirlce: 28.26 19 | 20 | Explaination 1: 3 isn't a multiple of 5 hence printed area of circle i.e 3.14*n*n 21 | */ 22 | 23 | int main() 24 | { 25 | int n; 26 | scanf("%d", &n); 27 | if(n%5==0) // Check if n is a multiple of 5 28 | printf("Area of square: %d", n*n); // Print area of square 29 | else 30 | printf("Area of circle %.2f", 3.14*n*n); // Print Area of circle with precision of 2 31 | } 32 | -------------------------------------------------------------------------------- /Programs/Sum_of_series.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | 5 | Program to print sum of series 6 | 7 | 1-2*2+3*3-4*4+5*5....... upto N 8 | 9 | 10 | 11 | */ 12 | 13 | int main() { 14 | 15 | int n, sign = 1, sum=0; 16 | scanf("%d", &n); 17 | 18 | for(int i = 1; i <= n; i++) { 19 | sum+=sign*i*i; 20 | sign=-sign; 21 | } 22 | printf("%d", sum); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Programs/TowerofHanoi.c: -------------------------------------------------------------------------------- 1 | #include 2 | int count; 3 | void tower(int n, char src, char dest, char aux) 4 | { 5 | if(n>0) 6 | { 7 | tower(n-1,src,aux,dest); 8 | printf("Move disk %d from peg %c to peg %c\n",n,src,dest); 9 | count++; 10 | tower(n-1,aux,dest,src); 11 | } 12 | } 13 | int main() 14 | { 15 | int disk; 16 | count=0; 17 | printf("Enter the number of disks\n"); 18 | scanf("%d",&disk); 19 | tower(disk,'A','C','B'); 20 | printf("The number of moves is %d\n",count); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Programs/armstrongNumber.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Armstrong number is a number that is equal to the sum of the nth power of the digits where n is the number of digits. For example 0, 1, 153, 370, 371, 407 and 1634 are the Armstrong numbers. 4 | 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | int main() 11 | { 12 | int n,r,sum=0,temp,d=0; // d is the number of digits 13 | printf("enter the number="); 14 | scanf("%d",&n); 15 | temp=n; 16 | while(temp>0) 17 | { 18 | d++; 19 | temp=temp/10; 20 | } 21 | temp=n; 22 | while(n>0) 23 | { 24 | r=n%10; 25 | sum=sum+(pow(r,d)); //using pow() which is a function of math.h 26 | n=n/10; 27 | } 28 | if(temp==sum) 29 | printf("armstrong number "); 30 | else 31 | printf("not armstrong number"); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Programs/babylonian_method.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() 4 | { 5 | int k; 6 | printf("Enter number to take root of: "); 7 | scanf("%d", &k); 8 | 9 | double an = k/2; 10 | 11 | int n = 100; 12 | while(n--) 13 | an = (an/2)+(k/(2*an)); 14 | 15 | printf("Sqrt of %d is: %lf", k, an); 16 | } 17 | -------------------------------------------------------------------------------- /Programs/calculator.c: -------------------------------------------------------------------------------- 1 | //programme of calculator for the basic four functions(+,-,*,/) 2 | #include 3 | int main() 4 | { 5 | float a,b; 6 | char c; 7 | printf("Enter the operation you want to perform\n"); 8 | scanf("%c",&c); 9 | printf("Enter the two operands(NOTE:If performing division add numerator first)\n"); 10 | scanf("%f%f",&a,&b); 11 | switch(c) 12 | { 13 | case '+': 14 | printf("you opted for addition\nresult: %.2f\n",a+b); 15 | break; 16 | case '-': 17 | printf("you opted for substraction\nresult: %.2f\n",a-b); 18 | break; 19 | case '/': 20 | if(b!=0) 21 | { 22 | printf("you opted for division\nresult: %.2f\n",a/b); 23 | break; 24 | } 25 | else 26 | printf("ERROR:you opted division with denominator zero\n"); 27 | case '*': 28 | printf("you opted for multiplication\nresult: %.2f\n",a*b); 29 | break; 30 | default: 31 | printf("Cannot recognise the operator\n"); 32 | } 33 | return 0; 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /Programs/concentric-rectangles.c: -------------------------------------------------------------------------------- 1 | /* 2 | Author : MiKueen 3 | Problem Statement : Print concentric rectangular pattern in a 2d matrix 4 | 5 | Given a positive integer n, print the matrix filled with rectangle pattern as shown below: 6 | a a a a a 7 | a b b b a 8 | a b c b a 9 | a b b b a 10 | a a a a a 11 | 12 | where a = n, b = n – 1,c = n – 2 and so on. 13 | 14 | Example: 15 | Input : n = 3 16 | Output : 17 | 3 3 3 3 3 18 | 3 2 2 2 3 19 | 3 2 1 2 3 20 | 3 2 2 2 3 21 | 3 3 3 3 3 22 | */ 23 | 24 | #include 25 | int main() { 26 | int n; 27 | scanf("%d", &n); 28 | int len = 2*n-1; 29 | int min1, min2, min; 30 | 31 | for (int i = 1; i <= len; i++) { 32 | for (int j = 1; j <= len; j++) { 33 | if (i <= len-i) 34 | min1 = i-1; 35 | else 36 | min1 = len-i; 37 | 38 | if (j <= len-j) 39 | min2 = j-1; 40 | else 41 | min2 = len-j; 42 | 43 | if (min1 <= min2) 44 | min = min1; 45 | else 46 | min = min2; 47 | 48 | printf("%d ", n-min); 49 | } 50 | printf("\n"); 51 | } 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /Programs/decimalToBinary.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(){ 5 | //Declared Variables 6 | int a[10],n,i; 7 | 8 | //Entering the number 9 | printf("Enter the number to convert: "); 10 | scanf("%d",&n); 11 | 12 | for(i=0;n>0;i++){ 13 | a[i]=n%2; 14 | n=n/2; 15 | } 16 | 17 | //Printing the Number 18 | printf("\nBinary of Given Number is="); 19 | for(i=i-1;i>=0;i--){ 20 | printf("%d",a[i]); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Programs/dectobin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void dec_bin(long int num) 6 | { 7 | long int rem[50],i=0,length=0; 8 | while(num>0) 9 | { 10 | rem[i]=num%2; 11 | num=num/2; 12 | i++; 13 | length++; 14 | } 15 | printf("nBinary number : "); 16 | for(i=length-1;i>=0;i--) 17 | printf("%ld",rem[i]); 18 | } 19 | 20 | void main() 21 | { 22 | long int num; 23 | clrscr(); 24 | 25 | printf("Enter the decimal number : "); 26 | scanf("%ld",&num); 27 | 28 | dec_bin(num); 29 | getch(); 30 | } -------------------------------------------------------------------------------- /Programs/factor_of_number.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | //This program shows factors of the number entered 5 | 6 | int number, i; 7 | printf("Enter a positive integer: "); 8 | scanf("%d",&number); 9 | printf("Factors of %d are: ", number); 10 | for(i=1; i <= number; ++i) 11 | { 12 | if (number%i == 0) 13 | { 14 | printf("%d ",i); 15 | } 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Programs/findingChar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void main() 5 | { 6 | char sentences[50]; 7 | int i,count=0; 8 | char find; 9 | 10 | //print dialog to window 11 | printf("Typing sentences (50 char) : "); 12 | scanf("%[^\n]",sentences); 13 | printf("Input char to find (case sensitif) : "); 14 | scanf("%s",&find); 15 | 16 | //logic for find char in sentences 17 | for( i=0; sentences[i] != '\0'; i++ ) { 18 | if(find == sentences[i]) count++; 19 | } 20 | 21 | //ouput 22 | if ( count!=0 ) printf("\nThere are total %d charf '%c' from your sentences ! ",count,find); 23 | else printf ("\nThere is no char that you to find!"); 24 | 25 | //let user press any key to close window 26 | getch(); 27 | } 28 | -------------------------------------------------------------------------------- /Programs/game.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | 7 | int number, guess, nguess = 0; 8 | 9 | srand(time(0)); 10 | number = rand() % 100 + 1; 11 | // printf("\n%d", number); 12 | 13 | do 14 | { 15 | printf("\nEnter your guess... "); 16 | scanf("%d", &guess); 17 | 18 | if (guess > number) 19 | { 20 | printf("\nLower number plese.."); 21 | } 22 | else if (guess < number) 23 | { 24 | printf("\nHigher number plese.."); 25 | } 26 | else 27 | { 28 | printf("\nYou guessed number in %d attempt", nguess); 29 | } 30 | nguess++; 31 | 32 | } while (guess != number); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Programs/gcd.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | long temp, num1, num2; 5 | printf("Insert your first number\n"); 6 | scanf("%ld", &num1); 7 | printf("Insert your second number\n"); 8 | scanf("%ld", &num2); 9 | 10 | while (num2 != 0) { 11 | temp = num1 % num2; 12 | num1 = num2; 13 | num2 = temp; 14 | } 15 | printf("Greatest common denominator = %ld\n", num1); 16 | } 17 | -------------------------------------------------------------------------------- /Programs/generate_random_numbers_finding_prime.c: -------------------------------------------------------------------------------- 1 | //This program generates random numbers and counts the number of prime numbers present in the selection 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | void populateArray(int row, int col, int arr [row][col]){//fill array with random numbers 10 | 11 | srand(time(NULL));//if this is not included, we'll get same values at each run 12 | for (int i = 0; i < row; i++){ 13 | for(int j = 0; j < col; j++){ 14 | arr[i][j] = (rand() % 100) + 1; 15 | } 16 | } 17 | 18 | } 19 | 20 | int isPrime(int n){// Function to check if number is prime 21 | int prime = 1, num; 22 | num = sqrt(n); 23 | for (int i = 2; i < num; i++){ 24 | if(num%i == 0){ 25 | prime = 0; 26 | } 27 | } 28 | return prime; 29 | } 30 | 31 | int main(void) { 32 | int row, col; 33 | printf("Input row: "); 34 | scanf("%d", &row); 35 | printf("Input column: "); 36 | scanf("%d", &col); 37 | 38 | int grid [row][col]; 39 | populateArray(row, col, grid);//Initialising array 40 | 41 | 42 | 43 | for (int i = 0; i < row; i++){ 44 | for(int j = 0; j < col; j++){ 45 | printf("%d\t", grid[i][j]); 46 | } 47 | printf("\n"); 48 | } 49 | 50 | int count= 0; 51 | 52 | for (int i = 0; i < row; i++){ 53 | for(int j = 0; j < col; j++){ 54 | if (isPrime(grid[i][j]) == 1){ 55 | count++; 56 | } 57 | } 58 | } 59 | 60 | printf("Count of prime numbers: %d", count); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /Programs/largeelementarray.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int find_maximum(int[], int); 4 | 5 | int main() 6 | { 7 | int c, array[100], size, location, maximum; 8 | 9 | printf("Input number of elements in array\n"); 10 | scanf("%d", &size); 11 | 12 | printf("Enter %d integers\n", size); 13 | 14 | for (c = 0; c < size; c++) 15 | scanf("%d", &array[c]); 16 | 17 | location = find_maximum(array, size); 18 | maximum = array[location]; 19 | 20 | printf("Maximum element location = %d and value = %d.\n", location + 1, maximum); 21 | return 0; 22 | } 23 | 24 | int find_maximum(int a[], int n) { 25 | int c, max, index; 26 | 27 | max = a[0]; 28 | index = 0; 29 | 30 | for (c = 1; c < n; c++) { 31 | if (a[c] > max) { 32 | index = c; 33 | max = a[c]; 34 | } 35 | } 36 | 37 | return index; 38 | } 39 | -------------------------------------------------------------------------------- /Programs/largefactorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long int ll; 3 | ll mod = 1e9 + 7; 4 | int main() 5 | { 6 | ll n, q, i, p = 1,s=0,t=0,sum=0; 7 | scanf("%lld %lld", &n, &q); 8 | ll a[n]; 9 | ll prefix[n]; 10 | for (i = 0; i < n; i++) 11 | scanf("%lld", &a[i]); 12 | 13 | for(i=0;i 2 | #include 3 | #include 4 | #include 5 | 6 | int CheckCorrect(char * userin, char * secret) { 7 | int rndnum, i, j, correct, occ; 8 | correct = 0; 9 | occ = 0; 10 | int * tmp; 11 | int * tml; 12 | tmp = (int *)malloc(3 * sizeof(int)); 13 | tml = (int *)malloc(3 * sizeof(int)); 14 | for(i = 0; i < 3; i++) { 15 | tmp[i] = 0; 16 | tml[i] = 0; 17 | } 18 | for(i = 0; i < 3; i++) { 19 | if(userin[i] == secret[i]) { 20 | tmp[i] = 1; 21 | tml[i] = 1; 22 | correct++; 23 | } 24 | } 25 | for(i = 0; i < 3; i++) { 26 | for(j = 0; j < 3; j++) { 27 | if(userin[i] == secret[j] && tmp[i] != 1 && tml[j] != 1 && i != j) { 28 | tmp[i] = 1; 29 | tml[j] = 1; 30 | occ++; 31 | } 32 | } 33 | } 34 | 35 | printf("\nOcc: %d", occ); 36 | printf("\nCorrect: %d \n", correct); 37 | printf("\n"); 38 | return correct; 39 | } 40 | 41 | int main(int argc, char ** argv) { 42 | char * userin; 43 | char * secret; 44 | userin = (char *)malloc(3*sizeof(char)); 45 | secret = (char *)malloc(3*sizeof(char)); 46 | int i, j, o, guess, rndnum; 47 | guess = 3; 48 | 49 | srand(time(NULL)); 50 | for(i = 0; i < 3; i++) { 51 | rndnum = rand() % 3; 52 | switch(rndnum) { 53 | case 0: 54 | secret[i] = 'r'; 55 | break; 56 | case 1: 57 | secret[i] = 'g'; 58 | break; 59 | case 2: 60 | secret[i] = 'b'; 61 | break; 62 | default: 63 | printf("Invalid Letter"); 64 | exit(0); 65 | } 66 | } 67 | printf("Input your guess: "); 68 | fgets(userin, 4, stdin); 69 | while(1) { 70 | while(strlen(userin) != 3) { 71 | printf("Please re-enter you guess: "); 72 | fgets(userin, 4, stdin); 73 | } 74 | if(CheckCorrect(userin, secret) != 3) { 75 | printf("Guess again: "); 76 | fgets(userin, 4, stdin); 77 | } else { 78 | printf("\nThe secret code was: %s\n", secret); 79 | printf("You Win!\n"); 80 | printf("\n"); 81 | guess = 0; 82 | exit(0); 83 | } 84 | } 85 | } 86 | 87 | -------------------------------------------------------------------------------- /Programs/matrix_multiply.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | int a[10][10],b[10][10],mul[10][10],r,c,i,j,k; 5 | system("cls"); 6 | printf("enter the number of row="); 7 | scanf("%d",&r); 8 | printf("enter the number of column="); 9 | scanf("%d",&c); 10 | printf("enter the first matrix element=\n"); 11 | for(i=0;i 2 | #define MAX 100 3 | 4 | 5 | 6 | void main() 7 | { 8 | int arr[MAX]; 9 | int arr_size; 10 | int i; 11 | printf("enter array size\n"); 12 | scanf("%d", &arr_size); 13 | 14 | printf("\n enter array \n"); 15 | for(int i=0;i 2 | 3 | void findMinMax(int A[], int n){ 4 | int high=0; 5 | int low=9999; 6 | for (int i=0; ihigh){ 11 | high=A[i]; 12 | } 13 | } 14 | printf("highest element in the array is: %d \n", high); 15 | printf("lowest element in the array is %d \n", low); 16 | } 17 | 18 | void main(){ 19 | int array[5]; 20 | printf("populate array: \n"); 21 | for (int i=0; i<5; i++){ 22 | scanf("%d", &array[i]); 23 | } 24 | 25 | findMinMax(array, 5); 26 | } 27 | -------------------------------------------------------------------------------- /Programs/nThRoot.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | 4 | n th root of real number using newton-raphson 5 | username : 0ya-sh0 6 | */ 7 | 8 | 9 | double pow(double x, int n) { 10 | double xn = 1; 11 | for(int i=0;i0?diff:-diff; 43 | } 44 | 45 | int precision(double k, double _x, int n) { 46 | return abs(k-pow(_x,n)) < 0.0001; 47 | } 48 | 49 | double nThRoot(double k, int n) { 50 | double _x = apprx(n, k); 51 | while(!precision(k, _x, n)) { 52 | _x = next(_x, n, k); 53 | } 54 | return _x; 55 | } 56 | 57 | int main() { 58 | int n = 2; 59 | double k = 50; 60 | double x = nThRoot(k,n); 61 | printf("%d root of %lf : %lf\n",n,k,x); 62 | printf("%lf ^ %d = %lf", x,n, pow(x,n)); 63 | return 0; 64 | } 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /Programs/palindrom.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void isPalindrome(char str[]) 4 | { 5 | int l = 0; 6 | int h = strlen(str) - 1; 7 | while (h > l) 8 | { 9 | if (str[l++] != str[h--]) 10 | { 11 | printf("%s is Not Palindrome", str); 12 | return; 13 | } 14 | } 15 | printf("%s is palindrome", str); 16 | } 17 | 18 | int main() 19 | { 20 | char str[50]; 21 | scanf("%s",str); 22 | isPalindrome(str); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Programs/perfectno.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num,i=1,sum=0; 5 | scanf("%d",&num); 6 | for(i=1;i<=num/2;i++) 7 | { 8 | if (num%i==0) 9 | sum=sum+i; 10 | printf("%d\n",i); 11 | } 12 | if (num==sum) 13 | { 14 | printf("the no is perfect\n"); 15 | } 16 | else 17 | { 18 | printf("the no is not perfect\n"); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Programs/power_)recur.c: -------------------------------------------------------------------------------- 1 | //Program to calculate power using recursion 2 | #include 3 | int power(int n1, int n2); 4 | int main() 5 | { 6 | int base, powerRaised, result; 7 | printf("Enter base number: "); 8 | scanf("%d",&base); 9 | printf("Enter power number(positive integer): "); 10 | scanf("%d",&powerRaised); 11 | result = power(base, powerRaised); 12 | printf("%d^%d = %d", base, powerRaised, result); 13 | return 0; 14 | } 15 | int power(int base, int powerRaised) 16 | { 17 | if (powerRaised != 0) 18 | return (base*power(base, powerRaised-1)); 19 | else 20 | return 1; 21 | } 22 | -------------------------------------------------------------------------------- /Programs/qsort.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | void swap(int* a, int* b) 5 | { 6 | int t = *a; 7 | *a = *b; 8 | *b = t; 9 | } 10 | 11 | int partition (int arr[], int low, int high) 12 | { 13 | int pivot = arr[high]; 14 | int i = (low - 1); 15 | 16 | for (int j = low; j <= high- 1; j++) 17 | { 18 | if (arr[j] < pivot) 19 | { 20 | i++; 21 | swap(&arr[i], &arr[j]); 22 | } 23 | } 24 | swap(&arr[i + 1], &arr[high]); 25 | return (i + 1); 26 | } 27 | 28 | void quickSort(int arr[], int low, int high) 29 | { 30 | if (low < high) 31 | { 32 | int pi = partition(arr, low, high); 33 | 34 | quickSort(arr, low, pi - 1); 35 | quickSort(arr, pi + 1, high); 36 | } 37 | } 38 | 39 | void printArray(int arr[], int size) 40 | { 41 | int i; 42 | printf("["); 43 | for (i=0; i < size; i++) 44 | printf("%d ", arr[i]); 45 | printf("] \n"); 46 | } 47 | 48 | // Example code 49 | int main() 50 | { 51 | int arr[] = {10, 7, 8, 9, 1, 5}; 52 | int n = sizeof(arr)/sizeof(arr[0]); 53 | printf("Initial array : "); 54 | printArray(arr, n); 55 | quickSort(arr, 0, n-1); 56 | printf("Sorted array: "); 57 | printArray(arr, n); 58 | return 0; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /Programs/queuearray.c: -------------------------------------------------------------------------------- 1 | //queue implemented using array 2 | #include 3 | #include 4 | 5 | #define MAX 10 6 | 7 | typedef struct 8 | { 9 | int data[MAX]; 10 | int front; 11 | int rear; 12 | } QUEUE; 13 | 14 | int insert(QUEUE* q, int val) 15 | { 16 | if (q->rear == MAX - 1) 17 | { 18 | return 1; 19 | } 20 | if (q->front == -1) 21 | { 22 | q->front = q->rear = 0; 23 | } 24 | else 25 | { 26 | ++q->rear; 27 | } 28 | q->data[q->rear] = val; 29 | return 0; 30 | } 31 | 32 | int delete_static(QUEUE* q, int* del) 33 | { 34 | if (q->front == -1) 35 | { 36 | return 1; 37 | } 38 | *del = q->data[q->front]; 39 | if (q->front == q->rear) 40 | { 41 | q->front = q->rear = -1; 42 | } 43 | else 44 | { 45 | ++q->front; 46 | } 47 | return 0; 48 | } 49 | int delete_shift(QUEUE* q, int* del) 50 | { 51 | if (q->front == -1) 52 | { 53 | return 1; 54 | } 55 | *del = q->data[q->front]; 56 | if (q->front == q->rear) 57 | { 58 | q->front = q->rear = -1; 59 | } 60 | else 61 | { 62 | for (int i = q->rear; i >= q->front; --i) 63 | { 64 | q->data[i + 1] = q->data[i]; 65 | } 66 | } 67 | return 0; 68 | } 69 | 70 | int main() 71 | { 72 | QUEUE q; 73 | q.front = q.rear = -1; 74 | int val = rand() % 10; 75 | if (insert(&q, val) != 0) 76 | { 77 | printf("QUEUE Overflow\n"); 78 | } 79 | else 80 | { 81 | printf("%d inserted successfully\n", val); 82 | } 83 | 84 | int del; 85 | if (delete_static(&q, &del) != 0) 86 | { 87 | printf("QUEUE Underflow\n"); 88 | } 89 | else 90 | { 91 | printf("%d deleted successfully\n", del); 92 | } 93 | return 0; 94 | } 95 | 96 | -------------------------------------------------------------------------------- /Programs/random.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int i, n; 6 | printf("Ten random numbers in [1,100]\n"); 7 | 8 | for (i = 1; i <= 10; i++) { 9 | n = rand() % 100 + 1; 10 | printf("%d\n", n); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Programs/reverse_a_number.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n, reverse=0, rem; 5 | printf("Enter a number: "); 6 | scanf("%d", &n); 7 | while(n!=0) 8 | { 9 | rem=n%10; 10 | reverse=reverse*10+rem; 11 | n/=10; 12 | } 13 | printf("Reversed Number is : %d",reverse); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Programs/reverse_string.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char str[1024]; 4 | int main(){ 5 | if (fgets(str, 1024, stdin) == NULL || str[0] == '\n') { 6 | return 1; 7 | } 8 | for(int i=0;i 2 | 3 | int main() 4 | { 5 | int array[100], n, c, d, position, swap; 6 | 7 | printf("Enter number of elements\n"); 8 | scanf("%d", &n); 9 | 10 | printf("Enter %d integers\n", n); 11 | 12 | for (c = 0; c < n; c++) 13 | scanf("%d", &array[c]); 14 | 15 | for (c = 0; c < (n - 1); c++) 16 | { 17 | position = c; 18 | 19 | for (d = c + 1; d < n; d++) 20 | { 21 | if (array[position] > array[d]) 22 | position = d; 23 | } 24 | if (position != c) 25 | { 26 | swap = array[c]; 27 | array[c] = array[position]; 28 | array[position] = swap; 29 | } 30 | } 31 | 32 | printf("Sorted list in ascending order:\n"); 33 | 34 | for (c = 0; c < n; c++) 35 | printf("%d\n", array[c]); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Programs/sqrt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int t,n,ans; 6 | scanf("%d",&t); 7 | while(t--) 8 | { 9 | scanf("%d",&n); 10 | ans=sqrt(n); 11 | printf("%d\n",ans); 12 | 13 | } 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Programs/sum_of_digit.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | 5 | Program to print sum digit of positive number 6 | 7 | Sample input 0: 8 | 123 9 | Sample output 0: 10 | 6 11 | 12 | Sample input 1: 13 | 57 14 | Sample output: 15 | 12 16 | 17 | Sample input 2: 18 | -12 19 | Sample output 2: 20 | Negative Number 21 | 22 | 23 | */ 24 | int main() { 25 | 26 | int n, sum=0; 27 | scanf("%d", &n); 28 | 29 | if(n>0) { 30 | while(n>0) { // Check while n > 0 31 | sum+=n%10; // 123 % 10 = 3 so we get unit's digit and add it into the sum 32 | n/=10; // 123/10 = 12 ten's's digit changed to units 33 | } 34 | printf("%d", sum); // print sum 35 | } 36 | else printf("Negative Number"); 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Programs/sumdiag.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int mat[100][100]; 5 | int i,j,m,n,sum=0; 6 | printf("Enter the number of rows and columns for 1st matrix\n"); 7 | scanf("%d%d",&m,&n); 8 | printf("Enter the elements of the matrix\n"); 9 | for(i=0;i 2 | int main() 3 | { 4 | int a=10, b=20; 5 | printf("a=%d b=%d",a,b); 6 | a=a+b; 7 | b=a-b; 8 | a=a-b; 9 | printf("\nAfter swapping a=%d b=%d",a,b); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Programs/swap_numbers.c: -------------------------------------------------------------------------------- 1 | /** Contributor : Vivek Bhardwaj 2 | * swapping using X-OR 3 | **/ 4 | 5 | #include 6 | 7 | #include 8 | void swap(int *a, int *b) 9 | { 10 | int temp; 11 | 12 | temp = *a; 13 | *a = *b; 14 | *b = temp; 15 | } 16 | 17 | int main() 18 | { 19 | 20 | int x, y; 21 | printf("\nEnter two numbers which you want swap..."); 22 | scanf("%d%d", &x, &y); 23 | 24 | printf("\nBefore Swap X : %d And Y : %d ", x, y); 25 | 26 | swap(&x, &y); 27 | 28 | printf("\nAfter Swap X : %d And Y : %d ", x, y); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Programs/writefile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void main(){ 9 | //char msg[20] = "hello \n"; 10 | char buffer[1]; //used for reading file 11 | 12 | int fd = open("name.txt", O_CREAT | O_WRONLY, 0777); 13 | int w = write(fd, "chris", 5); //writing 'chris' to the file "name.txt" 14 | close(fd); 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Recursion/factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | int sum(int); 3 | main() 4 | { 5 | int x,z; 6 | printf("Enter the value of x:\n"); 7 | scanf("%d",&x); 8 | z=sum(x); 9 | printf("The sum of %d numbers is %d.\n",x,z); 10 | } 11 | int sum(int a) 12 | { 13 | int s; 14 | if(a==1) 15 | return(a); 16 | s=a*sum(a-1); 17 | return(s); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Recursion/factorial.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Recursion/factorial.exe -------------------------------------------------------------------------------- /Recursion/factorial.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Recursion/factorial.o -------------------------------------------------------------------------------- /Recursion/gcd.c: -------------------------------------------------------------------------------- 1 | #include 2 | int gcd(int,int); 3 | int min; 4 | main() 5 | { 6 | int x,y; 7 | printf("Enter the value of x:\n"); 8 | scanf("%d",&x); 9 | printf("Enter the value of y:\n"); 10 | scanf("%d",&y); 11 | min=x>y?y:x; 12 | printf("The GCD of %d and %d is %d.\n",x,y,gcd(x,y)); 13 | } 14 | int gcd(int a,int b) 15 | { 16 | if(a%min==0&&b%min==0) 17 | { 18 | return min; 19 | } 20 | min--; 21 | gcd(a,b); 22 | } 23 | -------------------------------------------------------------------------------- /Recursion/gcd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Recursion/gcd.exe -------------------------------------------------------------------------------- /Recursion/gcd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Recursion/gcd.o -------------------------------------------------------------------------------- /Recursion/lcm.c: -------------------------------------------------------------------------------- 1 | #include 2 | int lcm(int,int); 3 | main() 4 | { 5 | int x,y,ans; 6 | printf("Enter the value of x:\n"); 7 | scanf("%d",&x); 8 | printf("Enter the value of y:\n"); 9 | scanf("%d",&y); 10 | ans=lcm(x,y); 11 | printf("The lcm of %d and %d is %d.\n",x,y,ans); 12 | } 13 | int lcm(int a,int b) 14 | { 15 | static int comm=1;//value of comm remains present till the end of programs i.e it doesn't get overwrite. 16 | if(comm%a==0&&comm%b==0) 17 | { 18 | return comm; 19 | } 20 | comm++; 21 | lcm(a,b); 22 | } 23 | -------------------------------------------------------------------------------- /Recursion/lcm.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Recursion/lcm.exe -------------------------------------------------------------------------------- /Recursion/lcm.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Recursion/lcm.o -------------------------------------------------------------------------------- /Recursion/lcm1.c: -------------------------------------------------------------------------------- 1 | #include 2 | int lcm(int,int); 3 | int max; 4 | main() 5 | { 6 | int x,y,z; 7 | printf("Enter the value of x:\n"); 8 | scanf("%d",&x); 9 | printf("Enter the value of y:\n"); 10 | scanf("%d",&y); 11 | max=x>y?x:y; 12 | z=lcm(x,y); 13 | printf("The lcm of %d and %d is %d.\n",x,y,z); 14 | } 15 | int lcm(int a,int b) 16 | { 17 | if(max%a==0&&max%b==0) 18 | { 19 | return max; 20 | } 21 | max++; 22 | lcm(a,b); 23 | } 24 | -------------------------------------------------------------------------------- /Recursion/lcm1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Recursion/lcm1.exe -------------------------------------------------------------------------------- /Recursion/lcm1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Recursion/lcm1.o -------------------------------------------------------------------------------- /Recursion/power.c: -------------------------------------------------------------------------------- 1 | #include 2 | int power(int,int); 3 | main() 4 | { 5 | int x,y,z; 6 | printf("Enter the value of x:\n"); 7 | scanf("%d",&x); 8 | printf("Enter the value of y:\n"); 9 | scanf("%d",&y); 10 | z=power(x,y); 11 | printf("The answer is %d.",z); 12 | } 13 | int power(int a,int b) 14 | { 15 | int s; 16 | if(b==1) 17 | return a; 18 | s=a*power(a,b-1); 19 | return s; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Recursion/power.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Recursion/power.exe -------------------------------------------------------------------------------- /Recursion/power.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Recursion/power.o -------------------------------------------------------------------------------- /Recursion/sumofn.c: -------------------------------------------------------------------------------- 1 | #include 2 | int sum(int); 3 | main() 4 | { 5 | int x,z; 6 | printf("Enter the value of x:\n"); 7 | scanf("%d",&x); 8 | z=sum(x); 9 | printf("The sum of %d numbers is %d.\n",x,z); 10 | } 11 | int sum(int a) 12 | { 13 | int s; 14 | if(a==1) 15 | return(a); 16 | s=a+sum(a-1); 17 | return(s); 18 | } 19 | -------------------------------------------------------------------------------- /Recursion/sumofn.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Recursion/sumofn.exe -------------------------------------------------------------------------------- /Recursion/sumofn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/Recursion/sumofn.o -------------------------------------------------------------------------------- /STACK IMPLEMENTATION: -------------------------------------------------------------------------------- 1 | #include 2 | int push(int a[],int top) 3 | { char c; 4 | 5 | S: top++; 6 | scanf("%d",&a[top]); 7 | printf("Want to push more?(y/n):");fflush(stdin); 8 | scanf("%c",&c); 9 | if(c=='y') 10 | goto S; 11 | return top; 12 | 13 | } 14 | int pop(int a[],int top) 15 | { 16 | if(top == -1) 17 | printf(" -->>Stack is Underflow <<--"); 18 | else 19 | { 20 | printf("Element %d popped!",a[top]); 21 | top=top-1; 22 | } 23 | return top; 24 | } 25 | 26 | void display(int a[],int top) 27 | { 28 | for(int i=top;i>=0;i--) 29 | printf("%d\n",a[i]); 30 | } 31 | 32 | void peek(int a[],int top) 33 | { 34 | printf("%d\n",a[top]); 35 | } 36 | 37 | #define Max 10 38 | int main() 39 | { 40 | int stack[Max],top=-1,ch; 41 | char c; 42 | 43 | A: printf("\tMenu \n 1 Push \n 2 Pop \n 3 Display \n 4 Peek "); 44 | printf("\nEnter your choice: "); 45 | scanf("%d",&ch); 46 | 47 | 48 | switch(ch) 49 | { 50 | case 1: 51 | top= push(stack,top); 52 | break; 53 | case 2: 54 | top=pop(stack,top); 55 | break; 56 | case 3:display(stack,top); 57 | break; 58 | case 4:peek(stack,top); 59 | break; 60 | default: 61 | printf("Wrong input!"); 62 | break; 63 | } 64 | 65 | printf("\nMENU?(y/n): ");fflush(stdin); 66 | scanf("%c",&c); 67 | if(c=='y') 68 | goto A; 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /Stack Linked list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int data; 6 | struct node* pointer ; 7 | }; 8 | typedef struct node node; 9 | 10 | void push(int data, node** stack) { 11 | node* tmp; 12 | tmp = malloc(sizeof(node)); 13 | 14 | tmp->data = data; 15 | tmp->pointer = *stack; 16 | 17 | (*stack) = tmp; 18 | } 19 | 20 | void pop(node** stack) { 21 | if (*stack != NULL) { 22 | printf("Element Popped: %d", (*stack)->data); 23 | *stack = (*stack)->pointer; 24 | } 25 | else { 26 | printf("Stack Empty"); 27 | } 28 | } 29 | 30 | void printall(node* stack) { 31 | if (stack != NULL) { 32 | printf("Stack elements are :\n"); 33 | while (stack->pointer != NULL) { 34 | printf("%d\n", stack->data); 35 | stack = stack->pointer; 36 | } 37 | printf("%d\n", stack->data); 38 | 39 | } 40 | else 41 | { 42 | printf("Empty stack\n"); 43 | } 44 | } 45 | 46 | int main() { 47 | node* root = malloc(sizeof(node)); 48 | root->data = 3; 49 | root->pointer = NULL; 50 | push(4, &root); 51 | push(7, &root); 52 | push(12, &root); 53 | printall(root); 54 | pop(&root); 55 | printall(root); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /basic practice/area_of_circle.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | float r, area; 6 | printf("Enter the Radius of the circle "); 7 | scanf("%f", &r); 8 | area = 3.14 * r * r; 9 | printf("The area of the circle is %f", area); 10 | return 0; 11 | } -------------------------------------------------------------------------------- /basic practice/area_of_rectangle.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int l,b,area; 5 | printf("Enter the length and breath of Rectangle "); 6 | scanf("%d,%d",&l,&b); 7 | area=l*b; 8 | printf("The Area of the Rectangle is %d",area); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /basic practice/celsius_to_fahrenheit.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | float celsius,fahrenheit; 5 | printf("Enter the degree in celsius "); 6 | scanf("%f",&celsius); 7 | fahrenheit=celsius*1.8+32; 8 | printf("The degree of celsius to fahrenheit is %f",fahrenheit); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /calloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int n,*arr,i; 5 | printf("Enter the size:\n"); 6 | scanf("%d",&n); 7 | arr=(int*)(calloc(n,sizeof(int))); 8 | if(arr==NULL) 9 | { 10 | printf("No memory.\n"); 11 | } 12 | else 13 | { 14 | printf("Array Elements:\n"); 15 | for(i=0;i 4 | 5 | //function to check leap year 6 | int checkLeapYear(int year) 7 | { 8 | if( (year % 400==0)||(year%4==0 && year%100!=0) ) 9 | return 1; 10 | else 11 | return 0; 12 | } 13 | 14 | int main() 15 | { 16 | int i,n; 17 | 18 | printf("Enter the value of N: "); 19 | scanf("%d",&n); 20 | 21 | printf("Leap years from 1 to %d:\n",n); 22 | for(i=1;i<=n;i++) 23 | { 24 | if(checkLeapYear(i)) 25 | printf("%d\t",i); 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /insert_sort.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | 6 | 7 | void insertionSort(int arr[], int n) 8 | { 9 | int i, key, j; 10 | for (i = 1; i < n; i++) { 11 | key = arr[i]; 12 | j = i - 1; 13 | while (j >= 0 && arr[j] > key) { 14 | arr[j + 1] = arr[j]; 15 | j = j - 1; 16 | } 17 | arr[j + 1] = key; 18 | } 19 | } 20 | 21 | int main() 22 | { 23 | int arr[] = { 3,7,2,1,5 }; //input 24 | int n = 5; //number of values 25 | 26 | insertionSort(arr, n); 27 | for (int i = 0; i < n; i++) 28 | printf("%d ", arr[i]); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /malloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int s,*p,*ptr,i,sum=0,*q,m; 5 | printf("Enter the size of array:\n"); 6 | scanf("%d",&s); 7 | ptr=(int*)malloc(s*sizeof(int)); 8 | p=ptr; 9 | printf("Memory allocation is %u.",ptr); 10 | if(ptr==NULL) 11 | { 12 | printf("Out of Memory.\n"); 13 | exit(0); 14 | } 15 | printf("\nEnter %d values:\n",s); 16 | for(i=1;i<=s;i++) 17 | { 18 | scanf("%d",ptr); //Don't use backslash here after %d as if you use it then it will bring the cursor at the next line when value of i becomes equal to s. Even if you don't use \n the cursor will go to new line. 19 | sum+=*ptr; 20 | ptr++; 21 | } 22 | printf("Elements are:\n"); 23 | for(i=1;i<=s;i++) 24 | { 25 | printf("%d\n",*p); 26 | printf("\n%d its address is %u\n",*p,p); 27 | p++; 28 | } 29 | printf("\nAddition is %d.",sum); 30 | printf("Enter the new size of array:\n"); 31 | scanf("%d",&m); 32 | ptr=(int*)realloc(ptr,m*sizeof(int)); 33 | if(ptr=NULL) 34 | { 35 | printf("Out of memory."); 36 | exit(0); 37 | } 38 | printf("Reallocated memory %u.",ptr); 39 | q=ptr; 40 | printf("\nEnter %d values:\n",m); 41 | for(i=1;i<=s;i++) 42 | { 43 | scanf("%d",ptr); //Don't use backslash here after %d as if you use it then it will bring the cursor at the next line when value of i becomes equal to s. Even if you don't use \n the cursor will go to new line. 44 | sum+=*ptr; 45 | ptr++; 46 | } 47 | printf("Elements are:\n"); 48 | for(i=1;i<=s;i++) 49 | { 50 | printf("%d\n",*q); 51 | printf("\n%d its address is %u\n",*q,q); 52 | q++; 53 | } 54 | printf("\nAddition is %d.",sum); 55 | } 56 | -------------------------------------------------------------------------------- /malloc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/malloc.exe -------------------------------------------------------------------------------- /malloc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/malloc.o -------------------------------------------------------------------------------- /pointer/Address.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int j=9,x=5,y=3,z=8; 5 | int *p; 6 | p=&z; 7 | p=&y; 8 | *p=11; 9 | printf("The value of x is %d.\n",x); 10 | printf("The value of y is %d.\n",y); 11 | printf("The address of x is %d %d %d %d.\n",&j,&x,&y,&z); 12 | printf("The value of pointer is %d.\n",p); 13 | printf("The value of pointer is %p.\n",p); 14 | p=11; 15 | printf("The value of pointer is %d.\n",p); 16 | } 17 | -------------------------------------------------------------------------------- /pointer/Address.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/pointer/Address.exe -------------------------------------------------------------------------------- /pointer/Address.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/pointer/Address.o -------------------------------------------------------------------------------- /pointer/address2.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int a,b,*p,*q; 5 | p=&a; 6 | q=&b; 7 | printf("Address of p is %d and address of p+1 is %d.\n",p,p+1); 8 | printf("Address of p is %d and address of p+3 is %d.\n",p,p+3); 9 | printf("Address of p is %d and address of p-2 is %d.\n",p,p-2); 10 | printf("Address of p is %d and address of q is %d and p-q is %d.\n",p,q,p-q); 11 | } 12 | -------------------------------------------------------------------------------- /pointer/address2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/pointer/address2.exe -------------------------------------------------------------------------------- /pointer/address2.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/pointer/address2.o -------------------------------------------------------------------------------- /pointer/call by reference.c: -------------------------------------------------------------------------------- 1 | #include 2 | void f1(int *,int *); 3 | main() 4 | { 5 | int a=5,b=6; 6 | f1(&a,&b); 7 | printf("a=%d and b=%d",a,b); 8 | } 9 | void f1(int *p,int *q) //we can write *x and *y as different locations is allocated for same variable 10 | { 11 | *p=7; 12 | *q=9; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /pointer/call by reference.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/pointer/call by reference.exe -------------------------------------------------------------------------------- /pointer/call by reference.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/pointer/call by reference.o -------------------------------------------------------------------------------- /pointer/call by value.c: -------------------------------------------------------------------------------- 1 | #include 2 | void f1(int,int); 3 | main() 4 | { 5 | int a=5,b=6; 6 | f1(a,b); 7 | printf("a=%d and b=%d",a,b); 8 | } 9 | void f1(x,y) 10 | { 11 | x=4; 12 | printf("x=%d\n",x); 13 | } 14 | -------------------------------------------------------------------------------- /pointer/call by value.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/pointer/call by value.exe -------------------------------------------------------------------------------- /pointer/call by value.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/pointer/call by value.o -------------------------------------------------------------------------------- /pointer/display structure.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct Book 3 | { 4 | int bid; 5 | float rate; 6 | char name[25]; 7 | }; 8 | struct Book input(); 9 | 10 | struct Book input() 11 | { 12 | struct Book b; 13 | printf("\n Enter BookID,name,rate"); 14 | scanf("%d",&b.bid); 15 | fflush(stdin); 16 | gets(b.name); 17 | scanf("%f",&b.rate); 18 | return b; 19 | }; 20 | struct Book display(b) 21 | { 22 | struct Book b2; 23 | printf("\n BookID=%d\nBook name=%s\nBook rate=%f",b2.bid,b2.name,b2.rate); 24 | }; 25 | 26 | main() 27 | { 28 | struct Book b1,b2; 29 | b1=input(); 30 | b2=display(); 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /pointer/display structure.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/pointer/display structure.exe -------------------------------------------------------------------------------- /pointer/display structure.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/pointer/display structure.o -------------------------------------------------------------------------------- /pointer/exchange variable.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int x=7; 5 | printf("The value of x before using pointer is %d.\n\n",x); 6 | int *p; 7 | p=&x; 8 | *p=12; 9 | printf("The value of x after using pointer is %d.\n",x); 10 | } 11 | -------------------------------------------------------------------------------- /pointer/exchange variable.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/pointer/exchange variable.exe -------------------------------------------------------------------------------- /pointer/exchange variable.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/pointer/exchange variable.o -------------------------------------------------------------------------------- /queueprogram.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define MAX 50 4 | void insert(); 5 | void delete(); 6 | void display(); 7 | int queue_array[MAX]; 8 | int rear = - 1; 9 | int front = - 1; 10 | int main() 11 | { 12 | int choice; 13 | while (1) 14 | { 15 | printf("1.Insert element to queue n"); 16 | printf("2.Delete element from queue n"); 17 | printf("3.Display all elements of queue n"); 18 | printf("4.Quit n"); 19 | printf("Enter your choice : "); 20 | scanf("%d", &choice); 21 | switch(choice) 22 | { 23 | case 1: 24 | insert(); 25 | break; 26 | case 2: 27 | delete(); 28 | break; 29 | case 3: 30 | display(); 31 | break; 32 | case 4: 33 | exit(1); 34 | default: 35 | printf("Wrong choice n"); 36 | } 37 | } 38 | } 39 | void insert() 40 | { 41 | int item; 42 | if(rear == MAX - 1) 43 | printf("Queue Overflow n"); 44 | else 45 | { 46 | if(front== - 1) 47 | front = 0; 48 | printf("Inset the element in queue : "); 49 | scanf("%d", &item); 50 | rear = rear + 1; 51 | queue_array[rear] = item; 52 | } 53 | } 54 | void delete() 55 | { 56 | if(front == - 1 || front > rear) 57 | { 58 | printf("Queue Underflow n"); 59 | return; 60 | } 61 | else 62 | { 63 | printf("Element deleted from queue is : %dn", queue_array[front]); 64 | front = front + 1; 65 | } 66 | } 67 | void display() 68 | { 69 | int i; 70 | if(front == - 1) 71 | printf("Queue is empty n"); 72 | else 73 | { 74 | printf("Queue is : n"); 75 | for(i = front; i <= rear; i++) 76 | printf("%d ", queue_array[i]); 77 | printf("n"); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /rock_paper_scissor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int rockpaperscissor(char you, char com); 6 | 7 | int rockpaperscissor(char you,char com) 8 | { 9 | if(you==com) 10 | { 11 | return 0; 12 | } 13 | if(you=='r' && com=='p') 14 | { 15 | return -1; 16 | } 17 | else if(you=='p' && com=='r') 18 | { 19 | return 1; 20 | } 21 | if(you=='r' && com=='s') 22 | { 23 | return 1; 24 | } 25 | else if(you=='s' && com=='r') 26 | { 27 | return -1; 28 | } 29 | if(you=='s' && com=='p') 30 | { 31 | return 1; 32 | } 33 | else if(you=='p' && com=='s') 34 | { 35 | return -1; 36 | } 37 | } 38 | 39 | void main() 40 | { 41 | char you,com; 42 | srand(time(0)); 43 | int n = rand()%100 + 1; 44 | if(n>0 && n<33) 45 | { 46 | com = 'r'; 47 | } 48 | else if(n>=33 && n<66) 49 | { 50 | com = 'p'; 51 | } 52 | else if(n>=66 && n<=100) 53 | { 54 | com = 's'; 55 | } 56 | printf("Enter r for rock, p for paper, s for scissor:\n"); 57 | scanf("%c",&you); 58 | int result = rockpaperscissor(you,com); 59 | if(result==0) 60 | { 61 | printf("You have tied with computer\n"); 62 | } 63 | else if(result==1) 64 | { 65 | printf("You have won the game\n"); 66 | } 67 | else if(result==-1) 68 | { 69 | printf("You have lost the game\n"); 70 | } 71 | printf("You choose %c and computer choose %c\n",you,com); 72 | } -------------------------------------------------------------------------------- /selection_sort.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | void swap(int *xp, int *yp) 5 | { 6 | int temp = *xp; 7 | *xp = *yp; 8 | *yp = temp; 9 | } 10 | 11 | void selectionSort(int arr[], int n) 12 | { 13 | int i, j, min_idx; 14 | for (i = 0; i < n-1; i++) 15 | { 16 | min_idx = i; 17 | for (j = i+1; j < n; j++) 18 | if (arr[j] < arr[min_idx]) 19 | min_idx = j; 20 | swap(&arr[min_idx], &arr[i]); 21 | } 22 | } 23 | 24 | 25 | 26 | int main() 27 | { 28 | int arr[] = { 3,7,2,1,5 }; //input 29 | int n = 5; //number of values 30 | 31 | insertionSort(arr, n); 32 | for (int i = 0; i < n; i++) 33 | printf("%d ", arr[i]); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /stringwithoutfunctions/comparestring.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int i,flag=0,m,n; 5 | char c[20],s[20]; 6 | printf("Enter string 1:\n"); 7 | gets(c); 8 | printf("Enter string 2:\n"); 9 | gets(s); 10 | m=strlen(c); 11 | n=strlen(s); 12 | if(m==n) 13 | { 14 | for(i=0;s[i]!='\0';i++) 15 | { 16 | if(s[i]==c[i]) 17 | { 18 | flag=1; 19 | } 20 | else 21 | { 22 | break; 23 | } 24 | } 25 | } 26 | if(flag==0) 27 | printf("The strings are not equal.\n"); 28 | else 29 | printf("The strings are equal.\n"); 30 | } 31 | -------------------------------------------------------------------------------- /stringwithoutfunctions/comparestring.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/stringwithoutfunctions/comparestring.exe -------------------------------------------------------------------------------- /stringwithoutfunctions/comparestring.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/stringwithoutfunctions/comparestring.o -------------------------------------------------------------------------------- /stringwithoutfunctions/copystring.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int i; 5 | char c[20],s[20]; 6 | printf("Enter the string 1:\n"); 7 | gets(c); 8 | for(i=0;c[i]!='\0';i++) 9 | { 10 | s[i]=c[i]; 11 | } 12 | s[i]='\0'; 13 | puts(s); 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /stringwithoutfunctions/copystring.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/stringwithoutfunctions/copystring.exe -------------------------------------------------------------------------------- /stringwithoutfunctions/copystring.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/stringwithoutfunctions/copystring.o -------------------------------------------------------------------------------- /stringwithoutfunctions/copystring2.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int i; 5 | char c[20],s[20]; 6 | printf("Enter the string 1:\n"); 7 | gets(c); 8 | for(i=0;c[i]!='\0';i++) 9 | { 10 | s[i]=c[i]; 11 | } 12 | s[i]='\0'; 13 | for(i=0;s[i]!='\0';i++) //method1 14 | { 15 | printf("%c",s[i]); 16 | } 17 | printf("\n"); 18 | printf("%s\n",s); //method 2 19 | 20 | puts(s); //method 3 21 | } 22 | -------------------------------------------------------------------------------- /stringwithoutfunctions/lengthofstrings.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int i; 5 | char c[20]; 6 | printf("Enter the string:\n"); 7 | gets(c); 8 | for(i=0;c[i]!='\0';i++); 9 | printf("The length of the string is %d.\n",i); 10 | } 11 | -------------------------------------------------------------------------------- /stringwithoutfunctions/lengthofstrings.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/stringwithoutfunctions/lengthofstrings.exe -------------------------------------------------------------------------------- /stringwithoutfunctions/lengthofstrings.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/stringwithoutfunctions/lengthofstrings.o -------------------------------------------------------------------------------- /stringwithoutfunctions/lowertoupper.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int i; 5 | char c[20]; 6 | printf("Enter the string:\n"); 7 | gets(c); 8 | for(i=0;c[i]!='\0';i++) 9 | { 10 | if(c[i]>96&&c[i]<123) 11 | printf("%c",c[i]-32); 12 | else 13 | printf("%c",c[i]); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /stringwithoutfunctions/lowertoupper.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/stringwithoutfunctions/lowertoupper.exe -------------------------------------------------------------------------------- /stringwithoutfunctions/lowertoupper.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/stringwithoutfunctions/lowertoupper.o -------------------------------------------------------------------------------- /stringwithoutfunctions/reversethestring.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int i,l,s; 5 | char c[20]; 6 | printf("Enter the string:\n"); 7 | gets(c); 8 | for(i=0;c[i]!='\0';i++); 9 | for(l=0;l 2 | main() 3 | { 4 | int i; 5 | char c[20]; 6 | printf("Enter the string:\n"); 7 | gets(c); 8 | for(i=0;c[i]!='\0';i++) 9 | { 10 | if(c[i]>64&&c[i]<91) 11 | printf("%c",c[i]+32); 12 | else 13 | printf("%c",c[i]); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /stringwithoutfunctions/uppertolower.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/stringwithoutfunctions/uppertolower.exe -------------------------------------------------------------------------------- /stringwithoutfunctions/uppertolower.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/stringwithoutfunctions/uppertolower.o -------------------------------------------------------------------------------- /ternaryoperator: -------------------------------------------------------------------------------- 1 | // C program to find largest among two 2 | // numbers using ternary operator 3 | 4 | #include 5 | #define max(a, b) ((a)>(b))?(a):(b) 6 | #define min(a, b) ((a)<(b))?(a):(b) 7 | 8 | int main() 9 | { 10 | // variable initialization 11 | int n1 = 5, n2 = 10, n3 = -12; 12 | 13 | // Print the largest number 14 | printf("Largest number between %d, %d and %d is %d. ", n1, n2, n3, max(n1, max(n2, m3))); 15 | // Print the smallest number 16 | printf("Smallest number between %d , %d and %d is %d", n1, n2, n3, min(n1, min(n2, m3))); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /useofdma.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int *p; 5 | p=(int*)malloc(4); 6 | *p=27; 7 | printf("The value in malloc is %d.\n",*p); 8 | } 9 | -------------------------------------------------------------------------------- /useofdma.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/useofdma.exe -------------------------------------------------------------------------------- /useofdma.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FireFeathers06/Basic-C-Programming/27f5312d45985e2279c05944463840e87376eda0/useofdma.o --------------------------------------------------------------------------------