Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int data[]={7,1,7,4,3,7,5,5,1,7};
- int totaldata=10;
- void showData(){
- for(int i=0; i<totaldata; i++){
- printf("%d ", data[i]);
- }
- printf("\n");
- }
- int totalMuncul(int angka){
- int total=0;
- for(int i=0; i<totaldata; i++){
- if(data[i]==angka){
- total++;
- }
- }
- return total;
- }
- int checkSudahMuncul(int posisi){
- //kita cek apakah int angka sudah pernah muncul sebelumnya
- for(int i=posisi-1; i>=0; i--){
- if(data[posisi]==data[i]){
- return 1;
- }
- }
- return 0;
- }
- void main(){
- showData();
- for(int i=0; i<totaldata; i++){
- if(checkSudahMuncul(i)==0){ //false
- printf("Number %d was found %d times.\n", data[i], totalMuncul(data[i]));
- }
- }
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment