1:
cpp
#include <stdio.h>
int main(void)
{
int i;
char number[26];
char c = 'a';
for ( i = 0; i < 26; i++, c++)
{
number[i] = c;
}
for (i = 0; i < 26; i++)
{
printf("%c", number[i]);
}
return 0;
}
2:
cpp
#include <stdio.h>
int main(void)
{
for (int i = 1; i < 6; i++)
{
for (int a = 0; a <i ; a++)
{
printf("$");
}
printf("\n");
}
return 0;
}
3:
cpp
#include <stdio.h>
int main(void)
{
int j, i;
char c;
for (int i = 0; i <= 6; i++)
{
for (j = 0,c = 'F';j<i;j++,c--)
{
printf("%c", c);
}
printf("\n");
}
return 0;
}
4:
cpp
#include <stdio.h>
int main(void)
{
int i, j;
char c = 'A';//要使字母不重复,即不要让A在循环中;
for (i = 1; i <= 6; i++)
{
for ( j = 0; j < i; j++, c++)
{
printf("%c", c);
}
printf("\n");
}
return 0;
}
5:
cpp
#include <stdio.h>
int main(void)
{
int i, j,k;
char c;
for ( i = 0; i < 5 ; i++)
{
for (j = 5; j > i; j--)
{
printf(" ");
}
for (c = 'A', k = 0; k <= i; c++,k++)
{
printf("%c", c);
}
for (k = i - 1, c = 'A' + k; k >= 0; k--, c--)
{
printf("%c", c);
}
printf("\n");
}
return 0;
}
6:
cpp
int main(void)
{
double YUAN = 1000000.0; // 初始存款100万美元
double LILV = 0.08; // 年利率8%
double TEN = 100000.0; // 每年取款10万美元
int years = 0;
do
{
YUAN = YUAN + YUAN * LILV;
YUAN -= TEN;
years++;
} while (YUAN > 9);
printf("%d年后取完", years);
return 0;
}