2025-03-10 19:07:30 +08:00

246 lines
4.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### C语言-1
```c
/*---------------------------------------------------------
【程序设计】程序将由数字字符组成的字符串转换为10进制实数
例如将"123.4567"转换为123.45670。
输出如下:
123.45670
0.12345
4567.00000
------------------------------------------------------------------------
注意部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容仅在
Program-End之间填入若干语句。不要删除标志否则不得分。
---------------------------------------------------------*/
#include<stdio.h>
#include<ctype.h>
double conver(char s[]){
int I,i,poi;
double F,p;
F=I=i=poi=0;
p=0.1;
/**********Program**********/
while(s[i] != '.'){
I*=10;
I+=s[i]-48;
i++;
}
i++;
while(s[i] != '\0'){
F+=(s[i]-48)*p;
p*=0.1;
i++;
}
/********** End **********/
return I+F;
}
int main()
{
char d[3][15]={"123.4567","0.12345","4567.0"};
int i;
for(i=0;i<3;i++)
printf("%12.5f\n",conver(d[i]));
return 0;
}
```
### C语言-2
```c
/*
-------------------------------------------------------
【程序填空】
---------------------------------------------------------
打印以下图案:
*****
*****
*****
*****
*****
*/
#include<stdio.h>
void main()
{
int i =0 , j =0 , k=0;
/**********Program**********/
for(i=0;i<5;i++){
for(j=0;j<i;j++){
printf(" ");
}
for(k=0;k<5;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
printf("\n");
}
```
### C语言-3
```c
/*-------------------------------------------------------
功能:功能:输入三角形的三边长,判断能否构成三角形,若能,利用海伦公式计
算该三角形的面积计算结果保留3位小数。
l=(a+b+c)/2s=sqrt(l*(l-a)*(l-b)*(l-c))
--------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
float a,b,c,s,l;
scanf("%f,%f,%f",&a , &b , &c);
if(a+b<c||a+c<b||b+c<a)
printf("该3个数据不能构成三角形\n");
else
{
/**********Program**********/
l=(a+b+c)/2;
s=sqrt(l*(l-a)*(l-b)*(l-c));
/********** End **********/
printf("该三角形的面积为%.3f\n",s);
}
}
```
### C语言-4
```c
/*-------------------------------------------------------
编写程序,打印以下图形:
*
***
*****
*******
*****
***
*
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j,k;
for(i=-3;i<=3;i++)
{
/**********Program**********/
for(j=0;j<abs(i);j++){
printf(" ");
}
for(k=0;k<7-2*j;k++){
printf("*");
}
printf("\n");
/********** End **********/
}
}
```
### C语言-5
```c
/*-----------------------------------------------------------
功能从键盘为一维整型数组输入10个整数调用函数找出其中
最小的数并输出。
-----------------------------------------------------------*/
#include <stdio.h>
#include<stdlib.h>
/**********Program**********/
int fun(int *a, int n){
int min = a[0], i;
for(i=1;i<n;i++){
if(min > a[i]){
min = a[i];
}
}
return min;
}
/********** End **********/
main()
{
int a[10],i,min;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<10;i++)
printf("%3d",a[i]);
printf("\n");
min=fun(a,10);
printf("min=%d\n",min);
}
```
### C语言-6
```c
/*------------------------------------------------------------------------------
【程序设计】编写函数rtrim用来删除字符串尾部的空格首部和中间的空格不删除。例如字符串为" A BC DEF "
删除后的结果是" A BC DEF"。要求函数形参采用指针变量。
测试输入: A BC DEF
测试输出: A BC DEF
说明测试输入中A前有4个空格F后有5个空格
------------------------------------------------------------------------
注意部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容否则不得分。
仅在Program-End之间填入若干语句。不要删除标志否则不得分。
------------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
void main()
{
void rtrim(char *p);
char s[100];
gets(s);
rtrim(s);
puts(s);
}
void rtrim(char *p)
{
int i;
/**********Program**********/
while(*p != '\0'){
p++;
}
p--;//定位到结束符前的位置
while(*p==' '){//如果当前指针位置是空格则指针向前移
p--;
}
p++;//移动当前位置后一个空格位
*p='\0';
/********** End **********/
}
```
### C语言-7
```c
```