/*
问题:金字塔图案,学习使用for 循环
时间:2016/4/6
*/
#include <stdio.h>
int main(void)
{
for (int i = 0; i < 5; i++)
{
char ch = 'A';
for (int j = 4-i; j >=0; j--)
printf(" ");
for (int x = 0; x <= i; x++, ch++)
printf("%c",ch);
ch = 'A' + i-1;
for (int y = 0; y < i; y++, ch--)
printf("%c", ch);
printf("\n");
}
return 0;
}
/*
问题:学习使用strlen()
时间:2016/4/6
*/
#include <stdio.h>
#include <string.h>
int main(void)
{
char word[20];
printf("please input a word: ");
scanf_s("%s", word);
//gets_s(word, 20);
printf("%s\n", word);
for (int i = strlen(word)-1; i >= 0; i--)
printf("%c", word[i]);
printf("\n");
return 0;
}
/*
问题:学习使用 for,九九乘法表
时间:2016/4/7
*/
#include <stdio.h>
int main(void)
{
for (int i = 1; i < 10; i++)
{
for (int j = 1; j <= i; j++)
printf("%d*%d=%2d ", j, i, j*i);
printf("\n");
}
return 0;
}
/*
问题:累计
时间:2016/4/10
*/
#include <stdio.h>
int main(void)
{
double num1[8], num2[8];
for (int i = 0; i < 8; i++)
scanf_s("%lf", &num1[i]);
/*for (int j = 0; j < 8; j++)
{
num2[j] = 0;
for (int t = 0; t <= j; t++)
num2[j] += num1[t];
}*/
num2[0] = num1[0];
for (int j = 1; j < 8; j++)
num2[j] = num2[j - 1] + num1[j];
for (int m = 0; m < 8; m++)
printf("%8.3f", num1[m]);
printf("\n");
for (int n = 0; n < 8; n++)
printf("%8.3f", num2[n]);
printf("\n");
return 0;
}