語言復(fù)習備用_第1頁
語言復(fù)習備用_第2頁
語言復(fù)習備用_第3頁
語言復(fù)習備用_第4頁
語言復(fù)習備用_第5頁
已閱讀5頁,還剩33頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

TOC\o"1-1"\h\z\u【1.app 2mn1<=m<=6,1<=n<=6)a(mn列)中的元素,分別求出各行元和,并輸出。輸出使用語句:printf("sumofrowdis%d\n",i,3 sumofrow0issumofrow1is-sumofrow2is#include<stdio.h>intmain(void){inti,j,m,n,intfor(i=0;i<m;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]); printf("sumofrow%dis%d\n",i,}return}mnm≥1,n≤6)mna中的元素,a中的每個元素b。23(m=2,456123New645312#include<stdio.h>intmain(void){inta[6][6],b[6][6],i,j,m,for(i=0;i<m;i++)for(j=0;j<n;j++) }printf("Newarray:\n");for(i=0;i<m;i++)for(j=0;j<n;j++)}return}repeat(0<repeat<10)repeat1n(1≤n≤6),na,元和。副對角線為從矩陣的右上角至左下角的連線。 231sum= #include<stdio.h>intmain(void){inti,j,n,sum,b;intrepeat,ri;intscanf("%d",for(ri=1;ri<=repeat;ri++){scanf("%d",&n);for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",

printf("sum=%d\n",}return}repeat0<repeat<10)repeat次下列運算:輸入一個正整數(shù)n(0<n<10)n×n項。 輸出*123112243369#include<stdio.h>intmain(void){inti,j,inta[10][10];intrepeat,for(ri=1;ri<=repeat;ri++){scanf("%d",&n); elseif(j==0)for(i=0;i<=n;i++){for(j=0;j<=n;if(i==0&&j==0)printf("%-4c",elseif(i==0||j<=i)printf("%-4d",a[i][j]);}}return}repeat(0<repeat<10)repeat輸入1個正整數(shù)n(1≤n≤6)和n階方陣a中的元素,如果a是上三角矩陣,"YES",否則,輸出"NO"上三角矩陣指主對角線以下的元素都為0的矩陣,主對角線為從矩陣的左上角至右下角 #include<stdio.h>intmain(void){intflag,i,j,n;inta[6][6];intrepeat,scanf("%d",for(ri=1;ri<=repeat;ri++){scanf("%d",&n);for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",

if(flag==0) }return}repeat0<repeat<10)repeat次下列運算:,day)year、month和dayintint。19813 (198131日20003 (200031日Daysofyear: (19813160天Daysofyear: (20003161天#include<stdio.h>intmain(void){intday,day_year,month,year;intrepeat,ri;intday_of_year(intyear,intmonth,intscanf("%d",for(ri=1;ri<=repeat;ri++){scanf("%d%d%d",&year,&month,&day); day_year=day_of_year(year,month, printf("Daysofyear:%d\n",day_year);}return} intday_of_year(intyear,intmonth,int{intintreturnday;}(n≤612345700089 12345700089#include<stdio.h>intmain(void){inta[10][10],i,j,n,scanf("%d",&n);for(i=0;i<n;for(j=0;j<n;j++)

}}}}for(i=0;i<n;for(j=0;j<n;j++)printf("%5d",a[i][j]);}return}repeat(0<repeat<10)repeat1n(1≤n≤6)naa1個鞍點,如果找到a的鞍點,就輸出其下標,否則,輸出"NO"。鞍點的元素值在該行上最大,在該列上最小。 20 9214a[2][1]6#include"stdio.h"intmain(void){intflag,i,j,k,row,col,n;inta[6][6];intrepeat,scanf("%d",for(ri=1;ri<=repeat;ri++){scanf("%d",&n);for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",

}if(flag!=printf("a[%d][%d]=%d\n",row,}

return}輸入一個以回車結(jié)束的字符串(80個字符),將它的內(nèi)容逆序輸出。如"ABCD"的逆序

eto!uoyot#include<stdio.h>intmain(void){inti,k,temp;charstr[80];i=while((str[i]=getchar())!='\n')str[i]= for(i=0;str[i]!=0;return0;}輸入一個以回車結(jié)束的字符串(80個字符,把字符串中的所有數(shù)字字符('0~'9')轉(zhuǎn)#include<stdio.h>intmain(void){inti,char return0;}repeat0<repeat<10)repeat(下標從0開始"NotFound"。 programming(字符串"programming") index=7 NotFound #include<stdio.h>#defineMAXLEN80intmain(void){charcc,charstr[MAXLEN];intcount,flag,i,index;intrepeat,ri;scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){cc=getchar();i=while((ch=getchar())!='\n'){str[i++]=ch;}str[i]= if(flag!=printf("index=%d\n",}

printf("Notreturn}repeat(0<repeat<10)repeat寫輔音字母:除'A','E','I','O','U'以外的大寫字母。 count=3 O"中有3個大寫輔音字母)count=0 #include<stdio.h>#defineMAXLEN80intmain(void){charcharstr[MAXLEN];intcount,i;intrepeat,scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){i=0;while((ch=getchar())!='\n'){}str[i]= printf("count=%d\n",}return}repeat(0<repeat<10)repeat原字 AflagofUSAAfterreced:ZflagofFHZAfterreced:1+2=3#include<stdio.h>#include<string.h>#defineMAXLEN80intmain(void){charcharstr[MAXLEN];inti;intrepeat,scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){i=0;while((ch=getchar())!='\n'){str[i]=ch;}str[i]= printf("Afterreced:");for(i=0;str[i]!=0;i++)}return}大寫英文字母則輸出“NotFoundFONTNAMEandFILENAMEfontnameandNotintmain(void){charstr[80],newstr[80];inti,j,k,ri,repeat;scanf("%d",&repeat);for(ri=1;ri<=repeat;while((str[i]=getchar())!='\n') }printf("Not

for(i=0;newstr[i]!='\0';i++)}return}輸入一個以回車結(jié)束的字符串(80個字符ASCII碼intmain(void){charstr[80],ch;inti=0,j,k;while((str[i]=getchar())!='\n')str[i]= for(i=0;str[i]!='\0';return0;}repeat(0<repeat<10)repeat1010 A#include<stdio.h>intmain(void){intx,base,i,k,y;intri,repeat;charscanf("%d",for(ri=1;ri<=repeat;ri++{ }return}repeat(0<repeat<10)repeat programming(字符串 (字符 count2('m'在"programming"2次)count=0('a'在"1234"中沒有出現(xiàn)過)#include"stdio.h"#defineMAXLEN80intmain(void){charcc,charstr[MAXLEN];inti,count;intrepeat,scanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){i=0;while((str[i]=getchar())!='\n')str[i]=0;cc=getchar(); printf("count=%d\n",}return}repeat0<repeat<10)repeat次下列運算:輸入一個正整數(shù)n(0<n<10),輸出三角形的前n行。 11111 1111 #include<stdio.h>intmain(void){inti,j,n,repeat,ri;inta[10][10]; }}return}3先輸入學生的人數(shù)(<30人(提示:定義一個score[30][5]數(shù)組,score[0]、score[1]、score[2]分別3門課程的分數(shù)score[3]、score[4]分別每個學生的總分和平均分total和avg3門課程的總分和平均分。) 788794(1個學生的成績808080(2個學生的成績767677(3個學生的成績588766(4個學生的成績898788(5個學生的成績)總分平均分#include<stdio.h>intmain(void){intavg[3],score[30][5],total[3];inti,j,n;for{} 枃 枃{

鏁板鑻辮鎬誨 騫沖潎鍒哱} printf("\n騫沖潎鍒?");return}repeat(0<repeat<10)repeatDec=Dec=#include"stdio.h"#include"string.h"#defineMAXLEN80intmain(void){charcharstr[MAXLEN],num[MAXLEN];inti,k;intrepeat,ri;longscanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){i=0;while((ch=getchar())!='\n'){}str[i]= printf("Dec=}return}repeat(0<repeat<10)repeatx和y,并通過指針運算找出兩個數(shù)中的最大值,輸出到屏幕上。 (x=3,max=#include<stdio.h>intmain(void){intmax,x,y,*pmax,*px, printf("max=return}nm(1<m<n<=10)n個整數(shù),將這些數(shù)排成一行,向右循環(huán)移動m個位置(從右邊移出的數(shù)再從左邊移入n個整數(shù)。mov(x,n,m)x的類型是整型指針,nmintvoid。5 1234 (5個整數(shù)Aftermoved:3451#includevoidmov(int*x,intn,intm);intmain(void){inti,m,intscanf("%d%d",&n,&m);for(i=0;i<n;i++)scanf("%d", printf("Aftermoved:");for(i=0;i<n;i++)printf("%d",a[i]);return} 輸入兩個實數(shù)a和b,要求定義并調(diào)用函數(shù)sum_diff(floatop1,floatop2,floatvoidmain4-2-0.75Thesumis10.00Thediffis-2.00Thesumis-6.00Thediffis2.00Thesumis1.00Thediffis0.50#includevoidsum_diff(floatop1,floatop2,float*psum,float*pdiff);intmain(void){floata,b,sum,diff;intri,repeat;scanf("%d",for(ri=1;ri<=repeat;ri++){scanf("%f%f",&a,&b); printf("Thesumis%.2f\nThediffis}return} repeat(0<repeat<10)repeatn1<n<=10)naa中的元sort(a,n)an個元素anint,函數(shù)的類型void。517 125432Aftersortedthearrayis:156Aftersortedthearrayis:12Aftersortedthearrayis:1234#include<stdio.h>voidsort(inta[],intn);intmain(void){inti,intrepeat,intscanf("%d",for(ri=1;ri<=repeat;ri++){scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&a[i]); printf("Aftersortedthearrayis:");for(i=0;i<n;i++)printf("%d",a[i]);}return} repeat0<repeat<10)repeatn(1<n<=10)nax,在數(shù)a中查找x,如果找到則輸出相應(yīng)元素的最小下標,否則輸出"Notfound"。search(list,n,x)listx,若找到則返回相應(yīng)元素的最小下標,否則返回-1listnx的類型intvoid。12- 1225 index=1Notfound#include<stdio.h>intmain(void){inti,index,n,res,x;intrepeat,ri;intintsearch(intlist[],intn,intscanf("%d",for(ri=1;ri<=repeat;ri++){scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&a[i]);scanf("%d", if(res!=-printf("index=%d\n",}

printf("Notreturn} 輸入一個正整數(shù)n(1<n<=50,有n個人圍成一圈,按順序從1到n編好號。從第一個人開始報數(shù),報到3的人退出圈子,下一個人從1開始重數(shù),報到3的人退出圈子。0的數(shù),該數(shù)就是最后一個人的編號。輸出使用語句:printf("No%d:d\n",no (n個人報數(shù),n=5)LastNois: intmain(void){intcount,i,n,no;intnum[50];intscanf("%d",&n);for(i=0;i<n;num[i]=i+1;p=num; p=num;while(*p==0)printf("LastNois:%d\n",*p);return0;}5個字符串,輸出其中最小的字符串。Minis:Jin*/#include<stdio.h>#include<string.h>intmain(void){ min[80],str[80];inti;scanf("%s", printf("Minis:%s\n",min);return0;}repeat(0<repeat<10)repeatststrcstrcst的尾部。HappyBirthday#includevoidstrc(char*s,char*t);intmain(void){charreturn} repeat(0<repeat<10)repeat5scanf("%s",sx);redbluegreenyellowThelongestis:zhangThelongestis:#include<stdio.h>#include<string.h>intmain(void){charsx[80],longest[80];inti;intrepeat,scanf("%d",for(ri=1;ri<=repeat;ri++){scanf("%s",sx); return}repeat(0<repeat<10)repeat輸入一個字符串t和一個正整數(shù)m,將字符串t中從第m個字符開始的全部字符到字符串s中,再輸出字符串s。要求定義并調(diào)用函數(shù)strmcpy(s,t,m),它的功能是將字符串t中從第m個字符開始的全部字符到字符串s中,函數(shù)形參s和t的類型是字符指針,形參m的類型是int,函數(shù)類void。happynewyearOutputis:newyear (從"happynewyear"第7個字符開始組成的新字符串為"newOutputis: (從"happy"1個字符開始組成的新字符串為error intmain(void){chars[80],t[80];intm;intrepeat,voidstrmcpy(char*s,char*t,intscanf("%d",&repeat);for(ri=1;ri<=repeat;ri++){scanf("%d",&m);if(strlen(t)<m)printf("errorinput\n"); printf("Outputis:}}return} bFaE3+8=1R大寫字母數(shù)為:小寫字母數(shù)為:空格為:數(shù)字為:其他字符為:intmain(void){chars[80];char*p;intblank,digit,lower,other,upper=lower=blank=digit=other= printf("澶у啓瀛楁瘝鏁頒負:%d\n灝忓啓瀛楁瘝鏁頒負:%d\n絀烘牸涓?%d\n涓d\n鍏朵粬瀛楃涓d\n",upperlowerblank,digit,other);return0;}/*3個字母移到最后,輸出變換后的字符串。#include<stdio.h>#include<stdlib.h>#include#defineMAXLINE100intmain(void){charline[MAXLINE],str[4];inti;if(strlen(line)<3)printf("瀛楃涓查暱搴﹀皬浜?n");} printf("%s\n",line);return0;}’或者’DAD123456789DAftersorted:1098765432#includevoidsortAsc(inta[],intn);voidsortDesc(inta[],intn);intmain(void){inti,n,a[10];charc;for(i=0;i<n;i++)scanf("%d",&a[i]);if(c=='A')sortAsc(a,n);elseif(c=='D')else{printf("theinputcharisnot'A'or'D'!,programisclosed");}printf("Aftersorted:");for(i=0;i<n;i++)printf("%d",a[i]);return} /*5個字符串,按由小到大的順序輸出。redyellowbluegreenAftersorted:#include<stdio.h>#include<string.h>intmain(void){inti,j,charsx[5][80],stemp[80];scanf("%s", printf("Aftersorted:\n");for(i=0;i<5;i++)return0;}/*repeat0<repeat<10)repeat輸入兩個字符串,調(diào)用函 p(s1,s2),實現(xiàn)兩個字符串的比較,返回值分別為1、0-1s1>s2,s1=s2,s1<s2的情況。30#include p(char*s1,char*s2);intmain(void){intresult,ri,repeat;chars1[80],scanf("%d",&repeat);for(ri=1;ri<=repeat;{p(s1,s2);printf("%d\n",result);}return} /*repeat0<repeat<10)repeat次下列運算:findstr(char*str,char*substr)2mkloas6。 asdasasdfgasdaszx67asd am123am456amam 65#include"stdio.h"intmain(void){

溫馨提示

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

評論

0/150

提交評論