Guest User

lab8zad3

a guest
Jan 15th, 2020
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4.  
  5. int main(){
  6. int n,k,count=0,temp;
  7. printf("Podaj ilosc elementow tablicy: ");
  8. scanf("%d", &n);
  9. int tablica[n];
  10. for(int i=0; i<n; i++){
  11. do{
  12. printf("Podaj %d element tablicy: ", i);
  13. k=scanf("%d", &tablica[i]);
  14. if(k==0) printf("blad formatu");
  15. fflush(stdin);
  16. }while(k==0);
  17. }
  18. printf("Twoja tablica: ");
  19. for(int i=0; i<n; i++){
  20. printf(" %d ", tablica[i]);
  21. }
  22. for(int j=0; j<n; j++){
  23.  
  24. for(int i=0; i<n; i++){
  25. if(tablica[i] > tablica[i+1]){
  26. temp = tablica[i+1];
  27. tablica[i+1] = tablica[i];
  28. tablica[i] = temp;
  29. }
  30. }
  31. }
  32. printf("\n Tablica po sortowaniu: ");
  33. for(int i=0; i<n; i++){
  34. printf(" %d ", tablica[i]);
  35. if(tablica[i] == 3) count++;
  36. }
  37.  
  38. for(int j=0; j<n-count-1; j++){
  39. for(int i=0; i<n-count-1; i++){
  40. if(tablica[i] < tablica[i+1]){
  41. temp = tablica[i+1];
  42. tablica[i+1] = tablica[i];
  43. tablica[i] = temp;
  44. }
  45. }
  46. }
  47. printf("\n Tablica po sortowaniu2: ");
  48. for(int i=0; i<n; i++){
  49. printf(" %d ", tablica[i]);
  50. }
  51.  
  52.  
  53. return 0;
  54.  
  55. }
RAW Paste Data