You are on page 1of 2

IMPLEMENTATION OF RANDOMIZED ALGORITHM

PROGRAM: #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<time.h> int main() { int a[10]={10,20,30,40,11,12,13,10,30,30}; int n=10; void repetation(int q[],int n); clrscr(); printf("\n\tProgram Files the repeated element"); repetation(a,n); getch(); return 0; } void repetation(int a[],int n) { int i,j,count,t; time_t; srand((unsigned)time(&t)); count=1; while(count<100) { i=rand()%(n+1); j=rand()%(n+1); if((i!=j)&&(a[i]==a[j])) { printf("\nRepeated Element is present at Index %d",i); } count++; } }

OUTPUT: Program Files the repeated element Repeated Element is present at Index 0 Repeated Element is present at Index 8 Repeated Element is present at Index 0 Repeated Element is present at Index 2 Repeated Element is present at Index 7 Repeated Element is present at Index 9 Repeated Element is present at Index 9 Repeated Element is present at Index 2

You might also like