I want an output :
92
95
97
98
99
Here is my code, please help :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int[] Arr = new int[5] { 99, 98, 92, 97, 95 };
//int[] Arr = { 90, 67, 87, 2, 5 };
int a, b,i;
int kw;
for (i = 0; i < 5; i++)
{
if (Arr[i] > Arr[i + 1])
{
int sw;
sw = Arr[i + 1];
Arr[i + 1] = Arr[i];
Arr[i] = sw;
Console.WriteLine(sw);
}
Console.WriteLine(sw);
// Console.WriteLine(" Sorted Array is : ", sw);
}
Console.ReadLine();
}
}
}
Shweta LodhaPosted Feb 6, 2014, 3:24 PM
1) variable sw if declared inside an IF condition and you are trying to print that variable sw outside IF, which is out of scope.
2) You just declared the variable sw and didn't assigned anything.
So, to resolve the error please declare your variable sw outside IF condition and assign some default value
ashutosh bhardwajPosted Feb 6, 2014, 10:45 AM