#c_arrays_programs
Explore tagged Tumblr posts
codezclub · 9 years ago
Text
Write a C Program to Merge Sort of two different arrays
Write a C Program to Merge Sort of two different arrays
  #include void Merge(int * , int , int , int ); void MergeSort(int *array, int left, int right) { int middle = (left+right)/2; /* We have to sort only when left<right because when left=right it is anyhow sorted*/ if(left<right) { /* Sort the left part */ MergeSort(array, left, middle); /* Sort the right part */ MergeSort(array, middle + 1,…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C Program to Calculate Addition of All Elements in Array
Write a C Program to Calculate Addition of All Elements in Array
  #include int main() { int i, arr[50], sum, num; printf("\nEnter no of elements :"); scanf("%d", &num); //Reading values into Array printf("\nEnter the values :"); for (i = 0; i < num; i++) scanf("%d", &arr[i]); //Computation of total sum = 0; for (i = 0; i < num; i++) sum = sum + arr[i]; //Printing of all elements of array for (i…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C Program to Implement a Queue using an Array
Write a C Program to Implement a Queue using an Array
#include #define MAX 50 int queue_array[MAX]; int rear = - 1; int front = - 1; main() { int choice; while (1) { printf("1.Insert element to queue \n"); printf("2.Delete element from queue \n"); printf("3.Display all elements of queue \n"); printf("4.Quit \n"); printf("Enter your choice : "); scanf("%d", &choice); switch (choice) { case 1:…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C Program to implement Stack Operations Using Arrays
Write a C Program to implement Stack Operations Using Arrays
Write a C Program to implement Stack Operations Using Arrays
  #include #include #include #define size 5 struct stack { int s[size]; int top; } st; int stfull() { if (st.top >= size - 1) return 1; else return 0; } void push(int item) { st.top++; st.s[st.top] = item; } int stempty() { if (st.top == -1) return 1; else return 0; } int pop() { int item; item = st.s[st.top]; st.top--; return (item); }…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C Program to Find Union & Intersection of 2 Arrays
Write a C Program to Find Union & Intersection of 2 Arrays
  #include #define SIZE 5 void get_value(int arr[]); void print_value(int arr[], int n); void function_sort(int arr[]); int find_intersection(int array1[], int array2[], int intersection_array[]); int find_union(int array1[], int array2[], int union_array[]); void main() { int array1[SIZE], array2[SIZE], intersection_array[SIZE],…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C program to replace all Even elements by 0 and Odd by 1
Write a C program to replace all Even elements by 0 and Odd by 1
Write a C program to replace all Even elements by 0 and Odd by 1
  #include void readArray(int arr[], int size) { int i =0; printf("\nEnter elements : \n"); for(i=0; i < size; i++) { printf("Enter arr[%d] : ",i); scanf("%d",&arr[i]); } } /** funtion : printArray() input : arr ( array of integer ), size to display ONE-D integer array on standard output device (moniter). **/ void printArray(int…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C program to sort even and odd elements of array separately
Write a C program to sort even and odd elements of array separately
Write a C program to sort even and odd elements of array separately
  #include #include //Used for INT_MAX #define MAX_SIZE 1000 //Maximum size of the array /* * Functions used in this program */ void arrange(int arr[], int len, int evenIndex, int evenCount, int oddIndex, int oddCount); void sort(int arr[], int start, int end); void print(int arr[], int len); int main() { int arr[MAX_SIZE], i, n;…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C program to sort an array in descending order
Write a C program to sort an array in descending order
Write a C program to sort an array in descending order
  #include int main() { int arr[100]; int size, i, j, temp; /* * Read size of array and elements in array */ printf("Enter size of array: "); scanf("%d", &size); printf("Enter elements in array: "); for(i=0; i<size; i++) { scanf("%d", &arr[i]); } /* * Array sorting code */ for(i=0; i<size; i++) { for(j=i+1; j<size; j++) { /* * If there is a…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C program to sort an array in ascending order
