Created
February 23, 2020 10:39
-
-
Save aasumitro/aa0b33d2cab304282bfde19855c89cb6 to your computer and use it in GitHub Desktop.
add value to an array 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
#include <stdio.h> | |
int main() { | |
// init array | |
int arr[10] = {18, 27, 24, 33, 72, 0, 0, 0, 0, 0}; | |
// declare var | |
int i, number; | |
// print array list | |
printf("Array of Number\n"); | |
for (i = 0; i < 10; i++) { | |
printf("index %d value %d\n", i, arr[i]); | |
} | |
// insert new data | |
printf("\n"); | |
printf("\n"); | |
printf("Enter an integer: "); | |
scanf("%d", &number); | |
// add array to new variable | |
int new_arr[] = {}; | |
new_arr[0] = number; | |
for (i = 0; i < 10; i++) { | |
new_arr[i+1] = arr[i]; | |
} | |
// print new array list | |
printf("\n"); | |
printf("\n"); | |
printf("New Array of Number\n"); | |
for (i = 0; i < 10; i++) { | |
printf("index %d value %d\n", i, new_arr[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment