- 论坛徽章:
- 0
|
4_大数运算_type.h
-
- #ifndef DASHU_T_H
- #define DASHU_T_H
- #include "0_问题.h"
- #include "6_常用.h"
- #include "3_组合验算_type.h"
- typedef int DASHU_t[WEISHU] ; //大数类型
-
- #endif // DASHU_T_H
复制代码
4_大数运算_function.h
-
- #ifndef DASHU_F_H
- #define DASHU_F_H
- #include "4_大数运算_type.h"
-
- #include <stdio.h>
- #include "3_组合验算_function.h"
-
- extern void qiu_mi ( DASHU_t * const , const int , int ) ;
- extern void fuzhi ( DASHU_t * const , const int ) ;
- extern void cheng ( DASHU_t * const , DASHU_t * const , const int );
- extern void jiaru ( DASHU_t * const , DASHU_t * const );
- extern void shuchu ( DASHU_t * const );
- extern void copy_ds( DASHU_t * const , DASHU_t * const ) ;
- extern SF xiaoyu ( DASHU_t * const , DASHU_t * const ) ;
- extern SF chaoguo_ws ( DASHU_t * const ) ;
- extern SF bugou_ws ( DASHU_t * const ) ;
- extern SF xiangtong ( DASHU_t * const , SHUZI_GESHU_t * const ) ;
- #endif // DASHU_F_H
复制代码
4_大数运算.c
-
- #include "4_大数运算_function.h"
- extern void shuchu( DASHU_t * const p_ds )
- {
- int *w = *p_ds , *t = *(p_ds+1) -1;
- int i;
-
- while( t > w && *t == 0) //前面的0不输出
- t--;
-
- for ( i = t - w ; i >= 0 ; i-- )
- printf("%d" , w[i]);
- putchar('\n');
- }
- extern void copy_ds ( DASHU_t * const p_zd, DASHU_t * const p_qd )
- {
- int i ;
- for (i = 0 ; i < GESHU(*p_zd) ; i++ )
- (*p_zd)[i] = (*p_qd)[i] ;
- }
- //判断*p_he的组合是否与*p_szzh相同
- SF xiangtong ( DASHU_t * const p_he , SHUZI_GESHU_t * const p_szzh )
- {
- SHUZI_GESHU_t szgs ;
- int i ;
- qing0 ( & szgs ) ;
- for (i = 0 ; i < GESHU(*p_he) ; i++ )
- szgs[(*p_he)[i]]++;
-
- for(i=0;i<GESHU(szgs);i++)
- if(szgs[i]!=((*p_szzh)[i]))
- return FOU ;
-
- return SHI;
- }
- //进位
- static void jinwei( DASHU_t * const p_ds)
- {
- int *q = *p_ds ;
- while ( q < *( p_ds + 1) - 1 ){
- * ( q + 1 ) += * q / JINZHI ;
- * q++ %= JINZHI ;
- }
- }
- //小于
- extern SF xiaoyu ( DASHU_t * const p_ds1 , DASHU_t * const p_ds2 )
- {
- int i;
- for( i = GESHU(*p_ds1) - 1 ; i >= 0 ; i -- ){
- if( (*p_ds1)[i]<(*p_ds2)[i] )
- return SHI ;
- if( (*p_ds1)[i]>(*p_ds2)[i] )
- return FOU ;
- }
- return FOU ;
- }
- //将*p_js累加入*p_he
- extern void jiaru( DASHU_t * const p_he , DASHU_t * const p_js)
- {
- int i;
- for(i=0;i<GESHU(*p_he);i++)
- (*p_he)[i] += (*p_js)[i];
-
- jinwei(p_he) ;
- }
- //判断是否超过WEISHU
- extern SF chaoguo_ws ( DASHU_t * const p_ds )
- {
- if( p_ds[1][-1] >= JINZHI ){
- return SHI ;
- }
- return FOU;
- }
- //判断是否位数不到WEISHU
- extern SF bugou_ws ( DASHU_t * const p_ds )
- {
- if( p_ds[1][-1] == 0 )
- return SHI ;
- return FOU;
- }
- //cs2*(*p_cs1)=>(*p_ji)
- extern void cheng ( DASHU_t * const p_ji , DASHU_t * const p_cs1 , const int cs2)
- {
- int *p = *p_ji ,*q = *p_cs1;
- while ( p < * ( p_ji + 1) )
- *p++ = *q++ * cs2 ;
-
- //进位
- jinwei( p_ji );
- }
- //求i的n次幂,放在 * p_ds 中
- extern void qiu_mi ( DASHU_t * const p_ds , const int i , int n )
- {
- fuzhi ( p_ds , i ) ;
- while ( --n > 0 )
- cheng ( p_ds , p_ds , i);
- }
- //赋值,大于JINZHI的数也可以
- extern void fuzhi ( DASHU_t * const p_ds , const int i )
- {
- int *q = *p_ds ;
- *q = i ;
- while ( q < *( p_ds + 1) - 1){
- * ( q + 1 ) = * q / JINZHI ;
- * q++ %= JINZHI ;
- }
- }
复制代码 |
|