【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;
}
相关推荐
董董灿是个攻城狮1 小时前
5分钟搞懂什么是窗口注意力?
算法
Dann Hiroaki1 小时前
笔记分享: 哈尔滨工业大学CS31002编译原理——02. 语法分析
笔记·算法
jz_ddk2 小时前
[学习] C语言数学库函数背后的故事:`double erf(double x)`
c语言·开发语言·学习
qqxhb3 小时前
零基础数据结构与算法——第四章:基础算法-排序(上)
java·数据结构·算法·冒泡·插入·选择
无小道3 小时前
c++-引用(包括完美转发,移动构造,万能引用)
c语言·开发语言·汇编·c++
FirstFrost --sy5 小时前
数据结构之二叉树
c语言·数据结构·c++·算法·链表·深度优先·广度优先
森焱森5 小时前
垂起固定翼无人机介绍
c语言·单片机·算法·架构·无人机
搂鱼1145145 小时前
(倍增)洛谷 P1613 跑路/P4155 国旗计划
算法
Yingye Zhu(HPXXZYY)5 小时前
Codeforces 2021 C Those Who Are With Us
数据结构·c++·算法
无聊的小坏坏6 小时前
三种方法详解最长回文子串问题
c++·算法·回文串