1,
#include <stdio.h>
#define N 20
int main(void)
{
long a[N] = {0};
int i = 0;
a[0] = 2;
a[1] = 3;
for (i = 2; i < 10; i++)
{
a[i] = a[i-2] * a[i-1];
}
printf("符合条件的序列前十项为:\n");
printf("%u, %u, ", a[0], a[1]);
for (i = 2; i < 10; i++)
{
printf("%u, ", a[i]);
}
printf("\n");
return 0;
}
2,
#include <stdio.h>
void bubble_sort(int array[10])
{
int tmp = 0;
int i = 0, j = 0;
for (i = 9; i >= 0; i--)
{
for (j = 0; j < i; j++)
{
if (array[j] > array[j+1])
{
tmp = array[j];
array[j] = array[j+1];
array[j+1] = tmp;
}
}
}
}
int main(void)
{
int a[10] = {0};
int i = 0, j = 0;
printf("请输入10个整数:\n");
for (i = 0; i < 10; i++)
{
scanf("%d", &a[i]);
}
bubble_sort(a);
for (j = 0; j < 10; j++)
{
printf("%d, ", a[j]);
}
printf("\n");
return 0;
}
3,
#include <stdio.h>
#include <string.h>
#define STR_LEN 128
int main(void)
{
int i = 0;
int count = 0;
char str[STR_LEN] = {0};
char ToBeSearch[3] = "ab";
int StrLen = 0;
printf("请输入一个字符串:\n");
gets(str);
StrLen = strlen(str);
while (i < StrLen)
{
if (str[i] == ToBeSearch[0] && str[i+1] == ToBeSearch[1])
{
count++;
i += 2;
}
else
{
i++;
}
}
printf("字符串 \"%s\" 中有 %d 个 \"%s\"\n", str, count, ToBeSearch);
return 0;
}
1,
#include <stdio.h>
#include <math.h>
int main(void)
{
float x, y, z;
printf("请输入三个实数:\n");
scanf("%f %f %f", &x, &y, &z);
if (x > 0 && y > 0 && z > 0)
{
if ((x+y > z && x+z > y && y+z > x)
&& (fabs(x-y) < z && fabs(x-z) < y && fabs(y-z) < x))
{
printf("以%f, %f, %f为三条边可以构成三角形,", x, y, z);
if (x==y && x==z)
{
printf("且是等边三角形\n");
}
else if (x==y || x==z || y==z)
{
printf("且是等腰三角形\n");
}
else if ((x*x + y*y == z*z)
|| (x*x == y*y + z*z)
|| (x*x + z*z == y*y))
{
printf("且是直角三角形\n");
}
else
{
printf("且是一般的三角形\n");
}
}
else
{
printf("以%f, %f, %f为三条边时不可以构成三角形!\n", x, y, z);
}
}
else
{
printf("以%f, %f, %f为三条边时不可以构成三角形!\n", x, y, z);
}
return 0;
}
都是简单的,还一两题你自己来,免得你也没进步!
温馨提示:答案为网友推荐,仅供参考