1、數學表示式
1、編寫程式,其功能是:計算並輸出下列多項式的值:, 將結果存到外存root.txt中。
clear
set talk off
s=0input "請輸入n的值:" to n
for i=1 to n
s=s+sqrt(n)
endfor
?"s=",s
display memory like s to file root
set talk on
cancel
2、編寫程式,其功能是:計算並輸出下列多項式的值:
clear
set talk off
s=0input "請輸入n的值:" to n
for i=1 to n
s=s+1/i
endfor
?"s=",s
set talk on
cancel
3、編寫程式,其功能是:計算並輸出下列多項式的值:,並輸出結果。例如,若n=20,則s=6.506583。
clear
set talk off
s=0input "請輸入n的值:" to n
for i=1 to n
s=s+log(i)
endfor
s=sqrt(s)
?"s=",s
set talk on
cancel
4、編寫程式,計算表示式:直到。例如x=2.5,則函式值為:12.182494。
clear
set talk off
input "請輸入計算函式值的值:" to x
i=0s=1
n=1do while n>1e-6
i=i+1
n=n*x/i
if n>1e-6
s=s+n
endif
enddo
?"ex=",s
set talk on
return
5、找出100~999之間的所有「水仙花數」(窮舉法、統計)
clear
set talk off
for i=100 to 999
a=int(i/100)
b=int((i-a*100)/100)
c=i-a*100-b*10
if i==a^3+b^3+c^3
??iendif
endfor
set talk on
return
6、從鍵盤輸入10個數,然後找出其中的最大值和最小值。(找最大數、最小數)
clear
dime a(10)
for i=1to 10
input "請輸入數:" to a(i)
endfor
max=a(1)
for i=2to 10
if a(i)>max
max=a(i)
endif
endfor
min=a(1)
for i=2to 10
if a(i) min=a(i)
endif
endfor
?"最大數為:",max
?"最小數為:",min
return
7、任意輸入n個數,按由小到大的順序排列並顯示輸出。(排序演算法--選擇法排序)
clear
input "請輸入陣列的個數:" to n
dimension a(n)
for i=1 to n
input "請輸入數值資料:" to a(i) &&輸入陣列的元素
endfor
for i=1 to n-1
for j=i+1 to n
if a(i)>a(j)
temp=a(i)
a(i)=a(j)
a(j)=temp
endif
endfor
endfor
for i=1 to n &&輸出排序以後的陣列
??a(i)
endfor
cancel
8、求5的階乘值(5!=?)
clear
p=1for i=2 to 5
p=p*i
endfor
?"1*2*3*4*5=",p
cancel
9、計算 t=1!+2!+……+10! 即求階乘之和(雙迴圈)。
clear
s=1p=1
for i=2 to 10
for j=2 to i
p=p*j
endfor
s=s+p
endfor
?"s=1!+2!+……+10!=",s
cancel
10、多項式s=1+2+22+23+……+232,請設計乙個程式,求s的值。
clear
s=1p=1
for i=1 to 32
p=p*2
endfor
s=s+p
?"s=1+2+2^2+2^3+……+2^32=",s
cancel
2、矩陣的處理
編寫程式,完成的功能是:實現b=a+a』,即把矩陣a加上a的轉置,存放在矩陣b中。例如使用者輸入矩陣,其轉置矩陣為,程式輸出。
clear
dimension a(3,3)
dimension b(3,3)
dimension c(3,3)
for i=1 to 9
input "請給陣列賦值:" to a(i)
endfor
for i=1 to 3
for j=1 to 3
b(i,j)=a(j,i)
endfor
endfor
for i=1 to 3
for j=1 to 3
c(i,j)=a(i,j)+b(i,j)
endfor
endfor
for i=1 to 3
for j=1 to 3
c(i,j)
endfor
endfor
return
(2)求矩陣a對角線元素之和。
clear
s=0 dimension a(3,3)
for i=1 to 9
input "請給陣列賦值:" to a(i)
endfor
for i=1 to 3
s=s+a(i,i)
endfor
?"矩陣a對角線元素之和:" ,s
return
三、字串的處理
1、編寫乙個程式,它的功能是:將ss字串中所有下標為奇數字置上的字母轉換為大寫(若該位置上不是字母,則不轉換)。例如,若輸入「abc4efg」,則應輸出「abc4efg」。
set talk off
clear
accept "請輸入一串字元:" to ss
n=len(ss)
for i=1 to n step 2
aa=substr(ss, i,1)
if (aa>="a".and.aa<="z")
bb=upper(aa)
ss=stuff(ss,i,1,bb)
endif
endfor
?"輸出轉換後的字串ss:",ss
set talk on
cancel
2、程式的功能是:將s所指字串中ascii值為偶數的字元刪除,串中剩餘字元形成乙個新串放在t所指的陣列中。
例如,若s所指字串中的內容為:「abcdefg12345」,其中字元b的ascii碼值為偶數、…、字元2的ascii碼值為偶數、…、都應當刪除,其它依此類推。最後t所指的陣列中的內容應是:
「aceg135」。
set talk off
clear
accept "請輸入一串字元:" to s
n=len(s)
c=""
for i=1 to n
w=substr(s, i,1)
aci=asc(w) &&返回最左邊的乙個字元的ascii值。
if aci%2=0
s=stuff(s,i,1,c)
endif
endfor
?"輸出轉換後的字串s:",s
set talk on
cancel
3、編寫程式,實現將s所指字串中的所有數字字元移到所有非數字字元之後,並保持數字字串和非數字字串原有的先後次序。例如,原字串為:def35adh3kjsdf7,執行結果為:
defadhkjsdf3537
set talk off
clear
accept "請輸入一串字元:" to s
n=len(s)
c=""
b=""
for i=1 to n
w=substr(s, i,1)
if (w>="0".and.w<="9")
b=b+w
s=stuff(s,i,1,c)
i=i-1
endif
endfor
s=s+b
?"輸出轉換後的字串s:",s
set talk on
cance
4、假定輸入的字串中只包含字母和*號。請編寫程式,它的功能是:使字串中尾部的*號不得多於n個;若多於n個,則刪除多於的*號;若少於或等於n個,則什麼也不做,字串中間和前面的*號不刪除。
set talk off
clear
j=0accept "請輸入一串字元:" to s
input "請輸入使字串中尾部的*號最大值:" to n
ls=len(s)
for i=1 to ls
w=substr(s, i,1)
if w!="*"
j=0endif
if w
j=j+1 &&j用於統計串尾連續的*個數
endif
endfor
if j>n
s=left(s,ls-(j-n))
endif
?"輸出轉換後的字串s:",s
set talk on
cancel
5、(對字串排序處理)有5個英文單詞,分別為:word,excel,powerpoint,type,angle,要求設計出如下程式:
(1)在鍵盤上輸入數n(本例輸入5),把英文單詞放入名為x大小為n的陣列中
(2)顯示出x陣列中的英文單詞
(3)對陣列中的英文單詞從小到大排序
(4)顯示出排序後x陣列中英文單詞
set talk off
clear
input "請輸入陣列的個數:" to n
dimension a(n)
for i=1 to n
accept "請輸入一串字元:" to a(i)
endfor
for i=1 to n-1
for j=i+1 to n
if a(i)>a(j)
2023年普通專公升本考試程式設計題總結
一 數學表示式 1 編寫程式,其功能是 計算並輸出下列多項式的值 將結果存到外存root.txt中。2 編寫程式,其功能是 計算並輸出下列多項式的值 3 編寫程式,其功能是 計算並輸出下列多項式的值 並輸出結果。例如,若n 20,則s 6.506583。4 編寫程式,計算表示式 直到 例如x 2.5...
2023年普通專公升本考試程式設計題總結
1 數學表示式 1 編寫程式,其功能是 計算並輸出下列多項式的值 將結果存到外存root.txt中。clear set talk off s 0input 請輸入n的值 to n for i 1 to n s s sqrt n endfor s s display memory like s to ...
2023年安徽專公升本程式設計題總結
求和類 1.計算s 1!2!3!4!n s 0k 1 input n to n for i 1 to n k k i s s k endfor s2.求 sum 0 for i 1 to 21 step 2 sum sum i 3 endfor sum sum 3.有一分數序列,求前20項之和 m ...