Posted by: khai_k_khai_k September 25, 2011
Login in to Rate this Post:
0
?
To dynamically allocate an array:
int n;
printf("Kati euta number: ");
scanf("%d", &n);
int * arr = (int *) malloc(n * sizeof(int));
for(int i=0;i<n;i++)
{
printf("\nNumber %d halnus: ",i+1);
scanf("%d",&arr[i]);
}
for(int i=0;i<n;i++)
{
printf("%d\t",arr[i]);
}
free(arr);
Your Prof. might want you to swap the elements in the array (in place). See http://www.cplusplus.com/reference/algorithm/swap/ for details on this function.
Good luck!
Your Prof. might want you to swap the elements in the array (in place). See http://www.cplusplus.com/reference/algorithm/swap/ for details on this function.
Good luck!