Skip to content

Instantly share code, notes, and snippets.

@anisur3036
Created November 1, 2022 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anisur3036/69fce58c01c6a7c1dfd6f5ad4ee746e0 to your computer and use it in GitHub Desktop.
Save anisur3036/69fce58c01c6a7c1dfd6f5ad4ee746e0 to your computer and use it in GitHub Desktop.
Value will be added specific index in C
/*
* 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