【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;
}
相关推荐
norlan_jame6 小时前
C-PHY与D-PHY差异
c语言·开发语言
ZPC82107 小时前
docker 镜像备份
人工智能·算法·fpga开发·机器人
ZPC82107 小时前
docker 使用GUI ROS2
人工智能·算法·fpga开发·机器人
琢磨先生David7 小时前
Day1:基础入门·两数之和(LeetCode 1)
数据结构·算法·leetcode
颜酱7 小时前
栈的经典应用:从基础到进阶,解决LeetCode高频栈类问题
javascript·后端·算法
多恩Stone7 小时前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
生信大杂烩7 小时前
癌症中的“细胞邻域“:解码肿瘤微环境的空间密码 ——Nature Cancer 综述解读
人工智能·算法
czy87874757 小时前
除了结构体之外,C语言中还有哪些其他方式可以模拟C++的面向对象编程特性
c语言
蜡笔小马7 小时前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
m0_531237177 小时前
C语言-数组练习进阶
c语言·开发语言·算法