标签:c程序设计
闲来无事把谭浩强的书里边的题敲了一遍,,纪念一哈,,纯手工
// 在屏幕上输出 This is a c program.
#include <stdio.h>
int main()
{
printf("This is a c program.\n");
return 0;
}
// 求两个整数之和
#include <stdio.h>
int main()
{
int a,b,c;
printf("请输入两个整数:\n");
scanf("%d %d",&a,&b);
c = a + b;
printf("两个整数之和是:%d\n",c);
return 0;
}
// 求两个整数中的较大者
#include <stdio.h>
int max( int a, int b )
{
int temp;
if( a > b )
{
temp = a;
}
else
{
temp = b;
}
return temp;
}
int main()
{
int a,b;
printf("请输入要比较的两个数:\n");
scanf("%d %d",&a,&b);
printf("大数是:%d\n",max(a,b));
return 0;
}
要说的是,这个简单的题 有好多种解法,我感觉最简单的最简短的就是用宏标记了,,
/* 输出
**********
very good!
**********
*/
#include <stdio.h>
int main()
{
int i;
for( i = 0; i < 10; i++)
{
printf("*");
}
printf("\n");
printf("very good!\n");
for( i = 0; i < 10; i++)
{
printf("*");
}
printf("\n");
return 0;
}
// 输入a,b,c三个值,输出其中最大者
#include <stdio.h>
int max( int a, int b, int c )
{
int temp;
if( a > b && a > c )
temp = a;
if( b > a && b > c )
temp = b;
if( c > a && c > b )
temp = c;
return temp;
}
int main()
{
int a,b,c;
printf("请输入三个数:\n");
scanf("%d %d %d",&a,&b,&c);
printf("最大的数是:%d\n",max(a,b,c));
return 0;
}
这一章的题都太简单了哈。。
标签:c程序设计
原文地址:http://blog.csdn.net/zhaoyaqian552/article/details/45025975