Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. void print_array(double *array, int power_of_the_massive){
  5. for(int i = 0; i < power_of_the_massive; i++){
  6. printf("%lf ", array[i]);
  7. }
  8. }
  9.  
  10. int create_array(double *a, int power_of_the_massive){
  11. a = (double *) calloc(sizeof(double), power_of_the_massive);
  12. for (int i = 0; i<power_of_the_massive; i++)
  13. {
  14. printf("a[%d] = ", i);
  15. scanf("%lf", &a[i]);
  16. }
  17. return 0;
  18. }
  19.  
  20. double find_first_min(int *a, int power_of_the_massive,int index2, double first_min){
  21.  
  22.  
  23. for (int i = 0; i < power_of_the_massive; i++) {
  24. if (a[i] < first_min) {
  25. first_min = a[i];
  26. index2 = i;
  27. }
  28. }
  29.  
  30. return 0;
  31.  
  32. }
  33.  
  34. int main(void) {
  35. int index1 = 0, index2 = 0, power_of_the_massive;
  36. double *a, *b = NULL;
  37.  
  38.  
  39. printf("power_of_the_massive = ");
  40. if (scanf("%d", &power_of_the_massive) == 0 || getchar() != '\n') {
  41. printf("power_of_the_massive is bad");
  42. return 0;
  43. }
  44. if(power_of_the_massive<=0){
  45. printf("power_of_the_massive is bad");
  46. return 0;
  47. }
  48.  
  49.  
  50. a = (double *) create_array(a, power_of_the_massive);
  51.  
  52. double first_min=a[0];
  53. print_array(a, power_of_the_massive);
  54.  
  55.  
  56.  
  57. for (int i = 0; i < power_of_the_massive; i++) {
  58. if (a[i] < first_min) {
  59. first_min = a[i];
  60. index1 = i;
  61. }
  62. }
  63.  
  64.  
  65. for (int i = 0; i < power_of_the_massive; i++){
  66. if (a[i]==0){
  67. index2=i;
  68. }
  69. }
  70.  
  71. b = (double *) calloc(sizeof(double), power_of_the_massive-(index1-index2));
  72. for (int i=0; i<power_of_the_massive-(index1-index2); i++){
  73. for(int j=0; i<power_of_the_massive-(index1-index2);j++){
  74. b[i]=a[j];
  75. }
  76. }
  77. print_array(b, power_of_the_massive-(index1-index2));
  78. free(a);
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement