Posted by Naga116 under C# on 8/23/2011 | Points: 10 | Views : 1055 | Status : [Member] | Replies : 2
Aim is to print odd and even numbers and Odd number which ends with 3
even numbers: 2,4,6,8,10...
like: 3,13,....

I am getting System out of memory exception..

protected void Page_Load(object sender, EventArgs e)
{
int evensum = 0;
int oddsum = 0;

int a = 10;
int j = 10;

for(int i=1; i<=a;i++)
{
if (i % 2 == 0)
{
Response.Write("Even number" + i+"</br>");
evensum = evensum + i;
}
else
{
while (i <= 10)
{
Response.Write("Odd Number" + i*3 + "</br>");
}

oddsum = oddsum + j;

}
}
Response.Write("Even sum" + evensum + "Odd sum" + oddsum);
}
}

Nagaraju

Responses

Posted by: Harikatakam on: 8/23/2011 [Member] Starter | Points: 25
 0 Dera Naga Hope below code will help you int evensum = 0; int oddsum = 0; int sumof3s=0; ArrayList arryof3s=new ArrayList(); ArrayList arryofevens = new ArrayList(); ArrayList arryofOdds = new ArrayList(); int a = 50; int j = 10; for (int i = 1; i <= a; i++) { if (i % 2 == 0) { evensum = evensum + i; arryofevens.Add(i); } else { string temp = i.ToString(); if (temp.EndsWith("3")) { sumof3s += i; arryof3s.Add(i); } else { oddsum += i; arryofOdds.Add(i); } oddsum = oddsum + j; } } for(int i=0;i
Posted by: Ndebata on: 8/23/2011 [Member] Starter | Points: 25
 0 ```int MaxBound = 20; var evens = Enumerable.Range(1, MaxBound).Where(a => a % 2 == 0).ToArray(); foreach (var item in evens) { Console.Write(item + " "); } Console.WriteLine(); var numendswith3 = Enumerable.Range(1, MaxBound).Where(a => a % 10 == 3).ToArray(); foreach (var item in numendswith3) { Console.Write(item + " "); }``` Naga116, if this helps please login to Mark As Answer. | Alert Moderator
Latest Posts