編寫程式,設n是四位數,它的9倍恰好是其反序數,求n的值

時間 2022-04-09 23:33:29

1樓:好名字都被取了

先寫乙個針對四位數反序數的函式,主函式裡面用for迴圈遍歷所有的四位數便可。

#include

#include

#include

int nixu (int a);

main()

system("pause");

}// 函式功能:實現4位數的逆序

int nixu (int a)

return c;}

2樓:

設n是乙個四位數,它的9倍恰好是其反序數,求n。反序數就是將整數的數字倒過來形成的整數。例如:1234的反序數是4321。

*問題分析與演算法設計

可設整數n的千、百、十、個位為i、j、k、l,其取值均為0~9,則滿足關係式:

(i*103+j*102+10*k+l)*9=(l*103+k*102+10*j+i)

的i、j、k、l即構成n。

*程式說明與注釋

#include

int main()

*執行結果

the number satisfied states condition is:1089

c語言 設n是乙個四位數,它的9倍恰好是其反序數(例如:123的反序數是321),求n的值。

3樓:匿名使用者

設a,b,c,d為這個四位數的千百個十數

判斷條件為9*(1000*a+100*b+10*c+d)=1000*d+100*c+10*b+a

你用4個for迴圈就可以找出,必須a的範圍是1到9,其他都是0~9

4樓:匿名使用者

如果還是4位數,那麼這個4位數 只有1000到1111。

#include

int main()

return 0;}

5樓:匿名使用者

#include

void main()}}

}}}結果是1089;

設n是乙個4位數,它的9倍恰好是其反序數,試程式設計求n的值

6樓:諾諾百科

設n的第一位數是x1,第二位數是x2,第三位數是x3,第四位數是x4。

首先,n的反序數任然是乙個四位數,乙個四位數乘9仍然是四位數,第一位x1只能等於1;

第二位只能等於1或0。

根據該問題列式:(x1*1000+x2*100+x3*10+x4)*9=x4*1000+x3*100+x2*10+x1*1

求解得x1=1,x2=0,x3=8,x4=9

n為1000a+100b+10c+d,9n=9(1000a+100b+10c+d)=1000d+100c+10b+a(其中a,b,c,d均為整數),先宣告程式頭,分別定義a=1,b=0,c=0,d=0,

程式1:if(9(1000a+100b+10c+d)=1000d+100c+10b+a),

n=1000a+100b+10c+d,

if else 程式2

if else 程式3

if else 程式4

if else 程式5

定義程式2:if( b<=8)

b=b+1,

程式1,

定義程式3:if( c<=8)

c=c+1,

程式1,

定義:程式4 if (b<=8)

b=b+1,

程式2;

定義:程式5 if(a<=8)

a=a+1,

程式2,

if else n不存在。

7樓:匿名使用者

準備材料:電腦(windows系統),freebasic程式設計軟體及編譯器(網上會有)

建立乙個新文件,輸入以下命令:

dim as integer a,b,c,d,w,x,y,z,na=1000

b=0c=0

d=0do

w=a/1000

x=b/10

y=c*10

z=d*1000

n=a+b+c+d

if 9*n=w+x+y+z then

print n

sleep

stop

else

d=d+1

if d=10 then

c=c+10

d=0if c=100 then

b=b+100

c=0if b=1000 then

a=a+1000

b=0if a=10000 then

stop

end if

end if

end if

end if

end if

loop

輸入後儲存,點開"run"下拉列表,點選"compile",在同乙個選單中點"quick run",這時候會彈出乙個視窗,顯示的就是答案。

8樓:伊夢山

public class test }}

}}執行結果:1089x9=9801

9樓:匿名使用者

a,b,c,d四重迴圈,

如果(a*1000+b*100+c*10+d)*9=d*1000+c*100+b*10+a 則結束迴圈。

n=a*1000+b*100+c*10+d根據程式語言編就可以了。

10樓:射手掃黃大蝦

n為1000a+100b+10c+d,9n=9(1000a+100b+10c+d)=1000d+100c+10b+a(其中a,b,c,d均為整數),先宣告程式頭,分別定義a=1,b=0,c=0,d=0,

程式1:if(9(1000a+100b+10c+d)=1000d+100c+10b+a),

n=1000a+100b+10c+d,

if else 程式2

if else 程式3

if else 程式4

if else 程式5

定義程式2:if( b<=8)

b=b+1,

程式1,

定義程式3:if( c<=8)

c=c+1,

程式1,

定義:程式4 if (b<=8)

b=b+1,

程式2;

定義:程式5 if(a<=8)

a=a+1,

程式2,

if else n不存在。

11樓:匿名使用者

得到結果為1089,其9倍為9801

12樓:螞蟻游過大海

static void main(string args)string output = "";

for (int j = array.count() - 1; j >= 0; j--)

if (convert.toint32(output) == n)}console.readline();}

13樓:匿名使用者

#include

using namespace std;

int main()

return 0 ;

}很簡單!n是1089!

14樓:匿名使用者

什麼語言什麼語言什麼語言什麼語言

編寫程式,有乙個四位整數,它的9倍恰好是其反序數(反序數例:1234與4321互為反序數)。按下列

編寫程式VB,vb程式編寫

private sub form load dim s 50 i as integerrandomize for i 0 to 49 s i int rnd 100 1list1.additem s i next end sub private sub command1 click dim n,i ...

編寫程式求,編寫程式 求1 3 5 7 99 101的值,java語言

include int main int i,j,sum1 0,sum2 0 for i 1 i 101 i 4 sum1 i for j 3 j 99 j 4 sum2 j printf sum d sum1 sum2 return 0 int a 0,b 0 for int i 1 i 101 ...

用vb語言編寫程式,用VB語言編寫程式

我用兩個文字框和乙個命令按鈕來實現 其中文字框 text1 用來存放 輸入資料 text2用來存放處理後的結果 用command1實現以上功能 private sub command1 click text2.text val text1.text 10end sub 你把要求說的不太詳細,我只是按...

編寫程式,free pascal語言

var a integer x,y real begin read x if x 1 then a 1 else a trunc x 10 case a of 1 y 0 0 y x 1 y 10 2,3 y 0.5 x 20 else y 2 x 40 end write y 0 1 end.用了...

利用組合語言編寫程式,利用組合語言編寫程式

採納答案,用錯了語言。題目說 片內ram.這應該是 51 微控制器的。下面的程式,是求a b的平方和,存入c單元。mov a,30h call fing fang mov 32h,a mov a,31h call fing fang add a,32h mov 32h,a sjmp fing fan...