#include
void main()
{
int i, j;
for (i = 1; i <= 9; i++)// i控制行数
{
for (j = 1; j <= i; j++)// j控制列数,条件j<=i控制第i行的输出列数小于等于i
{
printf("%d*%d=%2d ", j, i, j*i);
if (i == j)// 判定换行的条件
printf("\n");
}
}
system("pause");
return ;
}
求出斐波那契数列前20项中的偶数项的和。提示:前两项为:0,1,从第3项开始,每一项均为其前两项的和(即:0+1+1+2+3+5+…)
#include
int main()
{
int numA = 0, numB = 0, temp = 0, sum = 0;
for (int i = 1; i <= 20; i++) {
if (i == 1 || i == 2) {
numA = 0;
numB = 1;
temp = i - 1;
}
else {
temp = numA + numB;
numA = numB;
numB = temp;
}
if (temp % 2 == 0) {
sum += temp;
}
}
printf("%d", sum);
printf("\n");
system("pause");
return 0;
}
#include
#include
#define N 20
int main()
{
int A[N];
int i, count = 0, sumE = 0, sumO = 0;
srand(time(NULL));
for (i = 0; i<N; i++)
{
A[i] = rand() % 90 + 10;
printf("第%d个数:%d\n", i + 1, A[i]);
}
for (i = 0; i < N; i++)
{
if (A[i] % 2 == 0) {
count++;
printf("第%d个偶数:%d\n", count, A[i]);
sumE += A[i];
}
}
count = 0;
for (i = 0; i < N; i++)
{
if (A[i] % 2 != 0) {
count++;
printf("第%d个奇数:%d\n", count, A[i]);
sumO += A[i];
}
}
printf("所有偶数之和为:%d\n", sumE);
printf("所有奇数之和为:%d\n", sumO);
system("pause");
return 0;
}
#include
int main() {
double c = 0, f;
scanf("%lf", &f);
c = 5.0*(f - 32) / 9.0;
printf("在此华氏温度下的摄氏温度是c=%.2lf\n", c);
system("pause");
return 0;
}
#include
int main() {
int sum = 0;
double mean = 0;
int A[4][4] = { { 1,2,3,4 },{ 5,6,7,8 },{ 9,10,11,12 } ,{ 13,14,15,16 } };
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
sum += A[i][j];
printf("%d\n", (A[i][j]));
}
}
mean = ((double)sum) / 16;
printf("16个元素的平均数为:%.2lf\n",mean);
system("pause");
return 0;
}
#include
main()
{
int i;
char s[1000];
gets(s);
for (i = strlen(s) - 1; i >= 0; i--) {
printf("%c", s[i]);
}
system("pause");
}
#include
main()
{
int A[3][3]={ { 1,2,3 },{ 4,5,6 },{ 7,8,9 } };
int temp = 0;
for (int i = 0; i < 2; i++) {
if (A[i][0] <= A[i+1][0]) {
temp = A[i][0];
A[0][i] = A[i+1][0];
A[i+1][0] = temp;
}
else {
temp = A[i+1][0];
}
}
printf("%d\n",temp);
system("pause");
}
#include
main()
{
int sum = 0;
for (int i = 0; i <= 1000; i++) {
if (i % 2 == 0) {
sum += i;
}
}
printf("%d\n",sum);
system("pause");
}