+ 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++; } } }
3 Réponses
+ 2
You can"t define arrays at runtime:
Replace n with a constant in:
int x[n]
and
int y[n]
+ 1
Thank you both of you