C程序设计 第一章

程序设计和C语言

例1.1 要求在屏幕上输出以下一行信息

This is a C program.

#include<stdio.h>
int main()
{
printf("This is a C program.\n");
return 0;
}

运行结果如下

在这里插入图片描述
例1.2 求两个整数之和

#include<stdio.h>
int main()
{
int a,b,sum;
a=123;
b=456;
sum=a+b;
printf("sum is %d\n",sum);
return 0;
}

运行结果如下

在这里插入图片描述

例1.3 求两个整数中的较大者

#include<stdio.h>
int main()
{
    int max(int x,int y);
    int a,b,c;
    scanf("%d,%d",&a,&b);
    c=max(a,b);
    printf("max=%d\n",c);
    return 0;
}
   int max(int x,int y)
{
   int z;
   if(x>y)z=x;
   else z=y;
   return(z);
}

运行结果如下
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44681132/article/details/87885262