求助C语言高手啊!!
1个回答
展开全部
提供加减乘除函数,你自己组织吧。
void
add(int
*a,int
*b,int
*c)
{
int
i,
carry
=
0;
for(i
=
N
-
1;
i
>=
0;
i--)
{
//
(a
+
b)
→
c
c[i]
=
a[i]
+
b[i]
+
carry;
if(c[i]
<
10000)
carry
=
0;
else
{
//进位
c[i]
=
c[i]
-
10000;
carry
=
1;
}
}
}
void
sub(int
*a,int
*b,int
*c)
{
//
(a -
b)
→
c
int
i,
borrow
=
0;
for(i
=
N
-
1;
i
>=
0;
i--)
{
c[i]
=
a[i]
-
b[i]
-borrow;
if(c[i]
>=
0)
borrow
=
0;
else
{
//借位
c[i]
=
c[i]
+
10000;
borrow
=
1;
}
}
}
void
mul(int
*a,int
b,
int
*c)
{
//
(a ×
b)
→
c
int
i,
tmp,carry
=
0;
for(i
=
N
-
1;
i
>=
0;i--)
{
tmp
=a[i]
*
b
+
carry;
c[i]
=
tmp
%
10000;
carry
=
tmp
/
10000;
}
}
void
div(int
*a,int
b,
int
*c)
{
//
//
(a ÷
b)
→
c
int
i,
tmp,remain
=
0;
for(i
=
0;
i
<
N;i++)
{
tmp
=
a[i]
+
remain;
c[i]
=
tmp
/
b;
remain
=
(tmp
%
b)
*
10000;
}
}
void
add(int
*a,int
*b,int
*c)
{
int
i,
carry
=
0;
for(i
=
N
-
1;
i
>=
0;
i--)
{
//
(a
+
b)
→
c
c[i]
=
a[i]
+
b[i]
+
carry;
if(c[i]
<
10000)
carry
=
0;
else
{
//进位
c[i]
=
c[i]
-
10000;
carry
=
1;
}
}
}
void
sub(int
*a,int
*b,int
*c)
{
//
(a -
b)
→
c
int
i,
borrow
=
0;
for(i
=
N
-
1;
i
>=
0;
i--)
{
c[i]
=
a[i]
-
b[i]
-borrow;
if(c[i]
>=
0)
borrow
=
0;
else
{
//借位
c[i]
=
c[i]
+
10000;
borrow
=
1;
}
}
}
void
mul(int
*a,int
b,
int
*c)
{
//
(a ×
b)
→
c
int
i,
tmp,carry
=
0;
for(i
=
N
-
1;
i
>=
0;i--)
{
tmp
=a[i]
*
b
+
carry;
c[i]
=
tmp
%
10000;
carry
=
tmp
/
10000;
}
}
void
div(int
*a,int
b,
int
*c)
{
//
//
(a ÷
b)
→
c
int
i,
tmp,remain
=
0;
for(i
=
0;
i
<
N;i++)
{
tmp
=
a[i]
+
remain;
c[i]
=
tmp
/
b;
remain
=
(tmp
%
b)
*
10000;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询