如有疑问,欢迎评论、私信讨论交流!
01:Hello, World!
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{
printf("Hello, World!\n");
return 0;
}
02:输出第二个整数
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
printf("%d\n",b);
return 0;
}
03:对齐输出
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("%8d %8d %8d\n",a,b,c);
return 0;
}
04:输出保留3位小数的浮点数
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{
float a;
scanf("%f",&a);
printf("%.3f\n",a);
return 0;
}
05:输出保留12位小数的浮点数
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{
double a;
scanf("%lf",&a);
printf("%.12lf\n",a);
return 0;
}
06:空格分隔输出
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{
char a;
int b;
float c;
double d;
scanf("%c\n%d\n%f\n%lf",&a,&b,&c,&d);
printf("%c %d %.6f %.6lf\n",a,b,c,d);
return 0;
}
07:输出浮点数
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{
double d;
scanf("%lf",&d);
printf("%f\n%.5lf\n%e\n%g\n",d,d,d,d);
return 0;
}
08:字符三角形
#include <stdio.h>
int main()
{
char a;
scanf("%c",&a);
printf(" %c\n\
%c%c%c\n\
%c%c%c%c%c\n",a,a,a,a,a,a,a,a,a);
return 0;
}
09:字符菱形
#include <stdlib.h>
#include <stdbool.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{
char d;
scanf("%c",&d);
printf(" %c\n",d);
printf(" %c%c%c\n",d,d,d);
printf("%c%c%c%c%c\n",d,d,d,d,d);
printf(" %c%c%c\n",d,d,d);
printf(" %c",d);
return 0;
}
10:超级玛丽游戏
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
cout<<" ********"<<endl;
cout<<" ************"<<endl;
cout<<" ####....#."<<endl;
cout<<" #..###.....##...."<<endl;
cout<<" ###.......###### ### ### ### ###"<<endl;
cout<<" ........... #...# #...# #...# #...#"<<endl;
cout<<" ##*####### #.#.# #.#.# #.#.# #.#.#"<<endl;
cout<<" ####*******###### #.#.# #.#.# #.#.# #.#.#"<<endl;
cout<<" ...#***.****.*###.... #...# #...# #...# #...#"<<endl;
cout<<" ....**********##..... ### ### ### ###"<<endl;
cout<<" ....**** *****...."<<endl;
cout<<" #### ####"<<endl;
cout<<" ###### ######"<<endl;
cout<<"############################################################## ##################################"<<endl;
cout<<"#...#......#.##...#......#.##...#......#.##------------------# #...#......#.##------------------#"<<endl;
cout<<"###########################################------------------# ###############------------------#"<<endl;
cout<<"#..#....#....##..#....#....##..#....#....##################### #..#....#....#####################"<<endl;
cout<<"########################################## #----------# ############## #----------#"<<endl;
cout<<"#.....#......##.....#......##.....#......# #----------# #.....#......# #----------#"<<endl;
cout<<"########################################## #----------# ############## #----------#"<<endl;
cout<<"#.#..#....#..##.#..#....#..##.#..#....#..# #----------# #.#..#....#..# #----------#"<<endl;
cout<<"########################################## ############ ############## ############"<<endl;
return 0;
}