This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"cmd": ["gcc", "${file}", "-o", "${file_path}/${file_base_name}.exe"], | |
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", | |
"working_dir": "${file_path}", | |
"selector": "source.c, source.c++", | |
"variants": | |
[ | |
{ | |
"name": "Run", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 有10个整数组成一个数组a,其中整数x出现了若干次,删除多余的x | |
只保留一个x,显示删除了的x的个数和最后的数组a */ | |
//假如要删除1 | |
#include <stdio.h> | |
#define N 100 | |
void main() | |
{ | |
int x, i, count = 0; | |
int a[10] = {5, 1, 2, 1, 1, 4, 3, 1, 1, 6}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 根据用户掷色子的值,显示相应个数的星号* | |
#include <stdio.h> | |
void showone (); | |
void showtwo (); | |
void showthree (); | |
void showfour (); | |
void showfive (); | |
void showsix (); // 色子数为1~6的情况分别以星号表示 | |
int randn(); //随机摇出色子点数 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 用递归法计算n! | |
#include <stdio.h> | |
long factorial (int n) | |
{ | |
long f; | |
if(n <= 1) f = 1; | |
else f = n * factorial(n - 1); | |
return(f); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 变量的作用域 | |
#include <stdio.h> | |
int count; // this is a global variable | |
void head1(); | |
void head2(); | |
void head3(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 求两个整数的最大公约数的算法; | |
对于两个整数integer1和integer2, 算法如下: | |
1 如果integer1/integer2的余数为0,那么integer2就是最大公约数 | |
2 如果余数不为0,那么将integer2赋值给integer1,余数赋值给integer2 | |
3 从步骤1重复执行 | |
编程一个程序来实现这个算法,它使用两个整型参数,并返回最大公约数。 */ | |
#include <stdio.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 截取并输出任意字符串的前n个字符 | |
#include <stdio.h> | |
void main() | |
{ | |
char cData[256]; | |
char *p = cData; // *p指向字符数组cData | |
int n; | |
puts("请输入一串字符串:"); | |
gets(p); // 输入的字符串存放在数组cData中 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 某班有3名同学参加考试,求成绩最高的学生的姓名 | |
#include <stdio.h> | |
#define N 3 | |
void main() | |
{ | |
char sName[N][10]; // 只写sName[N]为什么不行 // 假设姓名最多占10个字符(最多4个汉子或9个字母) | |
int i, t, iScore[N]; | |
printf("顺序输入每个同学的姓名和成绩(用空格分开):\n"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 求二维数组iData[M][N]中最大元素所在的行和列 | |
#include <stdio.h> | |
#define M 3 | |
#define N 4 | |
void main() | |
{ | |
int i, j, iData[M][N]; | |
int *p, *pMax; | |
printf("请按行输入%d x %d数组的各元素:\n", M, N); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 用起泡法排序 | |
#include <stdio.h> | |
#define N 100 | |
void main() | |
{ | |
int iData[N]; | |
int *p; | |
int i, j, n, t; | |
printf("共有几个数(1~%d):", N); |
OlderNewer