编写一个C程序,使用for循环以正弦波模式打印数字的平方。
#include <stdio.h>
int main()
{
int rows;
printf("Enter Square Numbers in Sine Wave Pat Side = ");
scanf("%d", &rows);
printf("The Square of Numbers in Sine Wave Pattern\n");
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < rows; j++)
{
if (j % 2 == 0)
{
printf("%d ", (rows * j) + i + 1);
}
else
{
printf("%d ", (rows * (j + 1)) - i);
}
}
printf("\n");
}
}

此C程序使用while循环以正弦波格式打印数字的平方模式。
#include <stdio.h>
int main()
{
int rows, i, j;
printf("Enter Square Numbers in Sine Wave Pat Side = ");
scanf("%d", &rows);
printf("The Square of Numbers in Sine Wave Pattern\n");
i = 0;
while (i < rows)
{
j = 0;
while (j < rows)
{
if (j % 2 == 0)
{
printf("%d ", (rows * j) + i + 1);
}
else
{
printf("%d ", (rows * (j + 1)) - i);
}
j++;
}
printf("\n");
i++;
}
}
Enter Square Numbers in Sine Wave Pat Side = 9
The Square of Numbers in Sine Wave Pattern
1 18 19 36 37 54 55 72 73
2 17 20 35 38 53 56 71 74
3 16 21 34 39 52 57 70 75
4 15 22 33 40 51 58 69 76
5 14 23 32 41 50 59 68 77
6 13 24 31 42 49 60 67 78
7 12 25 30 43 48 61 66 79
8 11 26 29 44 47 62 65 80
9 10 27 28 45 46 63 64 81