fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int get_array(double **array)
  5. {
  6. int nums_elements, counter;
  7.  
  8. do
  9. {
  10. printf("Quanti elementi deve contenere l'insieme? ");
  11. scanf("%d", &nums_elements);
  12. } while (nums_elements <= 0);
  13.  
  14. *array = (double *)calloc(nums_elements, sizeof (double));
  15.  
  16. for (counter = 0; counter < nums_elements; ++counter)
  17. {
  18. printf("Inserire valore %d-->", counter+1);
  19. scanf("%lf", &((*array)[counter]));
  20. }
  21. return (nums_elements);
  22. }
  23.  
  24. void print(double array[], int count)
  25. {
  26. printf("\n\n");
  27. for(int i=0; i<count; i++)
  28. printf("%lf | ", array[i]);
  29. printf("\n");
  30. }
  31.  
  32. int main(void)
  33. {
  34. int count;
  35. double *insieme_A;
  36. count = get_array(&insieme_A);
  37. print(insieme_A, count);
  38. return 0;
  39. }
Success #stdin #stdout 0s 9424KB
stdin
5
89 45 31 2 56
stdout
Quanti elementi deve contenere l'insieme? Inserire valore 1-->Inserire valore 2-->Inserire valore 3-->Inserire valore 4-->Inserire valore 5-->

89.000000 | 45.000000 | 31.000000 | 2.000000 | 56.000000 |