#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#define N 80
void printtext(int line, int col, char text[]);
void printspaces(int n);
void printblanklines(int n);
int main()
{
int line, col, i;
char text[N] = "hi,May~";
srand(time(0));
for (i = 1; i <= 10; ++i)
{
line = rand() % 25;
col = rand() % 80;
printtext(line, col, text);
Sleep(1000);
}
return 0;
}
void printspaces(int n)
{
int i;
for (i = 1; i <= n; ++n)
printf(" ");
}
void printblanklines(int n)
{
int i;
for (i = 1; i <= n; ++i)
printf("\n");
}
void printtext(int line, int col, char text[])
{
printblanklines(line - 1);
printspaces(col - 1);
printf("%s", text);
}
![]()
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
long long fun(int n);
int main()
{
int n;
long long f;
while (scanf("%d", &n) != 0)
{
f = fun(n);
printf("n=%d,f=%lld\n", n, f);
}
return 0;
}
long long fun(int n)
{
long long static s ;
if (n != 0)
s = 2*fun(n - 1)+1;
else
s = 1;
return s;
}
![]()
void hanoi(unsigned int n, char from, char temp, char to);
void moveplate(unsigned int n, char from, char to);
int main()
{
unsigned int n;
int c;
while (scanf("%u", &n) != 0)
hanoi(n, 'A', 'B', 'C');
return 0;
}
void hanoi(unsigned int n, char from, char temp, char to)
{
if (n == 1)
moveplate(n , from, to, temp);
else
{
hanoi(n - 1, from, to, temp);
moveplate(n, from, to);
hanoi(n - 1, temp, from, to);
}
}
void moveplate(unsigned int n, char from, char to)
{
static i = 0;
printf("%u:%c->%c\n", n, from, to);
i++;
if (n == 1 && to == 'C' && i != 1)
{
printf("一共移动了%d次\n", i);
i = 0;
}
}
![]()
#include<stdio.h>
#include<math.h>
int is_prime(int n);
int main()
{
int i,j;
for (i = 3; i < 20; i++)
{
if (i % 2 == 0)
{
for (j = 2; j <= i/2; j++)
if (is_prime(j) && is_prime(i - j))
printf("%d=%d+%d\n", i, j, i - j);
}
else
continue;
}
return 0;
}
int is_prime(int n)
{
int k;
for (k = 2; k <= sqrt(n); k++)
if (n % k == 0)
return 0;
return 1;
}![]()
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
long fun(long s);
int main()
{
long s, t;
printf("Enter a number:");
while (scanf("%ld", &s) != 0)
{
t = fun(s);
printf("new number is: %ld\n\n", t);
printf("Enter a number: ");
}
return 0;
}
long fun(long s)
{
int n,i=0;
long int q = 0;
for(;s!=0;)
{
n = s % 10;
if (n % 2 != 0)
{
q +=n* pow(10,i);
i++;
}
s = s / 10;
}
return q;
}
![]()