1樓:紫薇參星
按照你的要求,把c語言程式轉換成python3語言的程式如下#!/usr/bin/python
# -*- coding: utf-8 -*-def printmatrix(n):
arr = [ [0 for i in range(20)] for i in range(20)]
curnum = 1
for index in range(1,n+1):
i =0
j = index-1
for k in range(1,index+1):
if index%2 == 1:
arr[i][j] = curnum
curnum=curnum+1
else:
arr[j][i] = curnum
curnum=curnum+1
i=i+1
j=j-1
for index in range(n+1,2*n):
i =index-n
j = n-1
for k in range(1,2*n-index+1):
if index%2 == 1:
arr[i][j] = curnum
curnum=curnum+1
else:
arr[j][i] = curnum
curnum=curnum+1
i=i+1
j=j-1
print ("the matrix is as follow:");
for i in range(0,n):
for j in range(0,n):
print (arr[i][j],"\t",end='')print ("")
printmatrix(4)
執行結果
the matrix is as follow:
1 3 4 10
2 5 9 11
6 8 12 15
7 13 14 16
求各位大神把下面的c語言程式編碼翻譯成python語言,謝謝的!!急呀!!
2樓:天剛沒亮
price1 = 4.5
price2 = 5.5
price3 = 5.5
thing1 = raw_input('please input the first thing you wang to bug\n')
print thing1
num1 = int(raw_input('please input the number you need\n'))
print num1
print 'the price is %f' % float(num1*price1)
thing2 = raw_input('please input the first thing you wang to bug\n')
print thing2
num2 = int(raw_input('please input the number you need\n'))
print num2
print 'the price is %f' % float(num2*price2)
thing3 = raw_input('please input the first thing you wang to bug\n')
print thing3
num3 = int(raw_input('please input the number you need\n'))
print num3
print 'the price is %f' % float(num3*price3)
print 'the final price is %f' % float(num1*price1+num2*price2+num3*price3)
3樓:匿名使用者
很願意幫助你完成方面其他方式交流嗎
求大佬把這段c語言轉換成python,謝謝! 10
4樓:匿名使用者
基本上一句一句轉就行了
C語言怎麼轉化成python,將一段c語言程式轉變為python程式,急!!!
要將c語言轉化為python,前提 1對c語言語法即python程式設計均熟練掌握 2對演算法相關有一定了解 3至少可以看懂要轉換的c語言程式。由於c語言的語句,與python沒有對應關係,所以只能按照如下方式轉換 1讀懂c語言 實現功能,可以以函式為單位 2按照功能,依照python方式實現相同功...
用c語言如何打遇一段程式執行的時間
千鋒教育 1 在程式最開始的地方獲取一下系統當前時間並儲存 2 在程式結束的地方獲取一下系統當前時間並儲存 3 兩者相減即為程式執行時間,將其列印出來便可。include include void main vc平台用clock 吧 如 include include void main 單位是毫秒...
c語言資料結構迷宮我菜鳥下面一段代
我現在中專的!準備讀6年直到大專畢業!請問我學軟體工程可以的嗎?我數學特別不好!會不會有難處?我英語我會努力學的!改好了 include include include define row 10 define col 10 int maze row col void main int i,j,a,...
C語言課程設計要求編寫一段程式,題目是《校際運動會管
課程設計任務書 一 題目 十佳運動員評選活動。二 系統設計要求 1 充分理解課程設計的目的和意義 有乙個寓言叫庖丁解牛,講的是乙個叫庖丁的人,在開始學宰牛時,因為不了解牛的身體構造,眼前所見無非就是一頭頭龐大的牛。等他有了三年的宰牛經歷後,就完全了解了牛的構造。再看牛時,出現在眼前的就不再是一頭整牛...
編寫一段C語言程式,程式功能是 把1到100之內的所有素數
直接寫函式主體了啊,思路就是巢狀for,外面的提供所有1到100的整數,裡面的for用來檢測是否為素數,如果不是就把a更改為0,表示非素數 void sushu if a 1 include stdio.h int main if i j for i 0 i printf d n sum retur...