#include
int main()
{
int n = 0, t;
for (t=0; t<=20*7; t++)
{
if (t%5 == 0 && t <= 20*5) /* 控制A舰每隔5秒放1次 */
{
n++;
continue; /* 继续下一次循环 */
}
if ( t%6 == 0 && t <= 20*6) /* 控制B舰每隔6秒放1次 */
{
n++;
continue; /* 继续下一次循环 */
}
if (t%7 == 0) /* 控制C舰每隔7秒放1次 */
{
n++;
}
}
printf("n = %d\n", n);
}
#include
#define CURRENT 100
int main()
{
int year; /* 产值翻番所需年数 */
double growRate; /* 工业产值的增长率 */
double output; /* 工业总产值 */
printf("Input grow rate:");
scanf("%lf", &growRate);
output = CURRENT; /* 当年产值为100万元 */
for (year=0; output<2*CURRENT; year++)
{
output = output * (1 + growRate);
}
printf("When grow rate is %.0f%%, the output can be doubled after %d years.\n", growRate*100, year);
return 0;
}
#include
int main()
{
int i, j, k, m;
for (i=0; i<=9; i++)
{
for (j=0; j<=9; j++)
{
if (i != j)
{
k = i * 1000 + i * 100 + j * 10 + j;
for (m=31; m*m<=k; m++)
{
if (m*m == k)
printf("k=%d, m=%d\n", k, m);
}
}
}
}
}
#include
int main()
{
int x, y, z;
for (x = 0; x <= 9; x++)
{
for (y = 0; y <= 12; y++)
{
z = 36 - x - y;
if ( 4 * x + 3 * y + z / 2 == 36 && z % 2 == 0)
{
printf("men=%d,women=%d,children=%d\n", x, y, z);
}
}
}
return 0;
}
#include
#include
int main()
{
float a, b, c, s, area;
printf("Input a,b,c:");
scanf("%f,%f,%f", &a, &b, &c);
if (a+b>c && b+c>a && a+c>b)
{
s = (float)(a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("area = %f\n", area);
}
else
{
printf("It is not a triangle\n");
}
return 0;
}
#include
#include
int main()
{
int x, b0, b1, b2, y;
printf("Input x:");
scanf("%d", &x);
x = (int)fabs(x);
b2 = x / 100; /* 计算百位数字 */
b1 = (x - b2 * 100) / 10; /* 计算十位数字 */
b0 = x % 10; /* 计算个位数字 */
y = b2 + b1*10 + b0*100;
printf("y = %d\n",y);
return 0;
}
#include
int Gcd(int a, int b);
int main()
{
int a, b, c;
printf("Input a,b:");
scanf("%d,%d", &a, &b);
c = Gcd(a, b);
if ( c!= -1)
printf("Greatest Common Divisor of %d and %d is %d\n", a, b, c);
else
printf("Input number should be positive!\n");
return 0;
}
int Gcd(int a, int b)
{
if (a <= 0 || b <= 0)
return -1;
if (a == b)
return a;
else if (a > b)
return Gcd(a - b, b);
else
return Gcd(a, b - a);
}
#include
int DayofYear(int year, int month, int day);
int dayTab[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
int main()
{
int year, month, day, yearDay;
printf("Please enter year, month, day:");
scanf("%d,%d,%d", &year, &month, &day);
yearDay = DayofYear(year, month, day);
printf("yearDay = %d\n", yearDay);
return 0;
}
/* 函数功能:对给定的某年某月某日,计算并返回它是这一年的第几天 */
int DayofYear(int year, int month, int day)
{
int i, leap;
leap = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0); /* 若year为闰年,即leap值为1,则用第1行元素dayTab[1][i]计算;
否则leap值为0,用第0行dayTab[0][i]计算 */
for (i=1; i
#include
#include
int sum_prime(int a[]);
int prime(int n);
int main()
{
int i, a[10], sum;
sum = sum_prime(a);
for (i = 0; i < 10; i++)
printf("%6d", a[i]);
printf("\nsum=%d\n", sum);
return 0;
}
int sum_prime(int a[])
{
int i, j = 499, sum = 0;
for (i = 0; i < 10; )
{
if (prime(j))
{
sum = sum + j ;
a[i] = j;
i++;
}
j--;
}
return sum;
}
int prime(int n)
{
int i, k;
k = (int) sqrt((double)n);
for (i = 2; i <= k; i++)
{
if (n % i == 0)
return 0;
}
if ( i >= k + 1)
return 1;
}
#include
unsigned long Factorial(unsigned int number);
int main()
{
int m, k;
double p;
do{
printf("Please input m,k (m>=k>0):");
scanf("%d, %d", &m, &k);
} while (m
#include
int main()
{
char isbn[13];
int i, k = 0, last, p;
gets(isbn);
for (i = 0, p = 0; i < 11; i ++)
{
if (isbn[i] == '-') continue;
p ++;
k += (isbn[i] - 48) * p;
}
last = k % 11;
if (last == 10)
last = 'X';
else
last += 48;
if (last == isbn[12])
printf("Right");
else
{
isbn[12] = last;
printf("%s", isbn);
}
return 0;
}
#include
#include
#define NUM_ELECTORATE 10
#define NUM_CANDIDATE 3
struct candidate
{
char name[20];
int count;
}candidate[3] = {"li",0, "zhang",0, "wang",0};
int main()
{
int i, j, flag = 1, wrong = 0;
char name[20];
for (i=1; i<=NUM_ELECTORATE; i++)
{
printf("Input vote %d:", i);
scanf("%s", name);
strlwr(name); /* C语言的标准库函数,功能是将name中的字符全部变成小写字母 */
flag = 1;
for (j=0; j
#include
#define M 10
#define N 10
void Transpose(int a[][N], int at[][M], int m, int n);
void InputMatrix(int a[][N], int m, int n);
void PrintMatrix(int at[][M], int n, int m);
int main()
{
int s[M][N], st[N][M], m, n;
printf("Input m, n:");
scanf("%d,%d", &m, &n);
InputMatrix(s, m, n);
Transpose(s, st, m, n);
printf("The transposed matrix is:\n");
PrintMatrix(st, n, m);
return 0;
}
/* 函数功能:计算m*n矩阵a的转置矩阵at */
void Transpose(int a[][N], int at[][M], int m, int n)
{
int i, j;
for (i=0; i
#include
int main()
{
int i;
for (i = 100; i <= 200; i++)
{
if ( (i - 2) % 4 == 0)
{
if ((i - 3) % 7 == 0)
{
if ((i - 5) % 9 == 0)
printf("%d\n", i);
}
}
}
return 0;
}