I want to find the minimum number and summary from a dynamic integer table. I do not know why results not shown. Have I done something wrong on the malloc ? May I use realloc too ?
#include <stdlib.h>
#include <stdio.h>
int main()
{
int n,i,min,sum,xronos;
int* array;
printf("Give me how many numbers does the table will have: \n");
scanf("%d",&n);
array=(int*)malloc(n*sizeof(int));
for(i=1;i<=n;i++)
{
printf("Give the number %d",i);
printf("\n");
scanf("%d",&array[i]);
}
for(i=1;i<=n;i++)
{
sum=sum+array[i];
if (i=1)
{
min=array[i];
}
else
{
if (array[i]<min)
{
min=array[i];
}
}
}
printf("%d",sum);
printf("\n The answer is :",(n-2)*min+(sum-min));
getch();
return 0;
}