i want to know how to copy arrary without using any method
or function. I have tried the below
using System;
class e4
{
static void Main(string[] args)
{
int a,b;
int[ ] m= new int[5];
int[ ] n= new int[5];
for(a=0;a<=4;a++)
{
Console.WriteLine("enter any value");
m[a]=Convert.ToInt32(Console.ReadLine());
m[a]=n[a];
}
for(b=0;b<=4;b++)
{
Console.WriteLine(n[b]);
}
}
}
but it will give wrong result can anyone solve this problem
Answer Posted / jeremiah
It appears you are overwriting the value of m[a] with the
uninitialized version of n[a] (in .NET this will be
initialized to 0. So the output of your program will output
5 zeros instead of what you had input on the console.
Try changing your code to this (I formatted it slightly better):
-----------------------------------------------------------
using System;
class e4
{
static void Main(string[] args)
{
int a, b;
int[ ] m = new int[5];
int[ ] n = new int[5];
for( a = 0; a <= 4; a++ )
{
Console.WriteLine( "enter any value" );
m[a]=Convert.ToInt32( Console.ReadLine() );
// Don't overwrite m[a] here!
// m[a]=n[a];
n[a] = m[a];
}
for( b = 0; b <= 4; b++ )
{
Console.WriteLine( n[b] );
}
}
}
-----------------------------------------------------------
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is difference between class and function?
Does c++ vector allocate memory?
What is buffer and example?
How the endl and setw manipulator works?
In which situation the program terminates before reaching the breakpoint set by the user at the beginning of the mainq method?
What are arithmetic operators?
What's the hardest coding language?
How can we read/write Structures from/to data files?
What is #include cstdlib in c++?
What happens when you make call 'delete this;'?
What is null c++?
Explain the isa and hasa class relationships.
Is java the same as c++?
What is a vector c++?
What is abstract class in c++?