-
#include<iostream.h>
-
#include<conio.h>
-
-
void main()
-
{
-
int a[10],b[10],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<k;i++)
-
cout<<b[i];
-
getch();
-
}
-
this is the program to remove duplicate values from an array.
if my input is 2,2,3,4,5
then i should get output 3,4,5
but i am getting garbage value
but if i put my input 1,2,3,3,4
then i get the output 1,2,4 which is right
why i am not getting the output in first case.please if the program is wrong then let me know the right program
10 1489
#include<iostream.h>
#include<conio.h>
void main()
{int a[10],b[10],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<k;i++)
cout<<b[i];
getch();}
this is the program to remove duplicate values from an array.
if my input is 2,2,3,4,5
then i should get output 3,4,5
but i am getting garbage value
but if i put my input 1,2,3,3,4
then i get the output 1,2,4 which is right
why i am not getting the output in first case.please if the program is wrong then let me know the right program
The first thing I saw is a pile of meesy code. Please indent and use code tags: -
#include<iostream.h>
-
#include<conio.h>
-
-
void main()
-
{
-
int a[10],b[10],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<k;i++)
-
cout<<b[i];
-
getch();
-
}
-
The first thing I saw is a pile of meesy code. Please indent and use code tags: -
#include<iostream.h>
-
#include<conio.h>
-
-
void main()
-
{
-
int a[10],b[10],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<k;i++)
-
cout<<b[i];
-
getch();
-
}
-
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.
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.
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.
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
-
#include<iostream.h>
-
#include<conio.h>
-
-
void main()
-
{
-
int a[10],b[10],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<k;i++)
-
cout<<b[i];
-
getch();
-
}
-
this is the program to remove duplicate values from an array.
if my input is 2,2,3,4,5
then i should get output 3,4,5
but i am getting garbage value
but if i put my input 1,2,3,3,4
then i get the output 1,2,4 which is right
why i am not getting the output in first case.please if the program is wrong then let me know the right program
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: -
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++;
-
}
-
}
-
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! ;)
I don't think so, but I definately might have.
Nope, I missed one. Sorry!
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: -
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
Jos you beat me to it! ;)
Man, ain't I fast today ;-)
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Philip Ronan |
last post by:
OK, here's my 2p worth:
===
Q. Why am I getting the error message 'Headers already sent'?
A. PHP produces this error message when you try to set a header for a web
page after you have already...
|
by: Michael Bierman |
last post by:
Please forgive the simplicy of this question. I have the following code
which attempts to determine the color of some text and set other text
to match that color. It works fine in Firefox, but does...
|
by: Bruce Wood |
last post by:
I'm having a devil of a time calling DeviceCapabilities() in order to
get the list of paper names / codes / sizes for a printer. Here is my
code and the input it produces:
static extern Int32...
|
by: Scott Chang |
last post by:
Hi all,
I copied a set of VC++ version 6 source code of
the 'cppdll'(2 projects) from a website and put the
cppdll.cpp, cppdll.def, cpp.h, (as the 1st project) and
test.cpp (as the 2nd project)...
|
by: Peter Afonin |
last post by:
Hello,
I have a simple client-side form that is checking the domain availability on
the domain registrar's server:
<FORM action="https://www.webnames.ru/scripts/RegTimeSRS.pl" method="post">...
|
by: cypher543 |
last post by:
This has been driving me insane for the last hour or so. I have search
everywhere, and nothing works. I am trying to use the subprocess module
to run a program and get its output line by line. But,...
|
by: leescriven |
last post by:
Hi,
Thi is my first post on this forum, and I'm hoping that there is a guru out there who can help me with an annoying problem I am having.
I have written a Stored Procedure that relies heavily...
|
by: preeti13 |
last post by:
Hi friends i have a probelm i am try to pass the value to the employeeid parameter but getting th error please help me how i can do this i am getting the error here is my code
using System;...
|
by: preeti13 |
last post by:
Hi guys i am here with my another probelm please help me.trying insert the value into the data base but getting the null value error .I am getting thsi error
Cannot insert the value NULL into...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |