Click here to Skip to main content
15,938,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
1   2   3   4   5
1   4   9   16  25
1   3   5   7   9
9   7   5   3   1

i have done 1st three rows.but not able to display the 4th(9,7,5,3,1)row.i know the method...any one help??
C#
if(!IsPostBack)
        {
            DataTable dt=new DataTable();
            DataRow dr;
            dt.Columns.Add(new DataColumn("Numbers",typeof(Int32)));
            dt.Columns.Add(new DataColumn("Squares", typeof(Int32)));
            dt.Columns.Add(new DataColumn("Odd", typeof(Int32)));
            dt.Columns.Add(new DataColumn("OddReverse", typeof(Int32)));
            for(int i=0;i<=5;i++)
            {
                dr=dt.NewRow();
                dr[0]=i;
                dr[1] = Square(i);
                dr[2] = Odd(i);
                dr[3] = OddReverse(i);
                dt.Rows.Add(dr);
            }
            dlMyList.DataSource=dt;
            dlMyList.DataBind();
        }
    }

    int Square(int num)
    {
        int ans = num * num;
        return ans;
    }
    int Odd(int num)
    {
        int ans = num * 2-1;
        return ans;
    }
    int OddReverse(int num)
    {
for(num=5;num>=1;num--)

        int ans = num *2-1;
        return ans;
    }

this is the code..where should i place for loop??fr oddreverse?
Posted
Updated 5-Dec-11 23:25pm
v4
Comments
OriginalGriff 6-Dec-11 4:49am    
If I understood what your problem was, possibly.
As it is, I don't know what you are trying to do, or with what, or what is going wrong.
Edit your question, and provide a better example (before, after as it should be, after as it is) and a relevent code fragment.
Use the "Improve question" widget to edit your question and provide better information.
ythisbug 6-Dec-11 4:52am    
if(!IsPostBack)
{
DataTable dt=new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("Numbers",typeof(Int32)));
dt.Columns.Add(new DataColumn("Squares", typeof(Int32)));
dt.Columns.Add(new DataColumn("Odd", typeof(Int32)));
dt.Columns.Add(new DataColumn("OddReverse", typeof(Int32)));
for(int i=0;i<=5;i++)
{
dr=dt.NewRow();
dr[0]=i;
dr[1] = Square(i);
dr[2] = Odd(i);
dr[3] = OddReverse(i);
dt.Rows.Add(dr);
}
dlMyList.DataSource=dt;
dlMyList.DataBind();
}
}

int Square(int num)
{
int ans = num * num;
return ans;
}
int Odd(int num)
{
int ans = num * 2-1;
return ans;
}
int OddReverse(int num)
{
int ans = num *2-1;
return ans;
}
this is the code..but i unable to display reverse of odd number..where should i place the for loop for odd reverse m nt able to get it..
OriginalGriff 6-Dec-11 5:07am    
Put that in your question - along with the other info.

1 solution

use
C#
int OddReverse(int num)
{
   int ans = (6-num) *2-1;
   return ans;
}



BTW the main (and unique ) loop should be:
C#
for(int i=1; i<=5; i++)
 
Share this answer
 
Comments
Wendelius 6-Dec-11 5:47am    
Excellent, my 5
CPallini 6-Dec-11 6:03am    
Thank you.
ythisbug 6-Dec-11 6:16am    
thanks
CPallini 6-Dec-11 6:18am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900