【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;
}
相关推荐
Aaron158817 分钟前
基于RFSOC的数字射频存储技术应用分析
c语言·人工智能·驱动开发·算法·fpga开发·硬件工程·信号处理
爱编码的小八嘎1 小时前
C语言对话-21.模板特化,缺省参数和其他一些有趣的事情
c语言
_不会dp不改名_2 小时前
leetcode_3010 将数组分成最小总代价的子数组 I
算法·leetcode·职场和发展
yueyuexiaokeai13 小时前
linux kernel常用函数整理
linux·c语言
你撅嘴真丑4 小时前
字符环 与 变换的矩阵
算法
想放学的刺客4 小时前
单片机嵌入式试题(第29期)嵌入式系统的电源完整性设计与去耦电容选型。抗干扰设计与EMC合规性
c语言·stm32·嵌入式硬件·物联网·51单片机
早点睡觉好了4 小时前
重排序 (Re-ranking) 算法详解
算法·ai·rag
gihigo19984 小时前
基于全局自适应动态规划(GADP)的MATLAB实现方案
算法
ctyshr5 小时前
C++编译期数学计算
开发语言·c++·算法
zh_xuan5 小时前
最小跳跃次数
数据结构·算法