Advertisement
Kocyk

nazwy towarów w C

Nov 29th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. char nazwy[50][20];
  9. float ceny[50];
  10.  
  11. int j=0;
  12. int k=0;
  13. int i=0;
  14. int n=0;
  15. int m=0;
  16. do
  17. {
  18. fflush(stdin);
  19. printf("Podaj towar nr %d\n", i+1);
  20. scanf("%s", &nazwy[i]);
  21. printf("A teraz jego cene\n");
  22. scanf("%f", &ceny[i]);
  23. // printf("%s",nazwy[i]);
  24. i++;
  25. }while(strcmp("stop",nazwy[i-1]));
  26. float maxcena;
  27. maxcena=0;
  28. char nazwynowe[i][20];
  29. for(j;j<i;j++)
  30. {
  31. if(maxcena<ceny[j])maxcena=ceny[j];
  32. }
  33. j=0;
  34. for(j;j<i-1;j++)
  35. {
  36. if(ceny[j]>maxcena/2)
  37. {
  38. strcpy(nazwynowe[k],nazwy[j]);
  39. n++;
  40. k++;
  41. }
  42. }
  43. printf("Towary z cena wieksza od max/2: \n");
  44. for(m;m<n;m++)
  45. {
  46. printf("%s\n",nazwynowe[m]);
  47. }
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement