【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;
}
相关推荐
IT猿手2 小时前
2025最新群智能优化算法:山羊优化算法(Goat Optimization Algorithm, GOA)求解23个经典函数测试集,MATLAB
人工智能·python·算法·数学建模·matlab·智能优化算法
Dream it possible!5 小时前
LeetCode 热题 100_字符串解码(71_394_中等_C++)(栈)
c++·算法·leetcode
Kurbaneli6 小时前
深入理解 C 语言函数的定义
linux·c语言·ubuntu
Archer1946 小时前
C语言——链表
c语言·开发语言·链表
修己xj6 小时前
算法系列之深度优先搜索寻找妖怪和尚过河问题的所有方式
算法
夜晚中的人海6 小时前
【C语言】------ 实现扫雷游戏
android·c语言·游戏
面会菜.6 小时前
C语言(队列)
c语言·开发语言
开心比对错重要6 小时前
leetcode69.x 的平方根
数据结构·算法·leetcode
美狐美颜sdk6 小时前
什么是美颜SDK?从几何变换到深度学习驱动的美颜算法详解
人工智能·深度学习·算法·美颜sdk·第三方美颜sdk·视频美颜sdk·美颜api
m0_461502697 小时前
【贪心算法1】
算法·贪心算法