daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Jan 17th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void input(int n1, int *K1, int n2, int *K2);
  5.    
  6. void newArray(int n, int *K, int n1, int *K1, int n2, int *K2);
  7.  
  8. void sort(int n, int *K);
  9.  
  10. void output(int m, int *K);
  11.  
  12. int main () {
  13.    
  14.     //input
  15.    
  16.     int n1, n2;
  17.     printf("Insert n1: ");
  18.     scanf("%d", &n1);
  19.     printf("Insert n2: ");
  20.     scanf("%d", &n2);
  21.    
  22.     int *K1 = (int*) malloc (n1 * (sizeof(int)));
  23.     int *K2 = (int*) malloc (n2 * (sizeof(int)));
  24.    
  25.     input(n1, K1, n2, K2);
  26.    
  27.     int m;
  28.     printf("Insert m: ");
  29.     scanf("%d", &m);
  30.    
  31.     int n = n1 + n2;
  32.     int *K = (int*) malloc (n * (sizeof(int)));
  33.     newArray(n, K, n1, K1, n2, K2);
  34.    
  35.     sort(n, K);
  36.  
  37.     output(m, K);
  38.  
  39.     return 0;
  40. }
  41.  
  42. void input(int n1, int *K1, int n2, int *K2){
  43.     int i;
  44.    
  45.     for(i = 0; i < n1; i++) {
  46.         printf("Insert K1[%d] elements: ", i);
  47.         scanf("%d", &K1[i]);
  48.     }
  49.    
  50.     printf("\n");
  51.     for(i = 0; i < n2; i++) {
  52.         printf("Insert K2[%d] elements: ", i);
  53.         scanf("%d", &K2[i]);
  54.     }
  55.  
  56. }
  57.  
  58. void newArray(int n, int *K, int n1, int *K1, int n2, int *K2){
  59.     int i;
  60.    
  61.     for(i = 0; i < n1; i++) {
  62.         K[i] = K1[i];
  63.     }
  64.    
  65.     for(i = 0; i < n2; i++) {
  66.         K[i+n1] = K2[i];
  67.     }
  68. }
  69.  
  70. void sort(int n, int *K){
  71.     int sort;
  72.     do{
  73.         sort = 1;
  74.         int i;
  75.         for(i = 0; i < n-1; i++){
  76.             if(K[i] < K[i+1]){
  77.                 int tmp = K[i];
  78.                 K[i] = K[i+1];
  79.                 K[i+1] = tmp;
  80.                 sort = 0;
  81.             }
  82.         }
  83.     }while(sort==0);
  84.        
  85. }
  86.  
  87. void output(int m, int *K){
  88.     int i;
  89.     for(i = 0; i < m; i++) {
  90.         printf("Element %d is %d\n", i+1, K[i]);
  91.     }
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top