C语言-01

1、第一个test程序

#include<stdio.h>
int main(){
	printf("这是一个test\n");
}

2、a+b

#include<stdio.h>
int main(){
	int a,b,sum;
	a = 10;
	b = 20;
	sum = a + b;
	printf("sum的值 = %d \n",sum);
}

3、通过方法调用实现a+b

#include<stdio.h>

int plus(int x,int y){
	int z;
	z = x + y;
	return(z);
}

int main(){
	int a,b,c;
	scanf("%d,%d",&a,&b);
	c = plus(a,b);
	printf("c的值 = %d \n",c);
	return 0;
}

4、求两数最大者

#include<stdio.h>
//求两个数之间的最大者
int max(int x,int y){
	int z;
	if(x > y) z = x;
	else z = y;
	return(z);
}
//主函数
int main(){
	/*max方法放在main函数之前,就不需要下面这个声明
	  max方法放在main函数之后,就需要下面这个声明*/
	//int max(int x,int y);
	int a,b,c;
	scanf("%d,%d",&a,&b);
	c = max(a,b);
	printf("max=%d \n",c);
	return 0;
}

5、输出值为75-100的ASCII字符

#include<stdio.h>
int main(){
	int ch;
	for(ch = 75; ch <= 100; ch++){
		printf("ASCII的值 = %d,key = %c \n",ch,ch);
	}
}

6、大写A转换小写a

#include<stdio.h>
int main(){
	char c1,c2;
	c1 = 'A';
	c2 = c1 + 32;
	printf("%d\n",c2);
	printf("%c\n",c2);
	return 0;
}

7、输出下面的图案

在这里插入图片描述

#include<stdio.h>
int main(){
	int i,j,k;
	for(i=0;i<5;i++){
		for(k=0;k<i;k++){
			printf(" ");
		}
		for(j=0;j<5;j++){
			printf("*");
		}
		printf("\n");
	}
	
	return 0;
}

8、求三个数中最大者

#include<stdio.h>
// max_abc
int max(int x,int y,int z){
	int m;
	if(x>y && x>z){
		m = x;
	}
	else if(y>x && y>z){
		m = y;
	}else m = z;
	return(m);
}
// 主函数
int main(){
	int a,b,c,d;
	scanf("%d,%d,%d",&a,&b,&c);
	d = max(a,b,c);
	printf("a,b,c 中最大的是:%d \n",d);
	return 0;
}

9、对从1到用户输入的数进行求和

#include<stdio.h>

int x;
//求和
int sum(){
	int i;
	int total = 0;
	scanf("%d",&x);
	for(i=1;i<x;i++){
		total = total +i;
	}
	return(total);
}
// 主函数
int main(){
	int m = sum();
	printf("1到 %d 的总数和 = %d\n",x,m);
	return 0;
}

10、求三角形面积

#include<stdio.h>
#include<math.h>

int main(){
	double a = 3.67,b = 5.43,c = 6.21;
	double s,area;
	s = (a + b + c) / 2;
	area = sqrt(s * (s - a) * (s - b) * (s - c));
	printf("a = %f\t b = %f\t c = %f\n",a,b,c);
	printf("三角形的面积 = %f\n",area);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值