51c语言趣味编程100例,c趣味编程100例

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

using namespace std;

void z1();

void z2();

void z3();

void z4();

void z5();

void z6();

void z7();

void z8();

int c3(int, int);

int draw(int(*)(double), int(*)(double), int);

void z9();

string ten2(int);

void z10();

int main()

{

z1();

system("PAUSE");

z2();

system("PAUSE");

z3();

system("PAUSE");

z4();

system("PAUSE");

z5();

system("PAUSE");

z6();

system("PAUSE");

z7();

system("PAUSE");

z8();

system("PAUSE");

z9();

system("PAUSE");

z10();

system("PAUSE");

return EXIT_SUCCESS;

}

int draw(int(*f)(double x), int(*g)(double x), int z = 0)

{

int m, yy, n;

double y;

const int M = 62;

string s1, s2;

for (int i = 0; i 

s1 += ' ';

for (yy = 0; yy <= 20; yy++)

{

y = yy / 10.0;

s2 = s1;

m = (*f)(y);

s2[m] = '*';

s2[M - m] = '*';

if (z)

{

n = (*g)(y);

if (n  0)

s2[n] = '+';

}

cout <

}

cout <

}

/* TODO (#1#): 绘制余弦曲线 */

int f1(double x)

{

return (int)(acos(1-x) *10);

}

int f3(double x)

{

return 31-(int)(25 *sqrt(1-(x - 1)*(x - 1)));

}

int f2(double x)

{

return (int)(45 *(x - 1) + 31);

}

void z1()

{

draw(f1, f1);

return ;

}

/* TODO (#1#): 绘制余弦曲线和一条直线

*/

void z2()

{

draw(f1, f2, 1);

return ;

}

void z3()

{

/* TODO (#1#): 绘制圆 */

draw(f3, f1);

return ;

}

void z4()

{

/* TODO (#1#): 唱歌比赛

去掉最高分和最低分得到平均分 */

int max, min, sum = 0;

int ii[10] =

{

1, 2, 3, 4, 5, 6, 7, 8, 9, 11

};

max =  *max_element(ii, ii + 10);

min =  *min_element(ii, ii + 10);

sum = accumulate(ii, ii + 10, 0);

cout <

cout <

cout <

cout <

return ;

}

void z5()

{

/* TODO (#1#): 555555的最大的三位数约数是多少 */

long j;

int i;

j = 555555;

for (i = 999; i > 99; i--)

if (!(j % i))

{

cout <

break;

}

cout <

return ;

}

void z6()

{

/* TODO (#1#): 13的13次方的最后三位数是多少 */

long j, y, kk = 1;

int i;

j = 13;

y = 13;

for (i = 1; i <= y; i++)

kk *= j, kk %= 1000;

cout <

cout <

return ;

}

void z7()

{

/* TODO (#1#): 100 !的末尾有多少个0 */

int n, count = 0, i, j;

n = 100;

for (i = 5; i <= n; i += 5)

{

count++;

for (j = 25; j <= n; j *= 5)

if (!(i % j))

count++;

}

cout <

cout <

return ;

}

void z8()

{

/* TODO (#1#): 5个取3个的排列的总数以及方法 */

int n, count = 1;

cout <

vector  ve1;

set  se1;

for (int i = 1; i 

ve1.push_back(i);

while (next_permutation(ve1.begin(), ve1.end()))

{

n = ve1[0] *100+ve1[1] *10+ve1[2];

if (se1.find(n) == se1.end())

{

se1.insert(n);

cout <

ve1[2] <

}

}

cout <

return ;

}

void z9()

{

/* TODO (#1#): 计算杨辉三角形 */

int a, b, c = 12, count = 1;

cout <

for (b = 1; b <= c; b++)

{

for (a = 1; a <= c - b; a++)

cout <

for (a = 1; a <= b + 1; a++)

{

cout <

}

cout <

}

return ;

}

int c3(int x, int y)

{

if (y == 1 || y == x + 1)

return 1;

return c3(x - 1, y - 1) + c3(x - 1, y);

}

/* TODO (#1#): 把10进制度变成2进制 */

string ten2(int x1)

{

string s1;

char ch[256];

s1 = itoa(x1, ch, 2);

return s1;

}

/* TODO (#1#): 把10进制度变成2进制 */

void z10()

{

int num;

num = 256;

cout <

cout <

return ;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值