f(x) = 2x+5
same as c language;
Add(x,y) = x+y;
int main()
{
int num1 = 0;
int num2 = 0;
scanf("%d%d",&num1,&num2);
int sum = num1 + num2;
printf("%d\n",sum);
return 0;
}
题外小笔记:之前一直都是在vscode 里面跑的,不太好用,今天换到了vs2022,安装之后运行代码又有路径问题的错误,跑不起来,好吧原来是scanf的原因……
解决方式:
在代码首行加
#define _CRT_SECURE_NO_WARNINGS 1
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <windows.h>
int Add(int x,int y)
{
int z = 0;
z = x + y;
return z;
}
int main()
{
int num1 = 0;
int num2 = 0;
scanf("%d%d", &num1, &num2);
//int sum = num1 + num2;
//函数的方式
int sum = Add(num1, num2);
printf("%d\n", sum);
return 0;
}
数组
int main()
{
//int a = 1;
//int a = 2;
//int a = 3;
//int a = 4;
//数组:一组相同类型的元素的集合
//10个整型1-10存起来
int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
char ch[5] = { 'a','b','c' };//不完全初始化,剩下的默认为0
return 0;
}
数组是用下标来访问的:每个元素都有下标,第一个元素下标为0,第二个为1,以此类推
arr【0】,访问的第一个元素
int main()
{
//int a = 1;
//int a = 2;
//int a = 3;
//int a = 4;
//数组:一组相同类型的元素的集合
//10个整型1-10存起来
//数组是用下标来访问的
int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
int i = 0;
while (i < 10)
{
printf("%d ", arr[i]);
i++;
}
//char ch[5] = { 'a','b','c' };//不完全初始化,剩下的默认为0
return 0;