-
#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 1527
#include<iostre am.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();
-
}
-
sicarie 4,677
Recognized Expert Moderator Specialist
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.
sicarie 4,677
Recognized Expert Moderator Specialist
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.
JosAH 11,448
Recognized Expert MVP
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! ;)
sicarie 4,677
Recognized Expert Moderator Specialist
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
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 started sending out the content of the page.
Web content is always delivered with a few headers at the top, ending with a
blank line. For example, a web page might start like this:
|
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 nothing in IE.
I'd be greatful for any assistance. Also, if I will have problems the
code on Opera or Safari, I'd appreciate any pointers--I don't have a
Mac to test Safari.
THanks very much,
Michael
|
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 DeviceCapabilities(
string device,
string port,
Int16 capability,
out IntPtr outputBuffer,
|
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) into my Microsoft VC++ .NET
2002 - Windows XP Pro PC:
//----cppdll.cpp----
#include "cppdll.h"
//prevent function name from being mangled
|
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">
<input type="hidden" name="thisPage" value="pispCheckDomain">
<input type="hidden" name="username" value="test">
<input type="hidden" name="password" value="test">
domain_name: <input type="text" name="domain_name"><br>
| |
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, it always waits
for the process to terminate and then return the output all at once.
Can someone please show me some code that actually works for this sort
of thing? It doesn't even have to use the subprocess module. Don't
worry if the code...
|
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 on dynamic SQL to export a series of table/views to CSV format, then zip the files up, then it creates an series of ftp commands to put the newly created zip file onto the relevent ftp server. The list of files and destination server are held in a...
|
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;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
|
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 column 'EmployeeID', table 'Accomplishments.dbo.Accomplishment'; column does not allow nulls. INSERT fails. The statement has been terminated.
and my code is this
using System;
using System.Collections;
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |