现在的位置: 首页 > 综合 > 正文

a expample of the c programming language.(temp)

2013年02月28日 ⁄ 综合 ⁄ 共 692字 ⁄ 字号 评论关闭

#include <stdio.h>

int main()
{
    int row_amount, column_amount;   //定义需要输出的行数和列数.
    int i, j; //定义循环变量
    int nSquare(int,int); //声明函数:返回x的y次方结果;

    //输入需要打印的行数和列数.
    printf("Please input amount of ROWS(int)    to printout:");
    scanf("%d",&row_amount);
    printf("Please input amount of COLUMNS(int) to printout:");
    scanf("%d",&column_amount);

    //输出结果:一行一行输出 ;
    for (i=1;i<=row_amount;i++)
    {
        for (j=1;j<=column_amount;j++)
            printf("%10d",nSquare(i,j));

        printf("/n");  //一行打印完毕后换行.
    }

    return 0;
}

//定义函数 nSquare();
//作用: 返回x的y次方结果;
//参数: (int)x, (int)y ;
//返回值: (int)result;
int nSquare(int x, int y)
{
    int result = 1;   //函数返回值,初始化为1.
    int i;   //循环变量

    for (i=1;i<=y;i++)
        result = result * x;
    return result;
}

 

抱歉!评论已关闭.