打印cos函数的形状:考虑cos(x)的对称性
void printCos()
{
double x,y,arc;
for(y=1;y>=-1;y-=0.1)
{
arc=acos(y)*10;
for(x=1;x<arc;x++)
{
printf(" ");
}
printf("*");
for(;x<64-arc;x++)
{
printf(" ");
}
printf("*\n");
}
}打印圆形状:
void printCircle()
{
const int NUM=30;
double x,y,cirX;
for(y=10;y>=-10;y--)
{
cirX=2.5*sqrt(100-y*y);
for(x=1;x<NUM-cirX;x++)
{
printf(" ");
}
printf("*");
for(;x<NUM+cirX;x++)
{
printf(" ");
}
printf("*\n");
}
}求555555约数中最大的三位数是多少:
约数的定义:对于任意整数N,除了1和他自身外,凡能整除N的数即为N的约数
void getGreatestDivisor()
{
long num;
int i,max=100;
printf("Please input a num\n");
scanf("%ld",&num);
for(i=999;i>=100;i--)
{
if(num%i==0)
{
printf("The max factor with 3 digits %ld is %d",num,max);
break;
}
}
}高次方数的尾数:求13的13次方的最后的三位数
乘法的规律:乘积的最后三位的值只与乘数和被除数的最后三位有关,与乘数和被除数的高位无关
void getLastThree()
{
int i,numX,numY,last=1;
printf("Input X and Y(X**Y)");
scanf("%d**%d",&numX,&numY);
for(i=1;i<=numY;i++)
{
last=last*numX%1000;
}
printf("The last three of %d -- %d is %d",numX,numY,last);
}输出形如aabb的四位完全平方数:n=a*1100+b*11
bool isSquare(double num)
{
int temp=(int)(sqrt(num)+0.5);//四舍五入取整
return temp*temp==num;
}
void getSquare()
{
int a,b,num;
for(a=1;a<=9;a++)
{
for(b=0;b<=9;b++)
{
num=a*1100+b*11;
if(isSquare(num))
{
printf("%ld is square",num);
}
}
}
}
借书方案:小明有5本书要借给A,B,C三位小朋友,若每人每次只能借一本,则有多少种不同的借法
实际上是一个排列组合问题即从5个中取3个进行排列的方法的总数。可以用穷举的方法
void borrowBook()
{
int a,b,c,count=0;
printf("Therer are different methods for XiaoMing to distribute books to 3 readers\n");
for(a=1;a<=5;a++)
{
for(b=1;b<=5;b++)
{
for(c=1;c<=5;c++)
{
if(a!=b&&a!=c&&b!=c)
{
printf("%2d: %d %d %d ",++count,a,b,c);
if(count%5==0)
{
printf("\n");
}
}
}
}
}
}
//计算1-1/x+1/x*x…
void Algo1()
{
int i,j,n;
double x,sum=0,indexValue=1;
printf("请输入x n\n");
scanf("%lf%d",&x,&n);
for(i=1;i<=n;i++)
{
sum+=indexValue;
indexValue*=(-1.0/x);
}
printf("sum的值是:%lf\n",sum);
}//变量的引用类型和非引用类型的区别void fa(int n)
{
n++;
printf("在函数fa中:n=%d\n",n);
}
void fb(int &n)
{
n++;
printf("在函数fa中:n=%d\n",n);
}
void Algo2()
{
int n=1;
printf("在主函数调用fa之前n的值:%d\n",n);
fa(n);
printf("在主程中,调用函数fa之后,调用函数fb之前:n=%d\n",n);
fb(n);
printf("在主程中,调用函数fb之后:n=%d\n",n);
}
本文通过C语言展示了如何打印cos函数和圆形的图形表示,并提供了求解特定数学问题的算法示例,包括寻找最大三位数约数、计算高次幂的尾数等。
10万+

被折叠的 条评论
为什么被折叠?



