Advertisement
Guest User

Untitled

a guest
May 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #define max 100
  3. int main()
  4. {
  5. int tab[max];
  6. int n;
  7. int i;
  8. int j;
  9.  
  10. printf("Program wczytuje n liczb calkowitych i sprawdza, czy \n");
  11. printf("posrod nich znajduje sie para jednakowych.\n");
  12. printf("Liczbe n podaje uzytkownik.\n");
  13. printf("Mozna zalozyc, ze n nie moze byc wikesze od 100.\n");
  14. printf("Autor programu: Marcin Wojcik\n\n");
  15. printf("Ile liczb calkowitych ma wylosowac program? ");
  16. while(scanf("%d",&n)!=1 || n<=0 || n>max || getchar()!='\n')
  17. {
  18. printf("Podano bledne dane, prosze sprobowac ponownie.\n");
  19. printf("Pamietaj, ze mozesz losowac maksymalnie 100 liczb.\n");
  20. while(getchar()!='\n')
  21. ;
  22. }
  23. for(i=0;i<n;i++)
  24. {
  25. printf("Podaj wartosc %d elementu:",i+1);
  26. while(scanf("%d",&tab[i])!=1 || getchar()!='\n')
  27. {
  28. printf("Podano bledne dane, prosze sprobowac ponownie.\n");
  29. while(getchar()!='\n')
  30. ;
  31. }
  32. }
  33. printf("\n");
  34. for(i=0;i<n-1;i++)
  35. {
  36. for(j=i+1;j<n;j++)
  37. {
  38. if(tab[i]==tab[j])
  39. printf("Wystepuje para jednakowych liczb o wartosci %d\n",tab[j]);
  40. else
  41. ;
  42. }
  43. }
  44. printf("\nKoniec programu.\n\n");
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement