Answer to Question #99340 in C for Noel Suarez

Question #99340
use a one dimensional array to solve the following problem. read in 20 numbers, each of which is between 10 and 100 inclusively. as each number is read, print it only if its not a duplicate of a number already read. provide for the worst case scenario in which all 20 numbers are different . use the smallest possible array to solve this problem.
1
Expert's answer
2019-11-25T07:28:02-0500

#include<conio.h>

#include<stdio.h>

//using namespace std;

int main()


{

int a[20],i,j,k;

//clrscr();

printf("enter 20 no. between 10 to 100\n");


for(i=0;i<20;i++)

{


scanf("%d",&a[i]);



}

for(i=19;i>=0;i--)

{for(j=(i-1);j>=0;j--)

{

if(a[i]==a[j])

{

a[j]=NULL;

k=i;}

}

a[k]=NULL;

}

for(i=0;i<20;i++)

{

if(a[i]!=NULL)

{

printf("unique no %d\n",a[i]);

}}

getch();

return 0;

}



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS