C#課后習題答案_第1頁
C#課后習題答案_第2頁
C#課后習題答案_第3頁
C#課后習題答案_第4頁
C#課后習題答案_第5頁
已閱讀5頁,還剩3頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、1、 編寫程序(輸入一個華氏溫度,輸出一個攝氏溫度。公式C=(F-32)*5/9)static void Main(string args) Console.WriteLine(請輸入華氏溫度:); double f = double.Parse(Console.ReadLine(); double c = (f - 32) * 5 / 9; Console.WriteLine(對應攝氏溫度為: + c); Console.ReadLine(); 2、 編寫一個C#控制臺應用程序,對于輸入的正整數(shù)n,計算1!+2!+3!+n!的值并輸出結果。public int fn(int n) int s

2、um = 0, m = 1; for (int i = 1; i =0; i-) Console.Write(si); Console.Read(); 4、 C#寫一個輸入三個整數(shù),按大到小順序輸出的小程序int arr = new int3; for (int i = 0; i arr.Length; i+) Console.WriteLine(請輸入第 + (i + 1) + 個數(shù)); arri = Convert.ToInt32(Console.ReadLine(); for (int i = 0; i arr.Length - 1; i+) for (int j = 0; j arr.

3、Length - 1 - i; j+) if (arrj arrj + 1) int temp = arrj; arrj = arrj + 1; arrj + 1 = temp; for (int i = 0; i total ) /如果輸入2010 2 29就會出錯 txtXianShi.Text = 該天不存在;else if (y = 1 & y = 1 & m = 12) for (int i = 1; i = m; i+) /循環(huán)累加天數(shù) switch (i) case 1: case 3: case 5: case 7: case 8: case 10: case 12: coun

4、t = 31; break; case 4: case 6: case 9: case 11: count = 30; break; case 2: if (y % 100 != 0)&(y % 4 = 0)|(y % 400 = 0) count = 29; else count = 28; break; sum = sum + count; /循環(huán)一次累加一個月的天數(shù) txtXianShi.Text = sum.ToString(); /類型轉換后輸出 else txtXianShi.Text = 你輸入的年份不正確!請重新輸入!; else txtXianShi.Text = 你輸入的月

5、份不正確!請重新輸入!; 6、求公式1/2+3/2+5/3+8/5+13/8+21/13+.中前20項的和#include intmain()doublea = 2.0,b = 1.0;doublesum = 0.0;inti = 0;while( i 20 )sum += a / b;doubletemp = b;b = a;a = a + temp;i+;printf(sum = %lfn,sum);return0;7、雞兔同籠,雞兔共30只,腳90只,計算共多少只雞多少只兔#includemain() int chicken, rabbit; int legs = 90, sum = 3

6、0; rabbit = (90-30*2)/2; chicken = 30 - rabbit; printf(%d只兔子,%d只雞, rabbit, chicken);8、 編輯程序,求1100之間的所有質數(shù)using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication10 class Program static void Main(string args) int min, max, i, j, n; bool flag; Conso

7、le.WriteLine( 素數(shù) n); Console.WriteLine( 輸入范圍的下限(不小于2)); min = Convert.ToInt16(Console.ReadLine(); Console.WriteLine( 輸入范圍的上限); max = Convert.ToInt16(Console.ReadLine(); n = 0; /初始化素數(shù)的個數(shù)為0 for (i = min; i = max;i+ ) /i為min到max之間的所有自然數(shù) flag = true; /設置為真 for (j = 2; j = Math.Sqrt(i);j+ ) if (i % j = 0

8、) /如果i能被j整除 flag = false; /設置標記為假 break; /退出內循環(huán) if (!flag) /如果標記為假 continue; / 退出本次循環(huán) Console.Write(0,6,i); /輸出素數(shù) n+; /素數(shù)遞增 if(n%10=0) /沒輸出十個素數(shù)換一次行 Console.WriteLine(); Console.WriteLine(n 0到1之間的素數(shù)共有2,min,max,n); Console.ReadLine(); 9、編寫程序,顯示10個單項選擇題,用戶選擇答案并提交后給出分數(shù)(1)在設計中拉十個RadioButton控件和一個Button控件。

9、雙擊Button控件,寫入以下代碼!protected void Button1_Click(object sender, EventArgs e) int n=0;int i=0;if(RadioButton1.Checked=true)n=n+10;i+;if(RadioButton2.Checked=true)n=n+10;i+;.if(RadioButton10.Checked=true)n=n+10;i+;你將n打出來它就是你要的分數(shù),而i就是正確答案的個數(shù)(2)Gridview中的RadioButton在Gridview中放了一個radiobutton組 asp:Label id=

10、sque runat=server Text= asp:Label id=key runat=server Text= Visible=false asp:RadioButton id=RadioButton1 runat=server Text= GroupName= asp:RadioButton id=RadioButton2 runat=server Text= GroupName= asp:RadioButton id=RadioButton3 runat=server Text= GroupName= asp:RadioButton id=RadioButton4 runat=se

11、rver Text= GroupName= asp:SqlDataSource ID=paperconn runat=server ConnectionString= SelectCommand=SELECT Answer_A, Answer_B, Answer_C, Answe_D, Answe_Key, Ques_Squc, Ques_Title FROM Ques_Info WHERE (File_ID = File_ID) ORDER BY Ques_Squc 結果點擊交卷按鈕后執(zhí)行 protected void papersubmit_Click(object sender, Eve

12、ntArgs e) int score = 0; foreach (GridViewRow dr in GridView1.Rows) string str = ; string key = ; key = (Label)GridView1.Rows0.FindControl(key).Text; int radio_pre = GridView1.Controls.Count; if (RadioButton)dr.FindControl(RadioButton1).Checked) str = A; else if (RadioButton)dr.FindControl(RadioButton2).Checked) str = B; else if (RadioButton)dr.FindControl(RadioButton3).Checked) str = C; else if (RadioButton)dr.FindContro

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論