Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int k, n, *a, *b, *c;
  6.     printf("Subject: Given arrays a and b, consisting of n elements each. Get the array c, where c[k] = a[k] + b[k] \n");
  7.     do {
  8.         printf("Enter the size of the array: \n");
  9.         scanf("%d", &n); } while (n < 1);
  10.     a = malloc(n * sizeof(int));
  11.     b = malloc(n * sizeof(int));
  12.     c = malloc(n * sizeof(int));
  13.     printf("Array:\n");
  14.     printf("Enter a[k] \n");
  15.     for (k = 0; k < n; k++) {
  16.         scanf_s("%d", &a[k]);}
  17.     printf("Enter b[k] \n");
  18.     for (k = 0; k < n; k++) {
  19.         scanf_s("%d", &b[k]);
  20.     }
  21.     for (k = 0; k < n; k++) {
  22.         c[k] = a[k] + b[k];
  23.         printf("%d ", c[k]);
  24.     }
  25.     getch();
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement