heryvandoro

Untitled

Dec 24th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int data[]={7,1,7,4,3,7,5,5,1,7};
  4. int totaldata=10;
  5.  
  6. void showData(){
  7. for(int i=0; i<totaldata; i++){
  8. printf("%d ", data[i]);
  9. }
  10. printf("\n");
  11. }
  12.  
  13. int totalMuncul(int angka){
  14. int total=0;
  15. for(int i=0; i<totaldata; i++){
  16. if(data[i]==angka){
  17. total++;
  18. }
  19. }
  20. return total;
  21. }
  22.  
  23. int checkSudahMuncul(int posisi){
  24. //kita cek apakah int angka sudah pernah muncul sebelumnya
  25. for(int i=posisi-1; i>=0; i--){
  26. if(data[posisi]==data[i]){
  27. return 1;
  28. }
  29. }
  30. return 0;
  31. }
  32.  
  33. void main(){
  34. showData();
  35. for(int i=0; i<totaldata; i++){
  36. if(checkSudahMuncul(i)==0){ //false
  37. printf("Number %d was found %d times.\n", data[i], totalMuncul(data[i]));
  38. }
  39. }
  40. getchar();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment