1、打印hello world程序
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
结果:
2、计算两个整数的和
#include <stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
printf("a+b=%d\n",a+b);
return 0;
}
结果:
3、计算简单的多项式求值
计算当x=3的时候,y的值
#include <stdio.h>
int main()
{
int x,y;
printf("please input a number:");
scanf("%d",&x);
y=2*x*x+x+8;
printf("y=%d\n",y);
return 0;
}
结果:
4、两个整数的四则运算
输入两个数:num1、num2,设计一个程序,计算输出它们的和、差、积、商及余数
#include <stdio.h>
int main()
{
int num1,num2;
printf("please input two int number:");
scanf("%d %d",&num1,&num2);
printf("num1+num2=%d\n",num1+num2);
printf("num1-num2=%d\n",num1-num2);
printf("num1*num2=%d\n",num1*num2);
printf("num1/num2=%d\n",num1/num2);
printf("num1%%num2=%d\n",num1%num2);
}
结果:
|