要求自定义一个函数void dightCount(int x,intdight,intsquare),其中x是用户输入的一个整数,dight和square分别是整数x的个位数与x的平方,编写main函数,并在其中调用函数dightCount(),分别打印整数x的个位数与x的平方.
举例:
输入 2023
输出 个位数为3
平方为4092529
个位数求余10就行了,平方直接x*x
#include <stdio.h>
void dightCount(int x,int *dight,int *square)
{
*dight = x%10;
*square = x*x;
}
int main()
{
int n,dight=0,square=0;
scanf("%d",&n);
dightCount(n,&dight,&square);
printf("个位数为%d\n",dight);
printf("平方为%d\n",square);
return 0;
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!