fahimkamal63

Add to array

Feb 10th, 2020
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main(){
  4.     int n, i;
  5.     printf("Enter the number of elements: ");
  6.     scanf("%d", &n);
  7.     int a[n], b[n], c[n];
  8.     printf("Enter the elements of array a: ");
  9.     for(i = 0; i < n; i++){
  10.         scanf("%d", &a[i]);
  11.     }
  12.  
  13.     printf("Enter the elements of array b: ");
  14.     for(i = 0; i < n; i++){
  15.         scanf("%d", &b[i]);
  16.     }
  17.  
  18.     for(i = 0; i < n; i++){
  19.         c[i] = a[i] + b[i];
  20.     }
  21.  
  22.     printf("The result is: \n");
  23.     for(i = 0; i < n; i++){
  24.         printf("c[%d] = %d\n", i, c[i]);
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment