首页 > 代码库 > c语言100编程实例
c语言100编程实例
第一章
#include<stdio.h>
#include<math.h>
void fun_1()//绘制余弦直线
{
double y;
int m, x;
for (y = 1; y >= -1; y -= 0.1)
{
m = acos(y)*10;
for (x = 1; x < m; x++)printf(" ");
printf("*");
for (; x < 62 - m; x++)printf(" ");
printf("*\n");
}
int x_1, y_1;
x_1 = 0;
for (y_1 = 0; y_1 <= 10; y_1++)
for(x_1=0;x_1<=y_1;x_1++){
if(x_1==y_1) {
printf("*\n");
}
else {
printf(" ");
}
}
}
void fun_2() {
int i, max, min, sum=0, num[4] = {20,90,85,84};
max = min = num[0];
printf("max%d\n", max); printf("min%d\n", min);
printf("score:\n");
for (i = 0; i < 4; i++)
printf("%d\n", num[i]);
for (i = 0; i < 4; i++)
{
sum += num[i];
if (max < num[i])
{
max = num[i];
}
if (min > num[i])min = num[i];
}
sum = sum - max - min;
printf("avg%dmin%dmax%d", sum / 2,min,max);
}
void fun_3() {
int i;
long j;//N的数值
j = 555555;
for (i = 999; i > 100; i--)
{
if (j%i == 0)
{
printf("factor:%d", i);
break;
}
}
}
void fun_4() {
int x, y,last=1;
x = 13;
for (y = 13; y > 0; y--)
{
last = last*x%1000;
}
printf("%d",last);
}
void fun_5()
{
int a, count = 0;
for (a = 5; a <= 100; a = a + 5)
{
count++;
if (!(a % 25))count++;
}
printf("%d",count);
}
void fun_6()
{
int a, b, c, count=0;
for (a = 1; a <= 5; a++)
for (b = 1; b <= 5; b++)
for (c = 1; c <= 5 && a != b; c++)
if (c != a&&c != b)count++;
printf("%d",count);
}
void fun_7()
{
int n = 13,i,j;
for (i = 0; i < n; i++) {
for (j = 0; j < 12-i; j++)printf(" ");
for (j = 1; j < i + 2; j++)printf("%6d", fun_7_f(i, j));
printf("\n");
}
}
int fun_7_f(int x,int y)//fun_7子函数进行递归
{
int z;
if (y == 1 || y ==x + 1)return 1;
z = (x - 1, y - 1) + (x - 1, y); return z;
}
void fun_8()
{
int data[16];
int i = 0;
int x=98;
printf("%d\n", x);
for (i = 0;i<8; i++)
{
data[i] = x % 2;
x = x / 2;// printf("%d\n", x);
//printf("%d\n", data[i]);
}
for (i = 8; i > 0; i--)
{
if (data[i] == 1)
for (; i >= 0; i--)printf("%d", data[i]);
}
}
int main()
{
//fun_1();//绘制余弦直线
//fun_2();//歌星大奖赛
//fun_3();//求最大约数
//fun_4();//高次方数的尾数
//fun_5();//阶层尾数0个数
//fun_6();//三个小朋友分五本书
//fun_7();//杨辉三角
//fun_8();//二进制转换
return 0;
}
c语言100编程实例