【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;
}
相关推荐
计算机安禾几秒前
【数据结构与算法】第15篇:队列(二):链式队列的实现与应用
c语言·开发语言·数据结构·c++·学习·算法·visual studio
算法鑫探10 分钟前
C语言密码验证:3次机会解锁
c语言·数据结构·算法·新人首发
穿条秋裤到处跑24 分钟前
每日一道leetcode(2026.03.30):判断通过操作能否让字符串相等 II
算法·leetcode
Q741_14725 分钟前
每日一题 力扣 2840. 判断通过操作能否让字符串相等 II 力扣 2839. 判断通过操作能否让字符串相等 I 找规律 字符串 C++ 题解
c++·算法·leetcode·力扣·数组·找规律
xu_wenming30 分钟前
在 TinyML 场景下,如何将模型从 FP32 量化为 INT8?
arm开发·算法·iot
csdn_aspnet33 分钟前
C++ 求n边凸多边形的对角线数量(Find number of diagonals in n sided convex polygon)
开发语言·c++·算法
wsoz36 分钟前
快速从C过渡到C++
c语言·开发语言·c++
深邃-1 小时前
字符函数和字符串函数(1)
c语言·开发语言·数据结构·c++·算法·html5
我真不是小鱼1 小时前
cpp刷题打卡记录24——路径总和 & 路径总和II
数据结构·c++·算法·leetcode
菜鸟小九1 小时前
JVM垃圾回收
java·jvm·算法