C语言 基础
分享一下最基础的上课写的基础代码1.两数相加 sum
#include<stdio.h>
main()
{
int y,g,sum;
g=900;
y=100;
sum=y+g;
printf("y=%d\ng=%d\n",y,g);
printf("sum is %d\n",sum);
printf("当你走进这欢乐场 \n");
}
2.比大小max函数
#include<stdio.h>
int max(int a,int b);
main()
{
int x,y,z;
printf("input two numbers:\n");
scanf("%d,%d",&x,&y);
z=max(x,y);
printf("max=%d\n",z);
}
int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
3.多数字相加输出
#include<stdio.h>
main()
{
int a,b,c,d;
a=3000;
b=a+1;
c=b+1;
d=a+b+c;
printf("a=%d,b=%d,c=%d,d=%d\n",a,b,c,d);
}
4.乘除运算基础、
#include<stdio.h>
main()
{
int a,b,c,d;
a=3;
b=a*10;
c=b+1;
d=a*b*c ;
printf("a=%d,b=%d,c=%d,d=%d\n",a,b,c,d);
}
5.字符型变量的赋值以及计算问题
#include<stdio.h>
main()
{
char a,b;
int c,d;
a=97;
b=98;
c='c';
d='d';
printf("%c,%c\n%d,%d\n",a,b,a,b);
c=c-32;
d=d-32;
printf("%c,%c\n%d,%d\n",c,d,c,d);
} 谢谢大牛 谢谢分享 感谢楼主分享 谢谢大佬 好的,非常感谢 6666666666
页:
[1]