语法基础
#include <bits/stdc++.h>
using namespace std ;
int aa[100] ;
int b[][4] = {1,1,2,3,3,4,4} ;
int fun(int ,int);
int main(){
//cout << fixed << setprecision(10) << sqrt(2) << endl ;
double f = 7.0;
//cout << showpoint << f << endl;
// int c = 4 ;
// bool a = true ;
// a || (c+=1);
// cout << c << endl;
//
int a = INT_MAX + 1;
cout << a << endl << INT_MAX;
cout << endl ;
cout << LONG_LONG_MAX ; //64位
for(int i= 0;i<100; i++){
cout << aa[i] << " " ;
}
cout << endl ;
int aa[100] = {1,2} ;
for(int i= 0;i<100; i++){
cout << aa[i] << " " ;
}
int *p = aa;
p++;
cout << *p << endl ;
fun(10,20);
return 0;
}
int fun(int a, int b)
{
int c = a+b;
return c;
}
函数 和递归
#include<bits/stdc++.h>
using namespace std ;
int a[10];
char st[10]; //字符数组
void f(int i)
{
if(i > 10 ) return ;
cout << i << " ";
f(i+1);
}
int fib(int n)
{
if(n ==1 || n==2) return 1;
int a = fib(n-1);
int b = fib(n-2) ;
return a +b;
}
int c(int i)
{
if(i == 1) return 1;
int a = c(i-1) ;
return a + i - 1;
}
void ff(int n, int b)
{
if (n==0) return;
ff(n/b, b);
cout << n%b;
}
int main(){
ff(6,2) ;
return 0;
}
排序
#include<bits/stdc++.h>
using namespace std ;
int a[6] = {0, 3,2,4,1,5} ;
int main(){
int tot = 0;
int n= 5;
//冒泡排序
// for(int i=1; i<=n-1; i++) //趟数
// {
// for(int j = 1; j<= n-i; j++)
// if(a[j+1] < a[j]) {
// tot++ ; swap(a[j] , a[j+1]);//交换的次数
// }
// }
//选择排序
for(int i=1; i<=n-1; i++){
int k = i ;
for(int j=i+1;j <=n; j++){
if(a[j] < a[k] ) k = j;
}
if(k!=i) swap(a[k], a[i]);
}
cout <<tot <<endl ;
for(int i=1; i<=5; i++) {
cout << a[i] << " " ;
}
return 0;
}
—— 本文来自火龙信奥(义乌睿码科技):义乌青少年信息学奥赛与编程教育平台,专注 CSP-J/S、NOIP、GESP 竞赛培训,线上线下融合教学,助力编程升学。网址:hlcoding.com