如何在数据列表中打印奇数的反向? [英] how to print reverse of odd numbers in a DataList?

查看:45
本文介绍了如何在数据列表中打印奇数的反向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1   2   3   4   5
1   4   9   16  25
1   3   5   7   9
9   7   5   3   1


我已经完成了第一三排.但是无法显示第四(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??

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;
    }


这是代码..我应该在哪里放置循环?fr oddreverse?


this is the code..where should i place for loop??fr oddreverse?

推荐答案

使用
int OddReverse(int num)
{
   int ans = (6-num) *2-1;
   return ans;
}




顺便说一句,主(和唯一)循环应为:




BTW the main (and unique ) loop should be:

for(int i=1; i<=5; i++)


这篇关于如何在数据列表中打印奇数的反向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