第一个是替换字符串代码
#include#include #include int main() { char arr1[] = " WBG THESHY!"; char arr2[] = " IG Theshy!"; int left = 0; int right = strlen(arr1) - 1; //strlen 需要引入头文件 string.h while (left <= right) { arr2[left] = arr1[left]; printf("%sn", arr2); Sleep(200); //需要引入头文件 windows.h system("cls"); left++; } printf("%sn", arr2); return 0; }
第二个代码 {输入两个数,求其最大公约数(辗转相除法)}
#includeint main() { int a = 0; int b = 0; scanf("%d%d", &a, &b); int c = 0; while (c = a%b) { a = b; b = c; } printf("%dn", b); return 0; }
最后分享一个简单的题 (求n!)
#includeint main() { int n = 1; scanf("%d", &n); int a = 0; int c = 1; for (a = 1; a <= n; a++) { c *= a; } printf("%dn", c); return 0; }
初学C语言,有许多地方有问题,还请大家多多指点。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)