两个题算了很久不会做啊,上来求助了。。。

作者在 2010-04-18 17:40:03 发布以下内容

函数

 

一、实验目的

进一步掌握子函数的定义、函数的调用方法。

熟练函数调用中参数的传递过程。

3.熟练编写子函数。

 

二、实验内容

1输入两个正整数an,求a+aa+aaa+aaaa+aaa…ana)之和。要求定义并调用函数f(a,n),它的功能是返回aaa…ana)。

2)输入两个正整数,求最大公约数和最小公倍数。其中最大公约数和最小公倍数用子函

数实现。

 

问题 | 阅读 901 次
文章评论,共12条
breezemiss
2010-04-18 18:20
1
看来C你学的比我好。
红色杀戮(作者)
2010-04-18 23:38
2
<div class="quote"><span class="q"><b>breezemiss</b>: 看来C你学的比我好。</span></div>不会吧,呵呵,我也是不会啊,上来求救来了,共同努力吧…
小兔子慢慢
2010-04-19 08:53
3
#include&lt;stdio.h&gt;<br />
int f(int a,int n)<br />
{int i;<br />
 int s=0;<br />
 for(i=1;i&lt;=n;i++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s=s+a;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a=a*10;<br />
 <br />
 <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
return s;<br />
<br />
}<br />
<br />
<br />
void main()<br />
{int m,n,i,a,sum=0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; scanf(&quot;%d&quot;,&amp;m);<br />
&nbsp; &nbsp; scanf(&quot;%d&quot;,&amp;n);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(i=1;i&lt;=n;i++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; a=f(m,i);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum=sum+a;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
<br />
printf(&quot;%d\n&quot;,sum);<br />
<br />
}
红色杀戮(作者)
2010-04-19 11:23
4
<div class="quote"><span class="q"><b>小兔子慢慢</b>: #include&lt;stdio.h&gt;<br />
int f(int a,int n)<br />
{int i;<br />
 int s=0;<br />
 for(i=1;i&lt;=n;i++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s=s+a;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a=a*10;<br />
 <br />
 <br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
return s;<br />
<br />
}<br />
<br />
<br />
void main()<br />
{int m,n,</span></div>谢啦…<br />
<br />
刚才去问了一下老师那个第二题,她给我举了个例子:<br />
36,27<br />
36%27=9<br />
27%9=0<br />
最大公约数=9<br />
最小公倍数=36*27/9=108<br />
<br />
汗,这么个算法我还真想不到…<br />
呵呵,有兴趣的朋友就写写吧…
红色杀戮(作者)
2010-04-20 19:11
5
没有人写啊,这是我自己写的第二题的…大家看看<br />
/***代码开始***/<br />
int f(int a,int b)<br />
{<br />
&nbsp;&nbsp;int t;<br />
&nbsp;&nbsp;while(t=a%b!=0)&nbsp; &nbsp;/*这个循环是算最大公约数的*/<br />
&nbsp;&nbsp;{<br />
&nbsp; &nbsp; t=a%b;<br />
&nbsp; &nbsp; a=b;<br />
&nbsp; &nbsp; b=t;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;return(b);&nbsp; &nbsp;/*b的最后值就是最大公约数*/<br />
}<br />
int F(int a,int b)<br />
{<br />
&nbsp;&nbsp;int t;<br />
&nbsp;&nbsp;t=a*b/f(a,b);&nbsp; &nbsp;/*这个是算最小公倍数的*/<br />
&nbsp;&nbsp;return(t);<br />
}<br />
void main()<br />
{<br />
&nbsp;&nbsp;int a,b,m,n;<br />
&nbsp;&nbsp;printf(&quot;Input a,b:\n&quot;);<br />
&nbsp;&nbsp;scanf(&quot;%d,%d&quot;,&amp;a,&amp;b);<br />
&nbsp;&nbsp;m=f(a,b);<br />
&nbsp;&nbsp;n=F(a,b);<br />
&nbsp;&nbsp;printf(&quot;\nm=%d\nn=%d&quot;,m,n);<br />
&nbsp;&nbsp;getch();<br />
}<br />
/***代码结束***/<br />
唉,英语没学好,都是用字母表达的...<br />
欢迎交流...
小兔子慢慢
2010-04-21 08:10
6
<div class="quote"><span class="q"><b>红色杀戮</b>: 谢啦…<br />
<br />
刚才去问了一下老师那个第二题,她给我举了个例子:<br />
36,27<br />
36%27=9<br />
27%9=0<br />
最大公约数=9<br />
最小公倍数=36*27/9=108<br />
<br />
汗,这么个算法我还真想不</span></div>辗转相除法
JAVATWO
2010-04-22 11:38
7
我不会C++来看看
红色杀戮(作者)
2010-04-22 21:52
8
<div class="quote"><span class="q"><b>JAVATWO</b>: 我不会C++来看看</span></div>呵呵,是用C的,C++我也不懂额…<br />
你学的什么啊?
爱OO你
2010-04-24 01:13
9
我也不懂啊!!我学JAVA,来看看!!
红色杀戮(作者)
2010-04-24 22:34
10
<div class="quote"><span class="q"><b>爱OO你</b>: 我也不懂啊!!我学JAVA,来看看!!</span></div>呵呵,我学C的,你怎么把我加JAVA群里啊。。。
爱OO你
2010-04-25 00:14
11
呵呵,我学HACKER 也要看C啊!!!<br />
加你到JAVA 把这两个编程都看看,有助于对比学习吗??<br />
呵呵
Imtheone
2010-04-25 22:07
12
java难吗,我也想学 啊,
游客请输入验证码
浏览4552次
文章分类