424,984 Members | 1,086 Online Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

not getting the required output

 P: 6 Expand|Select|Wrap|Line Numbers #include #include   void main() {    int a,b,i,j,k=0,fg=0;    for(i=0;i<5;i++)    {       cout<<"enter no.";       cin>>a[i];}       for(i=0;i<5;i++)       {          for(j=0;j<5;j++)          {             if(a[i]==a[j]&& i!=j)             {                fg=1;                break;             }          }          if(fg==0)          {             b[k]=a[i];             k++;          }       }       for(i=0;i
10 Replies

 Expert 100+ P: 844 #include #include void main() {int a,b,i,j,k=0,fg=0; for(i=0;i<5;i++) {cout<<"enter no."; cin>>a[i];} for(i=0;i<5;i++) {for(j=0;j<5;j++) {if(a[i]==a[j]&& i!=j) { fg=1; break;}} if(fg==0) {b[k]=a[i]; k++;}} for(i=0;i #include   void main() {     int a,b,i,j,k=0,fg=0;     for(i=0;i<5;i++)     {         cout<<"enter no.";         cin>>a[i];     }     for(i=0;i<5;i++)     {         for(j=0;j<5;j++)         {             if(a[i]==a[j]&& i!=j)             {                 fg=1;                 break;             }         }         if(fg==0)         {             b[k]=a[i];             k++;         }     }     for(i=0;i

 Expert Mod 2.5K+ P: 4,677 The first thing I saw is a pile of meesy code. Please indent and use code tags: Expand|Select|Wrap|Line Numbers #include #include   void main() {     int a,b,i,j,k=0,fg=0;     for(i=0;i<5;i++)     {         cout<<"enter no.";         cin>>a[i];     }     for(i=0;i<5;i++)     {         for(j=0;j<5;j++)         {             if(a[i]==a[j]&& i!=j)             {                 fg=1;                 break;             }         }         if(fg==0)         {             b[k]=a[i];             k++;         }     }     for(i=0;i

 Expert Mod 2.5K+ P: 4,677 hpbrothers- You've already been asked by a Mod to use code tags, and now yo uhave by an Expert. I'm making it an official warning - read and follow the Posting Guidelines. If you want to post, you have to play by the rules. Aug 15 '07 #4

 Expert 100+ P: 844 ilikepython- Did you add a brace in there? I'm missing one, but I might have deleted it when I was trying to figure out the mess of code he made. I don't think so, but I definately might have. Aug 15 '07 #5

 Expert 10K+ P: 11,448 Shouldn't that variable 'fg' be reset every time the inner loop is started; e.g. insert 'fg= 0;' at line 14 of the code above. kind regards, Jos Aug 15 '07 #6

 Expert 100+ P: 844 Expand|Select|Wrap|Line Numbers #include #include   void main() {    int a,b,i,j,k=0,fg=0;    for(i=0;i<5;i++)    {       cout<<"enter no.";       cin>>a[i];}       for(i=0;i<5;i++)       {          for(j=0;j<5;j++)          {             if(a[i]==a[j]&& i!=j)             {                fg=1;                break;             }          }          if(fg==0)          {             b[k]=a[i];             k++;          }       }       for(i=0;i

 Expert 100+ P: 844 Shouldn't that variable 'fg' be reset every time the inner loop is started; e.g. insert 'fg= 0;' at line 14 of the code above. kind regards, Jos Jos you beat me to it! ;) Aug 15 '07 #8

 Expert Mod 2.5K+ P: 4,677 I don't think so, but I definately might have. Nope, I missed one. Sorry! Aug 15 '07 #9

 P: 6 You never set fg back to 0 when you set it to 1. The program works for me if I add fg = 0; after the first loop: Expand|Select|Wrap|Line Numbers     for(i=0;i<5;i++)     {         fg = 0;         for(j=0;j<5;j++)         {             if(a[i]==a[j]&& i!=j)             {                fg=1;                break;             }          }          if(fg==0)          {             b[k]=a[i];             k++;          }       }   thanks it is now working for me also Aug 15 '07 #10

 Expert 10K+ P: 11,448 Jos you beat me to it! ;) Man, ain't I fast today ;-) kind regards, Jos Aug 15 '07 #11 