Created
November 1, 2022 09:54
-
-
Save anisur3036/69fce58c01c6a7c1dfd6f5ad4ee746e0 to your computer and use it in GitHub Desktop.
Value will be added specific index in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* You will be given an positive integer N and after that an integer array of size N. | |
* Then you will be given Q which refers to queries. For each query you will be given i and v where i refers to the index and v to value. | |
* You need to add the value to that index. After all of the queries print the values | |
*/ | |
#include <stdio.h> | |
int main() { | |
// Write C code here | |
int i, n, m; | |
int value; | |
printf("Number of array element: "); | |
scanf("%d", &n); | |
int arr[n]; | |
for(i=0; i<n; i++) { | |
scanf("%d", &arr[i]); | |
} | |
for(i=0; i<n; i++) { | |
printf("%d ", arr[i]); | |
} | |
printf("\ntake an input\n"); | |
scanf("%d", &m); | |
int arr2[m]; | |
for(i=0; i<m; i++) { | |
scanf("%d %d", &arr2[i], &value); | |
arr[arr2[i]] += value; | |
} | |
printf("Result is: "); | |
for(i=0; i<n; i++) { | |
printf("%d ", arr[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment