首页 > 编程语言 > 详细

c语言代码编程题汇总 :程序求x的y的幂次方的最后3位数

时间:2017-03-12 15:14:48      阅读:311      评论:0      收藏:0      [点我收藏+]

求x的y的幂次方的最后3位数

程序代码如下:

 

 1     /*
 2         2017年3月12日14:07:05
 3         功能:程序求x的y的幂次方的最后3位数
 4     */
 5     #include"stdio.h"
 6     void fun(int);
 7     int main()
 8     {
 9         int x, y;
10         int x_power_y = 1;
11         printf("please int two number x and y :");
12         scanf("%d %d", &x, &y);
13         for (int i = 0; i < y; i++)
14         {
15             x_power_y *= x;
16         }
17         if (x_power_y < 999)
18         {
19             printf("the last three number of the x power y is %d ", x_power_y);
20         }
21         else
22         {
23             fun(x_power_y);                                                                    //大于999,进入调用函数
24         }
25 
26     }
27 
28     void fun(int x_power_y)
29     {
30         int first = x_power_y % 10;                                                            //此时求得是最后一位上的数值
31         int second = (x_power_y % 100 - first * 1) / 10;                                    //x_power_y % 100是最后两位上的数值
32         int thrid = (x_power_y % 1000 - second * 10 - first * 1) / 100;
33         printf("the last three number of the x power y is %d \n", thrid*100+second*10+first);
34     }
35     /*
36         总结;
37         在VC++6.0中显示的结果:
38         ——————————————————
39         please int two number x and y :11 3
40         the last three number of the x power y is 331
41         ——————————————————
42     */

 

c语言代码编程题汇总 :程序求x的y的幂次方的最后3位数

原文:http://www.cnblogs.com/wxt19941024/p/6537808.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!