【C语言】基础篇

简单输出"helloword"

cpp 复制代码
#include<stdio.h>
int main(){
	printf("hello world!");
	return 0;
}

和与商

cpp 复制代码
#include<stdio.h>
int main(){
	int a,b,sum,quotient;
	printf("Enter two numbers:");
	scanf("%d %d",&a,&b);
	sum = a + b;
	quotient = a / b;
	printf("%d + %d = %d\n",a,b,sum);
	if(b != 0){
	printf("%d / %d = %d",a,b,quotient);
	}
	else{
		printf("请检查你输入的数字是否正确。");
	}
	return 0;
}

判断奇偶

cpp 复制代码
#include<stdio.h>
int main(){
	int number;
	printf("Enter a number:");
	scanf("%d",&number);
	if(number%2 == 0){
		printf("%d is even",number);
	}
	else{
		printf("%d is odd",number);
	}
	return 0;
}

判断闰年

cpp 复制代码
#include<stdio.h>
int main(){
	int year;
	printf("Enter a year:");
	scanf("%d",&year);
	if(year % 4 == 0 & year % 100 != 0 | year % 400 == 0){
		printf("%d is a leap year",year);
	}
	else{
		printf("%d is not a leap year",year);
	}
}

求阶乘

cpp 复制代码
#include<stdio.h>
int main(){
	int n,i;
	int t = 1;
	printf("Enter a number:");
	scanf("%d",&n);
	for(i = 1;i <= n;i++){
		t = t * i;
	}
	printf("factorial = %d",t);
	return 0;
}
相关推荐
梨子串桃子_16 小时前
推荐系统学习笔记 | PyTorch学习笔记
pytorch·笔记·python·学习·算法
zfxwasaboy16 小时前
DRM KMS 子系统(4)Planes/Encoder/Connector
linux·c语言
夏鹏今天学习了吗16 小时前
【LeetCode热题100(83/100)】最长递增子序列
算法·leetcode·职场和发展
情缘晓梦.16 小时前
C语言指针进阶
java·开发语言·算法
极客代码17 小时前
深入解析C语言中的函数指针:原理、规则与实践
c语言·开发语言·指针·状态机·函数·函数指针
敲皮裤的代码17 小时前
《C语言》分支和循环(下)
c语言
北邮刘老师17 小时前
智能体治理:人工智能时代信息化系统的全新挑战与课题
大数据·人工智能·算法·机器学习·智能体互联网
AlenTech18 小时前
155. 最小栈 - 力扣(LeetCode)
算法·leetcode·职场和发展
mit6.82418 小时前
正反两次扫描|单调性cut
算法
Yzzz-F18 小时前
牛客小白月赛127 E
算法