Use one dimensional array to solve the following problem. Read 20 integers from data file, each of which is between 10 and 100, inclusive. As each number is read, print it only if it is not a duplicate of a number already read. Provide for the Worst case in which all 20 integers are different. Use the smallest possible array To solve this problem



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int arr[20];
for (int i=0;i<20;i++)
                {
                cout<<"enter the element no "<<i+1<<endl;
                cin>>arr[i];
                }

for (i=0;i<20;i++)
                {
                for (int j=0;j<20;j++)
                                {
                                if (i!=j)
                                {
                                                if (arr[i]==arr[j])
                                                arr[j]=0;
                                                else
                                                continue;
                                }
                                else
                                continue;
                                }
                }

for (i=0;i<20;i++)
                {
                if (arr[i]<=100&&arr[i]>=10)
                cout<<arr[i]<<endl;
                else
                continue;
                }

getch();
}



OUTPUT:

 enter the element no 1
1
enter the element no 2
11
enter the element no 3                                                         
12                                                                             
enter the element no 4                                                         
113
enter the element no 5                                                         
14                                                                             
enter the element no 6                                                          
15                                                                             
enter the element no 7                                                         
16                                                                              
enter the element no 8                                                         
17                                                                             
enter the element no 9                                                          
18                                                                             
enter the element no 10                                                        
19                                                                              
enter the element no 11                                                        
10                                                                             
enter the element no 12                                                        
11                                                                             
enter the element no 13                                                        
12                                                                             
enter the element no 14                                                        
13                                                                             
enter the element no 15                                                        
14                                                                              
enter the element no 16                                                        
15                                                                             
enter the element no 17                                                         
16                                                                             
enter the element no 18                                                        
17                                                                              
enter the element no 19                                                        
23                                                                             
enter the element no 20                                                         


34                                                                             
11                                                                             
12                                                                              
14                                                                             
15                                                                             
16                                                                             
17                                                                              
18                                                                             
19                                                                             
10                                                                              
13                                                                             
23                                                                             
34            

No comments:

Post a Comment