一、hello world /函数printf使用/
#include<stdio.h>
int main()
{
printf("helllo world\n");
return 0;
}
/ #include<stdio.h> 开头调用程序库 头文件 /
int main()
{
printf("helllo world\n"); 主函数
return 0;
}
//求最大者
#include<stdio.h> //头文件
int main() //主函数
{
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
if(a>b)c=a;
else c=b;
printf("最大值是:%d",c);
return 0;
}
//求最大者 函数调用
//定义函数叫行参 主函数叫实参
#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);
}
一个源程序文件 现在
多个函数 必须要有一个主函数 main
三部分 预处理 声明 主函数
//求和
//函数调用 定义函数叫行参 主函数叫实参
#include<stdio.h> //头文件
int main() //主函数{
int sum(int x,int y);
int a,b,c;
scanf("%d,%d",&a,&b);
c = sum(a,b);
printf("sum=%d\n",c);
return 0;
}
int sum(int x,int y)
{
int z;
z = x+y;
return(z);
}
二、算法
算法+数据结构=程序
//连乘
#include<stdio.h>
int main()
{
int p = 1,i = 2;
while(i<=5)
{
p = p*i;
i = i+1;
}
printf("%d",p);
return 0;
}
//
//流程图 表示算法 如何表示算法 流程图 NS图