C语言复习

这篇博客涵盖了C语言的基础知识,包括整数处理、时间转换、倒置整数、ASCII码、逻辑判断以及多种数学序列的输出。还涉及到数组、字符串操作、排序算法和二维数组的矩阵操作,是C语言学习者的良好实践材料。
摘要由CSDN通过智能技术生成

鸡兔同笼

#include<stdio.h>
void main()
{
   
	int n,m;
	int k,r;
	scanf("%d%d",&n,&m);
	r=(1.0/2.0)*(m-2*n);
	k=(1.0/2.0)*(4*n-m);
	printf("%d %d",k,r);
}

输出第2个整数

#include <bits/stdc++.h>
using namespace std;
int main()
{
   
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    printf("%d",b);
    return 0;
}

时分秒转换

#include<stdio.h>
void main()
{
   
	int h,m,s;
	scanf("%d",&s);
	h=s/3600;
	m=s/60%60;
	s%=60;
	printf("%d:%.2d:%.2d",h,m,s);
}

倒置整数

#include<stdio.h>
void main()
{
   
	int num;
	scanf("%d",&num);
	int a =0;
	int b =0;
	int c =0;
	int d =0;
	a=num%10;
	b=num/10%10;
	c=num/100;
	d=a*100+b*10+c;
	printf("%d",d);
	return 0;
}

显示字符的ASCII码

#include<stdio.h>
void main()
{
   
	int a;
	char c;
	a='c';
	c=getchar();
	printf("%d ",c);
	printf("0x%X",c);
}

ASCIIArt

#include <stdio.h>
void main()
{
   
	printf("(\\~~~/)\n");
	printf("(='_'=)\n");
	printf("(\") (\")~\n");
}

A+B

#include<stdio.h> 
void main() 
{
    
    printf("#include<stdio.h>\n");
    printf("int main()\n");
	printf("{\n");
	printf("    int a=246,b=789;\n");
	printf("    printf(\"a+b=%%d\\n\",a+b);\n");
	printf("}\n");
}

判断有1门课程不及格

#include<stdio.h>
void main()
{
   
	int a,b,c,d;
	a=1;
	b=0;
	scanf("%d%d",&c,&d);
	if(c<60 || d<60)
	{
   
		printf("%d",a);
	}
	else
	{
   
		printf("%d",b);
	}
	return 0;
}

平衡吗?

#include <stdio.h>
void main()
{
   
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a+b>c+d)
    {
   
        printf("Left");
    }
    else if(a+b==c+d)
    {
   
        printf("Balance");
    }
    else
    {
   
        printf("Right");
    }
}

阶梯水价

#include <stdio.h>
 
int main()
{
   
    double x,y;
    scanf("%lf",&x);
    if(x<=220)
    {
   
        y=3.5*x;
    }
    else
    {
   
        y=220*3.5+4.8*(x-220);
    }
    printf("%.1f",y);
    return 0;
}

星期几

#include<stdio.h>
 int main()
 {
   
     int t;
     scanf("%d", &t);
     printf("%d\n", (t + 4) % 7 == 0 ? 7 : (t + 4) % 7 );
     return 0;
 }

判断字符类别

#include<stdio.h>
int main(){
   
    char t;
    scanf("%c", &t);
    if (t >= 48 && t <= 57) printf("Digit\n");
    else if (t >= 65 && t <= 90) printf("Upper\n");
    else if (t >= 97 && t <= 122) printf("Lower\n");
    else printf("Other\n");
    return 0;
}

测试某点是否在正方形区域

#include<stdio.h>
main()
{
   
    float x,y;
    scanf("%f,%f",x,y);
    if(x>-1.0 && x<1.0 && y>-1.0 && y<1.0) printf("yes");
    else printf("no");
     
    return 0;
}

月份与天数

#include<stdio.h>
int main(){
   
    int y,m,d;
    scanf("%4d%2d",&y,&m);
 
    if (m==2) d = 28 + (y%4 == 0 && y % 100 || y%400==0);
    else if (m==4 || m==6 || m==9 || m==11) d = 30;
    else d = 31;
    printf
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值