C语言一百题1~20题

1~10
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int a[100] = { 1,1 }, i, n;
	scanf_s("%d", &n);
	if (n == 1 || n == 2)
		printf("Having only one rabbit\n");
	else
	{
		for (i = 3; i < n; i++)
			a[i] = a[i - 1] + a[i - 2];
		printf("Having %d rabbit\n",a[n-1]);
	}
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int i, j;
	for (i = 100; i <= 200; i++)
	{
		for (j = 2; j < i; j++)
			if (i%j == 0)
				break;
		if (j == i)
			printf("%d\t", i);
	}
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int i, x1, x2, x3;
	printf("水仙花数:");
	for (i = 100; i < 1000; i++)
	{
		x1 = i % 10;
		x2 = (i / 10) % 10;
		x3 = (i / 100) % 10;
		if (x1*x1*x1 + x2 * x2*x2 + x3 * x3*x3 == i)
			printf("%d ", i);
	}
	printf("\n");
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int n, i;
	scanf_s("%d", &n);
	printf("%d=", n);
	for (i = 2; 1; i++)
	{
		if (n%i == 0 && n != i)
		{
			n = n / i;
			printf("%d*", i);
			i = 1;
		}
		if (n == i)
		{
			printf("%d", i);
			break;
		}
	}
	printf("\n");
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	float n;
	char m;
	scanf_s("%f", &n);
	m = n >= 90 ? 'A' : n >= 60 ? 'B' : 'C';
	printf("The score is %c\n", m);
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int x, y, i, j, k;
	printf("Please input two number:");
	scanf_s("%d,%d", &x, &y);
	for (i = 1; 1; i++)
		if (i%x == 0 && i%y == 0)
			break;
	for (j = 1; j <=(x < y ? x : y); j++)
		if (x%j == 0 && y%j == 0)
			k = j;
	printf("The two number least common multiple:%d\nThe two number greatest common divisor:%d\n", i, k);
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int x, y, i, j, a, b, t;
	printf("Please input two number:");
	scanf_s("%d,%d", &x, &y);
	if (x < y)
	{
		t = x;
		x = y;
		y = t;
	}
	a = x;
	b = y;
	while (b != 0)//辗转相除法
	{
		t = a % b;
		a = b;
		b = t;
	}
	printf("The two number least common multiple:%d\nThe two number greatest common divisor:%d\n", x*y / a, a);
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	void char_geshu(char a[], int b[]);
	char a[100];
	int b[5] = { 0 };
	gets_s(a);
	char_geshu(a, b);
	printf("大写字母%d个\n小写字母%d个\n数字%d个\n空格%d个\n其他%d个\n", b[0], b[1], b[2], b[3], b[4]);
	system("pause");
	return 0;
}
void char_geshu(char a[], int b[])
{
	int i;
	for (i = 0; a[i] != '\0'; i++)
		if (a[i] >= 'A'&&a[i] <= 'Z') b[0]++;
		else if (a[i] >= 'a'&&a[i] <= 'z') b[1]++;
		else if (a[i] >= '0'&&a[i] <= '9') b[2]++;
		else if (a[i] == ' ') b[3]++;
		else b[4]++;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int n, x, i, s = 0, d;
	scanf_s("%d,%d", &n, &x);
	for (i = 1; i <= n; i++)
	{
		if (i == 1) d = x;
		else d = d * 10 + x;
		if (i != n)
			printf("%d+", d);
		else
			printf("%d=", d);
		s = s + d;
	}
	printf("%d\n", s);
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int i, j, s, n;
	scanf_s("%d", &n);
	printf("%d以内的完数:",n);
	for (i = 1; i <= n; i++)
	{
		s = 0;
		for (j = 1; j < i; j++)
			if (i%j == 0) 
				s = s + j;
		if (s == i)
			printf("%d ", i);
	}
	printf("\n");
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	float h, s = 0, x;
	int n, i;
	scanf_s("%f,%d", &h, &n);
	x = h;
	for (i = 1; i <= n; i++)
	{
		s = s + h;
		h = h / 2;
		s = s + h;
	}
	printf("小球在%f米高第十次落地共经过%f米,反弹为%f米高\n",x, s - h, h);
	system("pause");
	return 0;
}
11~20
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int i, j, k, x = 0;
	for (i = 1; i <= 4; i++)
	{
		for (j = 1; j <= 4; j++)
		{
			if (j == i) continue;
			for (k = 1; k <= 4; k++)
			{
				if (k == j || k == i) continue;
				printf("%d\t", i * 100 + j * 10 + k);
				x++;
			}
		}
	}
	system("pause");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
	float money, bonus;
	int x;
	scanf_s("%f", &money);
	x = (int)(money / 100000);
	switch (x)
	{
	case 0:bonus = money*0.1; break;
	case 1:bonus = (money - 100000)*0.075+100000*0.1; break;
	case 2:
	case 3:bonus = (money - 200000)*0.05+100000*0.175; break;
	case 4:
	case 5:bonus = (money - 400000)*0.03 + 100000 * 0.175 + 200000 * 0.05; break;
	case 6:
	case 7:
	case 8:
	case 9:bonus = (money - 600000)*0.015 + 100000 * 0.175 + 200000 * 0.08; break;
	case 10:bonus = (money - 1000000)*0.01 + 100000 * 0.175 + 200000 * 0.08 + 400000 * 0.015; break;
	}
	printf("%f\n", bonus);
	system("pause");
	return 0;
}
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
	int i = 0, x, y;
	while (1)
	{
		x = sqrt(i + 100);
		y = sqrt(i + 168);
		if (x*x == i + 100 && y * y == i + 168)
			break;
		i++;
	}
	printf("%d\n", i);
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct date
{
	int year;
	int month;
	int day;
};
int main()
{
	struct date a;
	int i,s=0,b[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }, c[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
	scanf_s("%d %d %d", &a.year, &a.month, &a.day);
	if ((a.year % 4 == 0 && a.year % 100 != 0) || a.year % 400 == 0)
		for (i = 0; i < a.month - 1; i++)
			s = s + c[i];
	else
		for (i = 0; i < a.month - 1; i++)
			s = s + b[i];
	s = s + a.day;
	printf("%d %d %d is %dst day\n",a.year,a.month,a.day,s);
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int a[100], n, i, j, k, t;
	scanf_s("%d", &n);
	printf("please input %d number:\n", n);
	for (i = 0; i < n; i++)
		scanf_s("%d", &a[i]);
	/*for (i = 0; i < n - 1; i++)
		for(j=0;j<n-i-1;j++)
			if (a[j] > a[j + 1])
			{
				t = a[j];
				a[j] = a[j + 1];
				a[j + 1] = t;
			}*/
	for (i = 0; i < n - 1; i++)
	{
		k = i;
		for (j = i + 1; j < n; j++)
			if (a[k] > a[j]) k = j;
		if (k != i)
		{
			t = a[k];
			a[k] = a[i];
			a[i] = t;
		}
	}
	printf("min->max\n");
	for (i = 0; i < n; i++)
		printf("%d ", a[i]);
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	printf("Hello C-world!\n");
	printf("   *******\n");
	printf("  *\n");
	printf(" *\n");
	printf(" *\n");
	printf(" *\n");
	printf("  *\n");
	printf("   ********\n");
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	char a = 176, b = 219;
	int i;
	printf("%c%c%c%c%c\n", b, a, a, a, b);
	printf("%c%c%c%c%c\n", a, b, a, b, a);
	printf("%c%c%c%c%c\n", a, a, b, a, a);
	printf("%c%c%c%c%c\n", a, b, a, b, a);
	printf("%c%c%c%c%c\n", b, a, a, a, b);
	for (i = 1; i <= 256; putchar(a), i++)
		a = (char)i;
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int x, y;
	for (x = 1;x <= 9; x++)
	{
		for (y = 1; y <= x; y++)
		{
			if ((x == 3 && y == 3) || (x == 4 && y == 3)) printf(" ");
			printf("%d*%d=%d ", y, x, x*y);
		}
		printf("\n");
	}
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int i, j;
	for (i = 0; i < 8; i++)
	{
		for (j = 0; j < 8; j++)
			if ((i + j) % 2 == 0)
				printf("%c",29);
			else
				printf("  ");
		printf("\n");
	}
	system("pause");
	return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int i, j;
	printf("*_*\n");
	for (i = 1; i < 11; i++)
	{
		for (j = 1; j <= i; j++)
		{
			printf("%c", 29);
			if(j == i)
				printf("*_*");
		}
		printf("\n");
	}
	system("pause");
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值