>whole program is correct but at end it is not displaying correct result.
Then the whole program is not correct. :rolleyes:
>#include<stdio.h>
This isn't needed.
>main()
This is illegal C++. Implicit int is not allowed, so you need to say:
>for(int i=0;i<10;i++)
This is not portable because you access i after the loop. i should be declared outside of the loop to be correct.
Compare this with what you have:
#include<iostream>
using namespace std;
int main()
{
int nTmp,i,j;
bool bFlag=false;
int a[10];
cout<<"entr 10 numbers b/w 20 and 100"<<endl;
for(i=0;i<10;i++)
{
while(!bFlag)
{
cout<<"Enter Value"<<endl;
cin>>nTmp;
////Here we check first Condition
// no between 20 and 100
while((nTmp<20)||(nTmp>100))
{
cout<<"enter no b/w 20 and 100"<<endl;
cin>>nTmp;
}
for(j=0;j<i;j++)
{
if(a[j]==nTmp)
{
cout<<nTmp<<" already exists"<<endl;
break;
}
}
if(j==i)
{
//save variable
a[i]=nTmp;
bFlag=true;
}
}
//again make it false
bFlag=false;
}
cout<<" the non dublicate nos are "<<endl;
for(i=0;i<10;i++)
cout<<a[i]<<endl;
}
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Offline 11,807 posts
since Sep 2004