|
דף
הבית >>זיכרון דינמי
שאלות |
פיתרון תרגיל 6 .
|
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
void print_array(int *array, int size)
{
for( ; size; size--, array++)
printf("%d ", *array);
printf("\n");
}
void main()
{
int *array=(int*)calloc(1,sizeof(int));
int size=1;
char flag=1;
int number;
clrscr();
printf("Enter numbers (to finish enter the number 0):\n");
scanf("%d", &number);
*array=number;
while((number)&&(flag))
{
size++;
scanf("%d", &number);
flag=*(char*)realloc(array,size);
if(flag)
*(array+size-1)=number;
else
size--;
}
printf("\nThere are %d elements in the array.\n",size);
print_array(array,size);
free(array);
getch();
}
|
|
 הקודם
|
|
הבא 
|
|