c和c++基础
c:
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
printf("%d",n);
return 0;
}
c++:
//该行为c++语言的输入cin 输出cout 的头文件
#include <iostream>
//一些常用算法的头文件
#include <algorithm>
//有了cstdio,在c++中可以使用scanf,printf
#include <cstdio>
//可以知道在c中的头文件xxxxx.h 改为cxxxxx就可以在c++里使用
using namespace std;//此行一定要有!
int main()
{
int n;
cin>>n;//输入
cout<<n<<endl;//输出
return 0;
}
//for while if else等和C语言使用方法相同
//再来一个c++例子
#include <iostream>
#include <algorithm>
using namespace std;
//令maxn为常量,通常用来设定数组范围
const int maxn=100+10;
//定义一个数组
int a[maxn];
int main()
{
int n;
cin>>n;
//在for里面int i,意味着i是局部变量,只能在for里面使用
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cout<<<a[i]<<" ";
}
//endl 为换行的意思,也可以写成cout<<"\n";
cout<<endl;
}
//未完待续~小伙伴们加油!
c与c++基础 #1
猜你喜欢
转载自blog.csdn.net/a_lazy_Rabbit/article/details/81062459
今日推荐
周排行