safwan092

c_code_homework

Sep 25th, 2022
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int i=0;
  6.  
  7. int sumofarray(int a[],int n)
  8. {
  9. int min,max,K;
  10. min=max=a[0];
  11. for(K=1; K<n; K++)
  12. {
  13. if(min>a[K])
  14. min=a[K];
  15. if(max<a[K])
  16. max=a[K];
  17. }
  18.  
  19. printf("\nminimum of array is : %d",min);
  20. printf("\nmaximum of array is : %d",max);
  21. }
  22.  
  23. int main(void)
  24. {
  25. FILE *fp;
  26.  
  27. fp = fopen("Data.csv","r");
  28.  
  29. if(fp == NULL)
  30. {
  31. printf("fucking ideot\nProgram terminating ...");
  32. exit(0);
  33. }
  34.  
  35. int ID;
  36.  
  37. char names[30];
  38.  
  39. int age;
  40. int age_list[100];
  41.  
  42. int weight;
  43. int weight_list[100];
  44.  
  45. float tage = 0;
  46. float tweight = 0;
  47. float avg_age = 0;
  48. float avg_weight = 0;
  49.  
  50. char line[100];
  51.  
  52. char *sp;
  53.  
  54. while (fgets(line,100,fp) != NULL)
  55. {
  56. sp = strtok(line,",");
  57.  
  58. ID = atoi(sp);
  59.  
  60. sp = strtok(NULL,",");
  61. strcpy(names , sp);
  62.  
  63. sp = strtok(NULL,",");
  64.  
  65. age = atoi(sp);
  66. age_list[i] = age;
  67.  
  68. sp = strtok(NULL,",");
  69.  
  70. weight = atoi(sp);
  71. weight_list[i] = weight;
  72. //tage += age;
  73.  
  74. //printf("\n%d %s %d %d",ID, names,age,weight);
  75. i++;
  76. }
  77.  
  78. //printf("\nthe average is %.2f",tage/100 );
  79. for(int j=0;j<=100;j++){
  80. age_list[j] = age_list[j+1];
  81. //weight_list[j] = weight_list[j+1];
  82. }
  83. for(int z=0;z<100;z++){
  84. tage += age_list[z];
  85. //tweight += weight_list[z];
  86. printf("\n\n%d",age_list[z]);
  87. }
  88. avg_age = tage/100;
  89. printf("\nage AVG %.2f", avg_age);
  90. sumofarray(age_list,100);
  91. printf("\n----------------------\n");
  92. for(int d=0;d<=100;d++){
  93. weight_list[d] = weight_list[d+1];
  94. if(weight_list[100]==57)
  95. weight_list[100]=87;
  96. //weight_list[j] = weight_list[j+1];
  97. }
  98. for(int y=0;y<100;y++){
  99. //tage += age_list[y];
  100. tweight += weight_list[y];
  101. printf("\n\n%d",weight_list[y]);
  102. }
  103. avg_weight = tweight/100;
  104. printf("\nWeight AVG %.2f", avg_weight);
  105. sumofarray(weight_list,100);
  106. printf("\n----------------------\n");
  107.  
  108. //printf("\nmin Age %.2f",minimum);
  109. fclose(fp);
  110. return 0;
  111. }
  112.  
Add Comment
Please, Sign In to add comment