• 简单输出“helloword”

#include<stdio.h>
int main(){
	printf("hello world!");
	return 0;
}
  •  和与商

#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;
}
  • 判断奇偶

#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;
}
  • 判断闰年

#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);
	}
}
  • 求阶乘

#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;
}

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部