Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #define _CRT_SECURE_NO_WARNINGS
- void main() {
- /*Програма, която заделя памет за масив от цели числа.
- Броят на елементите на масива се определя от потребителя.
- Запълването на стойности се извършва от потребитеря.
- Потребителя въвежда нова големина на масива,
- посредством realloc се заделя нова големина на масива,
- ако новата големина е по-голяма от старата, потребителя трабва да допълни масива.
- След, което се отпечатва.
- */
- int s1, s2, i;
- printf("Enter the length of the array: ");
- scanf("%d", &s1);
- int* array;
- array = (int*)malloc(s1 * sizeof(int));
- if (array == NULL) exit(1);
- else printf("OK!\n");
- for (i = 0; i < s1; i++) {
- printf("Enter value for element No %d: ", i+1);
- scanf("%d", array[i]);
- }
- printf("Enter the length of the new array: ");
- scanf("%d", &s2);
- if (s1 > s2 || s1 == s2)
- {
- for (int j = 0; j < s2; j++)
- {
- printf("%d", array[j]);
- }
- }
- else
- {
- array = (int*)realloc(array, s2);
- for (i; i < s2; i++)
- scanf("%d", array[i]);
- for (int j = 0; j < s2; j++)
- {
- printf("%d", array[j]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement