编写一个程序,输入一个正整数,并做以下运算:如果为偶数,除以2,如果为奇数,乘3加1。得到的结果再按上

要求运算,直到最后的结果为1。然后给出经过了多少次这样的运算才得到数1。(要求用C#回答)

1 Do not go overboard on the line, I let a friend get married next of kin, he and other male relatives in the home, the results to the woman would not let us into the house, and then have to come up with jewelry worth 5000 then pro-when the entry fee, I We were a few guys who rely on it Cou Cou it has only over 2000, to the groom to call, he said, people first take out, and then to either the card directly into the account the woman's relatives, the results do not agree with people distracted, non- to ready-made jewelry, instrument allows to engage well done my friend, and directly with the phone is not connected to us yelling, and all floats all back to the hotel, this time for all when he invited all friends and family to eat dinner meal. We walked away without a word, the results to the 11 o'clock a woman called me and asked what the situation, not for the wisdom for pick up, this man was a straightforward statement that you love does not end, I invited my buddy the whole when the They rub meal ... ... 10 minutes away from the poor 12 time, the bride wearing a wedding dress to play the hotel ... ...

-------------------- -------------------------------------------------- ------------------------------------------

2 on meeting a colleague to pick up the bride, the bride home, life and death allowed to enter, eventually 11:30 we had not let the door
fire was the groom, and a phone call in the past: Lv, love marriage is not married, does not appear 12:18 In front of the hotel, after never even think about into my door
call is finished the hotel
groom bride went home and went to the last time gave his daughter an honest past

------ -------------------------------------------------- -------------------------------------------------- ------

3 kicks can look, but do not fire. One of my friends got married.
other Dumen kneeling at the door to let him bark like a dog let him go, to discuss the failed my friend really called.
But the man called over there to finish also allowed to enter the fire, not directly on the back end up.
there an hour later the woman called me and asked after the father of the man directly refused, saying see you directly to the Bureau of Civil Affairs.
divorce. (The wedding before the licensing of the)

------------------------------------ -------------------------------------------------- --------------------------

4 a wedding company boss told me! Absolutely true!
That day is not, not busy, the boss went to his truck driving, tail is his company's cars.
from 7 o'clock in the groom take the bride went upstairs,mac make up brushes, not down 11 points!
anger the boss! A look ..........
up on getting the bride and groom! But before promising a large LCD TV, the groom did not give to buy, buy him now! After the meeting, said the groom, the bride not! Results do not buy do not say that! Finally, the groom
anger! Said to ask you again: do not follow me now?
bride say go!
turned just as the best man groom, camera and other people say: go!
a team does not utter a sound downstairs!
boss asked him where to go?
to certain quarters, he said. After
went to a girl knelt down, let her marry him, saying that we give her happiness, good to her!
kneeling for a long time ~
results to really take down a naked bride wedding!
the groom's face at this time also opened ~
boss said: I test! Ah man you have the bench?
bridegroom say you pulling my heart out! This is my classmate, always loved me, I used to senseless ... ...
then allegedly went to downtown venue the bride!
and the bride's family began to trouble. The groom said she did not marry me,Wholesale sunglasses!
bride the next day to do the original divorce ~ going to a marriage certificate of his classmates!
powerful, right?

-------------------------------------------- -------------------------------------------------- ------------------

5 I have seen one, although the consequences not so serious, when the groom is anxious, Aoao turned to scold the two go under the bride's family on the NB, the meal for mercy, then who can not stand that scene. That nauseating point, my buddy that his wife love to a very tough battle, and he usually is very overbearing person, considerate of his wife s home. Pick up the bride that day, really Baibandiaonan, Han strokes are used, primarily very sick tricks all the ink the more than 2 hours, even with a hungry TM excited to give our side of the groom who tortured destroyed. Some things are not personal experience, the really hard to imagine

--------------------------------- -------------------------------------------------- -----------------------------

6 to help man the times when the best man,, TMD. Meow marry him when he does a group of aging mother doom me to the ground by the thigh to the call.
take your pants off at night when the skin on the thighs to help with the pants on TMD are attached. No swelling the entire 1 month. .
spend money to hire a maid of honor was Miss, to throw across the quilt on the bed was covered with the quilt off his shirt. How to say my buddy was: grass! I stretch out my quilt to the inside for robbing, paralysis touch 7.8 hand. .
lunch there once, had booked a table prepared 50 tables 5 tables, should be enough, with the result the woman home, a family and I all came, and get more than 60 tables. All the woman who, like family with a gift account for a table 100. Hotel also did not marry another location. Engage in very well done, a table that 2.3 positions. Man to his wife to their relatives crowded crowded Teng two tables out of the whole, the main man a few years we are not together so it all. The results can not, man a bite, take us to get a few lead tables in a restaurant

--------------------------- -------------------------------------------------- -----------------------------------
7 out of my house to have such a thing
I Costa Rica, to work in Beijing, the two suites (Beijing West Railway Station set, Tongzhou a), will be relatives by marriage, the other party: family has debt, not on land sales have to go back, you'll have to see.
was agreed that we would at home. Wedding day, then in the house of the bride Tongzhou, which more than 30 people (thousands of miles came from Hunan, Heilongjiang we only came home in 10 people) red envelopes, or allowed to enter; let my brother sing out loud , finished a; the woman's uncle said, finally, this is where their customs, got to 88,888. My brother to burn, this is my life seen my brother the most burning one, I followed a long burning, burning down the stairs over to, and directly say married. After that is it, nothing.
now my brother is still single and vowed to never marry in this life. True TNND tragedy

----------------------------------------- -------------------------------------------------- ---------------------

8
year when the next of kin to accompany brothers, directly under the Tiechu security door, the woman's home to look , and quickly to open the door.
not find the shoes, the bride refused to go out, almost directly to the bed to carried away to have the brothers began to hit the door frame.
that scene,Dior sunglasses, the bride almost started crying.

-------------------------------------------- -------------------------------------------------- ------------------

9 I really run into a similar, one to a wedding, the bride is holding Joe, the groom's father to kneel down, the groom looked so angry, and stupid not to marry the bride, who will advise not work, finally away from, said that the bride did not find the right for years nobody wanted her.
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-03-21
本人不会C#,算法相通,用c语言演示一下:
#include<stdio.h>
void main(void)
{
int zhengshu=0;
int result = 0;
scanf("%d\n",&zhengshu);
while(zhengshu!= 1)
{
if(zhengshu / 2 == 0)
{
zhengshu = zhengshu /2;
}else
{
zhengshu = zhengshu *3+1;
}
result ++;
}
printf("一共经过了%d次运算\n",result);
}
我没有测试,也没有编译,应该对的,你试试。。。本回答被提问者采纳
第2个回答  2011-03-21
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string input;
int intNum;
do
{
Console.WriteLine("Press 'Q' to exit. \n");
Console.Write("请输入一个整数: ");
input = Console.ReadLine();
if (int.TryParse(input, out intNum))
{
Console.WriteLine("共计算了{0}次!", Calc(intNum));
}
} while (input.ToUpper() != "Q");
}

static int Calc(int intNum)
{
int iCalcCount = 0;
int iResult = 0;
if (intNum == 1) return 0;
if (intNum % 2 == 0) //偶数
{
iCalcCount++;
iResult = intNum / 2;
Console.WriteLine("算式: {0} / 2 = {1}", intNum, iResult);
iCalcCount += Calc(iResult);
}
else
{
iCalcCount++;
iResult = intNum * 3 + 1;
Console.WriteLine("算式: {0} * 3 + 1 = {1}", intNum, iResult);
iCalcCount += Calc(iResult);
}
return iCalcCount;
}
}
}
第3个回答  2011-03-21
楼上的 应该是%2 代表余数 /2=0 那就是小于2了