Write a C program to sort an array in ascending order
Write a C program to sort an array in ascending order
  #include int main() { int arr[100]; int size, i, j, temp; /* * Read size of array and elements in array */ printf("Enter size of array: "); scanf("%d", &size); printf("Enter elements in array: "); for(i=0; i<size; i++) { scanf("%d", &arr[i]); } /* * Array sorting code */ for(i=0; i<size; i++) { for(j=i+1; j<size; j++) { /* * If there is a…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C program to search an element in the array
Write a C program to search an element in the array
Write a C program to search an element in the array
  #include int main() { int arr[100]; int size, i, num, flag; /* * Read size of array and elements in array */ printf("Enter size of array: "); scanf("%d", &size); printf("Enter elements in array: "); for(i=0; i<size; i++) { scanf("%d", &arr[i]); } printf("\nEnter the element to search within the array: "); scanf("%d", &num); /* Supposes that…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C program to find reverse of an array
Write a C program to find reverse of an array
Write a C program to find reverse of an array
  #include int main() { int arr[100], reverse[100]; int size, i, j; /* * Reads the size of array and elements in array */ printf("Enter size of the array: "); scanf("%d", &size); printf("Enter elements in array: "); for(i=0; i=0; i--) { reverse[j] = arr[i]; j++; } /* * Prints the reversed array */ printf("\nReversed array : "); for(i=0; i<size; i++) {…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C Program to merge two sorted array in descending order
Write a C Program to merge two sorted array in descending order
Write a C Program to merge two sorted array in descending order
  #include #define MAX_SIZE 100 //Maximum size of the array int main() { int arr1[100], arr2[100], arr3[200]; int size1, size2, size3; int i, j, k; /* * Reads size of first array and element in first array */ printf("Enter the size of first array : "); scanf("%d", &size1); printf("Enter elements in first array : "); for(i=0; i<size1;…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C program to merge two sorted array in ascending order
Write a C program to merge two sorted array in ascending order
Write a C program to merge two sorted array in ascending order
#include #define MAX_SIZE 100 //Maximum size of the array   int main() {     int arr1[MAX_SIZE], arr2[MAX_SIZE], arr3[MAX_SIZE];     int size1, size2, size3;     int i, j, k;            /*      * Read size of first array and elements in first array      */     printf("Enter the size of first array : ");     scanf("%d", &size1);…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C program to count frequency of each element in an array
Write a C program to count frequency of each element in an array
Write a C program to count frequency of each element in an array
  #include int main() { int arr[100], freq[100]; int size, i, j, count; /* * Read size of array and elements in array */ printf("Enter size of array: "); scanf("%d", &size); printf("Enter elements in array: "); for(i=0; i<size; i++) { scanf("%d", &arr[i]); freq[i] = -1; } /* * Counts frequency of each element */ for(i=0; i<size;…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C program to delete all duplicate elements from an array
Write a C program to delete all duplicate elements from an array
Write a C program to delete all duplicate elements from an array
  #include #define MAX_SIZE 100 //Maximum size of the array int main() { int arr[MAX_SIZE]; //Declares an array of size 100 int size; //Total number of elements in array int i, j, k; //Used for loop /* * Reads size and elements of array */ printf("Enter size of the array : "); scanf("%d", &size); printf("Enter elements in array :…
View On WordPress
0 notes
codezclub · 9 years ago
Text
Write a C program count total number of duplicate elements in an array
Write a C program count total number of duplicate elements in an array
Write a C program count total number of duplicate elements in an array
  #include int main() { int arr[100]; int i,j, n, count = 0; /* * Reads size and elements of array */ printf("Enter size of the array : "); scanf("%d", &n); printf("Enter elements in array : "); for(i=0; i<n; i++) { scanf("%d", &arr[i]); } /* * Finds all duplicate elements in array */ for(i=0; i<n; i++) { for(j=i+1; j<n; j++)…
View On WordPress
0 notes