实验一
结果,会在随机的某一行(<25)某一列出现输出
实验二
结果:实现阶乘,static保证每一次循环中p的值会随之而改变,相当于我们只初始化一次p这个变量、
实验三
#include<stdio.h> #include <stdio.h> long long func(int n); // 函数声明 int main() { int n; long long f; while (scanf_s("%d", &n) != EOF) { f = func(n); // 函数调用 printf("n = %d, f = %lld\n", n, f); } return 0; } long long func(int n) { long long p = 1; for (int i = 0; i < n; i++) {17:07:17 p *= 2; } return p - 1; }
实验四
#include <stdio.h> #include<stdlib.h> void moveplate(int n, char from, char to) { printf("%d:%c-->%c\n", n, from, to); } int hanmo(int n, char from, char temp, char to) { int static count = 0; if (n == 1) { moveplate(n, from, to); return count+1; } else { hanmo(n - 1, from,to, temp); count++; moveplate(n, from, to); hanmo(n - 1, temp, from, to); } } int main() { int n = 0; while (scanf_s("%d", &n) != EOF) { int count=hanmo(n, 'A', 'B', 'C'); printf("%d", count); system("pause"); } }
实验六
#include <stdio.h> #include <math.h> long func(long s); // 函数声明 int main() { long s, t; printf("Enter a number: "); while (scanf_s("%ld", &s) != EOF) { t = func(s); // 函数调用 printf("new number is: %ld\n\n", t); printf("Enter a number: "); } return 0; } long func(long s) { int A[15] = {}; int count = 0; long sum = 0; for (int i = 1;s!=0&&i < 50; i++) { if((s%10)%2!=0){ A[count]=s%10; count++; } s /= 10; } for (int j = count; j>=0; j--) { sum += A[j]; printf("%d", sum); sum *= 10; } return sum/10; }
实验五
#include <stdio.h> #include<stdlib.h> void moveplate(int n, char from, char to) { printf("%d:%c-->%c\n", n, from, to); } int hanmo(int n, char from, char temp, char to) { int static count = 0; if (n == 1) { moveplate(n, from, to); return count+1; } else { hanmo(n - 1, from,to, temp); count++; moveplate(n, from, to); hanmo(n - 1, temp, from, to); } } int main() { int n = 0; while (scanf_s("%d", &n) != EOF) { int count=hanmo(n, 'A', 'B', 'C'); printf("%d", count); system("pause"); } }
标签:count,int,hanmo,long,char,实验,printf From: https://www.cnblogs.com/xuyi5448/p/17798417.html