當前位置:編程學習大全網 - 編程語言 - c語言程序設計的幾個題,求三角形形狀等,麻煩會的幫下忙,急急急!!!

c語言程序設計的幾個題,求三角形形狀等,麻煩會的幫下忙,急急急!!!

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;

}

都是簡單的,還壹兩題妳自己來,免得妳也沒進步!

  • 上一篇:部頒九年級上冊語文第六課原文及教案
  • 下一篇:外包開發壹套外賣app軟件需要多少錢
  • copyright 2024編程學習大全網