+ 2

I want to find the unique numbers of particular arry and this is my attempt it doesnt give the correct output?

#include<stdio.h> int main() { int n,i,j,count=0,dup; printf("enter how many numbers you wish to add:\n"); scanf("%d",&n); int x[n]; for(i=0;i<n;i++) { printf("enter no %d:\n",i+1); scanf("%d",&x[n]); } int y[n]; printf("Unique numbers are:\n"); for(i=0;i<n;i++) { for(j=0;j<count;j++) { if(y[j]==x[i]) {dup=1; break; } } if(dup==0) { printf("%d",x[i]); y[count]=x[i]; count++; } } }

14th Aug 2020, 5:30 AM
narthana wickramasinghe
narthana wickramasinghe - avatar
3 Respostas
+ 2
You can"t define arrays at runtime: Replace n with a constant in: int x[n] and int y[n]
14th Aug 2020, 6:43 AM
unChabon
unChabon - avatar
+ 1
Thank you both of you
14th Aug 2020, 7:46 AM
narthana wickramasinghe
narthana wickramasinghe - avatar