c語(yǔ)言編程代碼_第1頁(yè)
c語(yǔ)言編程代碼_第2頁(yè)
c語(yǔ)言編程代碼_第3頁(yè)
c語(yǔ)言編程代碼_第4頁(yè)
已閱讀5頁(yè),還剩74頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

C語(yǔ)言編程代碼include<stdio.h>#include<math.h>intmain(void)doubley;intx,m;for(y=10;y>=-10;y-)m=2.5*sqrt(100-y*y); /?計(jì)算行y對(duì)應(yīng)的列坐標(biāo)m,2.5是屏幕縱橫比調(diào)節(jié)系數(shù)因?yàn)槠聊坏男芯啻笥诹芯?不進(jìn)行調(diào)節(jié)顯示出來(lái)的將是橢圓?/for示出來(lái)的將是橢圓?/for(x=1;x<30_m;x++)printf("");控制?/printf("*");for(;x<30+m;x++)printf("");控制?/printf('*\n");/?圖形左側(cè)空白/?圓的左側(cè)?//?圖形的空心部分/?圓的右側(cè)?/return0;/*在Vc++6.0中的輸出結(jié)果是:****Pressanykeytocontinueinclude<stdio.h>intmain(void)(inta,b,c,max;printf("pleaseinputa,b,c[請(qǐng)以空格分隔]:\n");scanf("%d%d%d",&a,&b,&c);max=a;if(max<b)max=b;if(max<c)max=c;printf("thelargestnumberis%d\n",max);return0;include<stdio.h>intmain(void)finti=2518;floata=3.1415;printf("i=%d,a=%f,a*10=%e\n",i,a,a*10);return0輸出結(jié)果是:i=2518,a=3.141500,a*10=3.141500e+001include<stdio.h>intmain(void){inta=1,b=0;printf("%d\n",b=a+b);printf("%d\n",a=2*b);return0;輸出結(jié)果:12#include<stdio.h>intmain(void){doublea=123.456;printf(/z%6.2f",a);return0;輸出結(jié)果:123.46ttinclude<stdio.h>intmain(void){intx,y,t;printf("Enterx&y[請(qǐng)用空格分隔]:\n");scanf("%d%d”,&x,&y);printf("x=%dy=%d\n”,x,y);t=x;x=y;y=t;printf("x=%dy=%d\n”,x,y);輸出結(jié)果:Enterx&y:12x=ly=2x=2y=linclude<stdio.h>intmain(void){inta,b,c;printf("Pleaseinputa,b,c[請(qǐng)用逗號(hào)分隔]:\n");scanf("%d,%d,%d",&a,&b,&c);if(a〉=b)if(b>=c)printf("c=%d,b=%d,a=%d\n",c,b,a);elseif(c>=a)printf("b=%d,a=%d,c=%d\n",b,a,c);elseprintf("b=%d,c=%d,a=%d\n",b,c,a);elseif(a>c)printf("c=%d,a=%d,b=%d\n”,c,a,b);elseif(b>c)printf("a=%d,c=%d,b=%d\n”,a,c,b);elseprintf("a=%d,b=%d,c=%d\n”,a,b,c);return0;輸出結(jié)果:Pleaseinputa,b,c:1,4,7a=l,b=4,c=7Pleaseinputa,b,c:5,1,2b=l,c=2,a=5Pleaseinputa,b,c:2,1,5b=l,a=2,c=5include<stdio.h>intmain(void){if(3>2)printf("AAAA\n");elseif(3>1)printf("BBBB\n");elseprintf("CCCC'n");return0;)/*在Vc++6.0中的輸出結(jié)果是:AAAAinclude<stdio.h>intmain(void){ints,n;for(s=0,n=100;n>=l;n—){s=s+n;]printf("s=%d\n”,s);return0;在Vc++6.0中的輸出結(jié)果是:5050*/#include<stdio.h>intmain(void){inti;intsum=0;for(i=1;i<=100;++i)sum=sum+i;printf("sum=%d",sum);return0;)/*在Vc++6.0中的輸出結(jié)果是:5050#include<stdio.h>intmain(void){inti;intsum=0;for(i=1;i<10;i+=2)sum=sum+1;printf("sum=%d”,sum);return0;)/*在Vc++6.0中的輸出結(jié)果是:sum=5求!到10的奇數(shù)的和include<stdio.h>intmain(void){inti;intsum=0;for(i=1;i<10;i+=2){sum=sum+i;printf("i=%d\n,\i);printf("sum=%d\n”,sum);return0;)在Vc++6.0中的輸出結(jié)果是:i=11sum=25include<stdio.h>intmain(void){inti;intsum=0;for(i=3;i<=10;++i){if(i%3==0)sum=sum+i;printf("sum=%d\n",sum);return0;

sum=3sum=3sum=3sum=9sum=9sum=9sum=18sum=18*//?求1+1/2+1/3+....+1/100的和*/#include<stdio.h>intmain(void){inti;floatsum=0;for(i=1;i<=100;++i)sumsum+1/(float)i;printf("sum=%f\n",sum);return0;在Vc++6.0中的輸出結(jié)果是:sum=5.187378/?求!+1/2+1/3+....+1/100的和*/#include<stdio.h>intmain(void){inti;floatsum=0;for(i=1;iく=100;++i){sum=sum+1.0/i;}printf("sum=%f\n",sum);return0;sum=5.187378/?求!到100的奇數(shù)的和*/#include<stdio.h>intmain(void){inti;intsum=0;for(i=1;i<101;++i){if(i%2==1)

sum+=i;jprintf("sum=%d\n",sum);return0;在Vc++6.0中的輸出結(jié)果是:sum=2500*//?求!到100的奇數(shù)的個(gè)數(shù)*/#include<stdio.h>intmain(void)(inti;intent=0J〃個(gè)數(shù)用ent表示for(i=1;i<101;++i)(if(i%2==1)++cnt;Fprintf("ent=%d\n",ent);return0;在Vc++6.0中的輸出結(jié)果是:sum=50*//?求1到100的奇數(shù)和的平均值*/#include<stdio.h>intmain(void)finti;intsum=0;intent=0;〃個(gè)數(shù)用ent表示count的縮寫(xiě)floatavg;//average平均值的縮寫(xiě)for(i=1;i<101;++i)(if(i%2==1)sum+=i,++cnt;Iavg=1.0*sum/ent;printf("sum=%d\n",sum);printf("ent=%d\n",ent);printf("avg=%f\n",avg);return0;/*sum=2500ent=50avg=50.000000/?求1至リ100的奇數(shù)和與偶數(shù)和*/#include<stdio.h>intmain(void){inti;intsuml=0;intsum2=0;for(i=1;i<101;++i)if(i%2==1)(suml+=i;else{sum2+=i;printf("奇數(shù)和=%d\n",suml);printf("偶數(shù)和=%d\n",sum2);return0;在Vc++6.0中的輸出結(jié)果是:奇數(shù)和=2500偶數(shù)和=2550#include<stdio.h>intmain(void)(inti,j,k,m;i=3;j=3;k=i++;〃后自增整體表達(dá)式的值是i+1之前的值m=++j;〃前自增整體表達(dá)式的值是i+1之后的值printf("i=%d,j=%d,k=%d,m=%d\n",i,j,k,m);return0;/*在Vc++6.0中的輸出結(jié)果是:i=4,j=4,k=3,m=4#include<stdio.h>intmain(void)inti,j;for(i=0;i<3;++i)for(j=2;j<5;++j)printf("哈哈!\n");printf("嘻嘻!\n");return0;)/*在Vc++6.0中的輸出結(jié)果是:哈哈!

哈哈!哈哈!哈哈!哈哈!哈哈!哈哈!哈哈!哈哈!嘻嘻!*/#include<stdio.h>intmain(void)inti,j;for(i=0;i<3;++i)printf("嘿嘿!\n");for(j=2;

printfj<5;++j)(“哈哈!\n〃);printf("嘻嘻!\n〃);return0;/*哩哩!哩哩!哩哩I哈哈!哈哈!哈哈!嘻嘻!include<stdio.h>intmain(void){inti,j;for(i=0;i<3;++i){printf("嘿嘿!\n");{for(j=2;j<5;++j)printf("哈哈!\n");printf("嘻嘻!\n");printf("嗚嗚!\n");return0;哈哈!哈哈!哈哈!嘻嘻!哈哈!哈哈!哈哈!嘻嘻!哈哈!哈哈!哈哈!嘻嘻!嗚嗚!include<stdio.h>intmain(void){inti,j;for(i=0;i<3;++i){printf("嘿嘿!\n");for(j=2;j<5;++j){printf("哈哈!\n");printf("嘻嘻!\n");I}printf("嗚嗚!\n");return0;在Vc++6.0中的輸出結(jié)果是:哩哩!哈哈!嘻嘻!哈哈!嘻嘻!哈哈!嘻嘻!哈哈!嘻嘻!哈哈!嘻嘻!哈哈!嘻嘻!哈哈!嘻嘻!哈哈!嘻嘻!哈哈!嘻嘻!嗚嗚!#include<stdio.h>ttinclude<stdlib.h>intmain(void){intday=0,hour,minute,m;printf〈'Pleaseminutes:");scanf("%d",&m);minute=m%60;hour=m/60;while(hour>=24)hour-=24;day++;printf("day:%d,hour:%d,minute:%d\n,day,hour,minute);return0;在Vc++6.0中的輸出結(jié)果是:Pleaseminutes:560day:0,hour:9,minute:20ttinclude<stdio.h>intmain(void)(inta,b;printf(“請(qǐng)輸入兩個(gè)值[請(qǐng)以空格分隔]'n",a,b);scanf("%d%d”,&a,&b);a=a+b;b=a-b;a=a-b;printf("a=%d,b=%d\n”,a,b);return0;在Vc++6.0中的輸出結(jié)果是:請(qǐng)輸入兩個(gè)值[請(qǐng)以空格分隔]12a=2,b=l#include<stdio.h>intmain(void){intsum=0;inti;i=l;while(i<101)(sum=sum+i;++i;Tprintf("sum=%d\n",sum);return0;sum=5050Pressanykeytocontinuefor(l;2;3)A;等價(jià)于1;while(2)[A;3;}for循環(huán)比while邏輯性更強(qiáng)#include<stdio.h>intmain(void){intsum=0;intval;intm;printf("請(qǐng)輸入要判斷的數(shù)字:");scanf("%d",&val);m=val;while(m){sum=sum*10+m%10;m/=10;Iif(sum==val)printf("YES!\n");elseprintf("NO!\n");return0;在Vc++6.0中的輸出結(jié)果是:請(qǐng)輸入要判斷的數(shù)字:1234321YES!Pressanykeytocontinue*/include<stdio.h>include<math.h>intmain(void)doublea,b,c;doubledelta;doublexl,x2;printf(〃請(qǐng)輸入一元二次方程的3個(gè)系數(shù):'n〃);printf("a=");scanf(“機(jī)f”,&a);printf("b=");scanf("%lf",&b);printf("c=");scanf("機(jī)f”,&c);delta=b*b-4*a*c;if(delta>0){xl=(-b+sqrt(delta))/(2*a);x2=(-b-sqrt(delta))/(2*a);printf("有兩個(gè)解,xl=%lf,x2=%lf\n”,xl,x2);elseif(0==delta)xl=x2=(-b)/(2*a);printf("有唯一解,xl=x2=%lf\n/,,xl,x2);else(printf("無(wú)實(shí)數(shù)解!'n");return0;在Vc++6.0中的輸出結(jié)果是:請(qǐng)輸入一元二次方程的3個(gè)系數(shù):a=1b=5c=6有兩個(gè)解,xl=-2.000000,x2=-3.000000Pressanykeytocontinue#include<stdio.h>intmain(void){inta[5]={1,2,3,4,5};inti;for(i=0;i<5;++i)printf("%d\n",a[i]);return0;在Vc++6.0中的輸出結(jié)果是:12345Pressanykeytocontinue*/include<stdio.h>intmain(void){inta[5];inti;scanf("%d",&a[〇]);printf("a[〇]=%d\n”,a[0]);scanf("%d",&a[3]);printf("a[3]=%d\n",a[3]);for(i=0;i<5;++i)printf("%d",a[i]);return0;)/*在Vc++6.0中的輸出結(jié)果是:1a[0]=12a[3]=21-858993460-8589934602-858993460Pressanykeytocontinueinclude<stdio.h>intmain(void)finta[7]={1,2,3,4,5,6,7};inti,j,t;=0;j=6;while(i<j)(t=a[i];a[i]=a[j];a[j]=t;i++;—j;}for(i=0;i<7;++i)printf("%d\n",a[i]);return0;在Vc++6.0中的輸出結(jié)果是:7654321Pressanykeytocontinue#include<stdio.h>intmain(void){inta[3][4]={{1,2,3,4},{5,6,7,8),{9,10,11,12}inti,j;for(i=0;i<3;++i)(for(j=0;j<4;++j)printf("%-5d",a[i][j]);〃-表示左對(duì)齊5表示5個(gè)空格printf('\n");return0;在Vc++6.0中的輸出結(jié)果是:123456789101112Pressanykeytocontinue#include<stdio.h>intmain(void)doublevar;longa;scanf("%lf%d”,&var,&a);〃那個(gè)!f中的1一定要,否則錯(cuò)誤printf(z/%f%d\n,/,var,a);return0;/*在Vc++6.0中的輸出結(jié)果是:1.0000002Pressanykeytocontinue*/include<stdio.h>intmain(void)inta=0,b=0,c=0;c=(a-=a-5),(a=b,b+3);printf("%d,%d,%d\n,,,a,b,c);return0;/*在Vc++6.0中的輸出結(jié)果是:0,0,5Pressanykeytocontinueinclude<stdio.h>intmain(void)inta;floatb,c;scanf(,,%2d%3f%4f,/,&a,&b,&c);printf('\na=%d,b^f,c=%f\n”,a,b,c);return0;在Vc++6.0中的輸出結(jié)果是:987654321a=98,b=765.000000,c=432L000000Pressanykeytocontinue*/include<stdio.h>intmain(void)inta,s,f;printf("請(qǐng)輸入分鐘:\n");scanf&a);s=a/60;f=a%60;printf("您輸入的是%d時(shí)%d分.、n”,s,f);return0;在Vc++6.0中的輸出結(jié)果是:請(qǐng)輸入分鐘:560您輸入的是9時(shí)20分.Pressanykeytocontinue*/include<stdio.h>intmain(void)inti,sum=O;for(i=0;iく=100;i+=2)sum+=i;i+=2;}printf("/d\n",sum);return0;在Vc++6.0中的輸出結(jié)果是:1300Pressanykeytocontinue*/include<stdio.h>intmain(void){intsignal,i;floatitem=L0,sum=0.0;{item=sign*l.0/i;sum=sum+item;sign=~sign;}printf(/zThesum=sum);return0;在Vc++6.0中的輸出結(jié)果是:Thesum=0.692646Pressanykeytocontinue1到9,任選3個(gè)數(shù)加起來(lái)和為15,用C語(yǔ)言編寫(xiě),求有多少組,并列出來(lái)include<stdio.h>intmain(void)(inta[9],i,k,j,s=0;for(i=l;i<=9;i++)a[i-l]=i;for(i=l;iく=9;i++)for(k=i;k〈=9;k++)j=15-a[i-l]-a[k-l];if(j>=l&&jく=9&&j>=a[i-l]&&j>=a[k-l]){printf("%d+%d+%d=15\n",a[i-l],a[k-l],j);s++;printf("總共有%d種可能”,s);return0;在Vc++6.0中的輸出結(jié)果是:1+5+9=151+6+8=151+7+7=152+4+9=152+5+8=152+6+7=153+3+9=153+4+8=153+5+7=153+6+6=154+4+7=154+5+6=155+5+5=15總共有13種可能Pressanykeytocontinueinclude<stdio.h>intmain(void)finta[9],i,k,j,s=0;for(i=l;iく=9;i++)a[i-l]=i;for(i=l;iく=9;i++)for(k=i;k<=9;k++)(j=14-a[i-l]-a[k-l];if(j>=l&&jく=9&&j>=a[i-l]&&j>=a[k-l]&&a[i-1]!=a[k]&&a[k]!=j){printf("刎+%d+%d=15\n”,a[i-l],a[k],j);s++;printf("總共有%d種可能”,s);return0;1+5+9=151+6+8=152+4+9=152+5+8=152+6+7=152+7+6=153+4+8=153+5+7=154+5+6=154+6+5=15總共有10種可能Pressanykeytocontinueinclude<stdio.h>intmain(void)(inta[10]={0,1,2,3,4,5,6,7,8,9},i=l,k=l,j=l,s=0;for(i=l;i<=9;i++)for(k=i+l;k<=9;k++)j=15-a[i]-a[k];if(j>=l&&jく=9&&j>a[k])printf(*%d+%d+%d=15\n*,a[i],a[k],a[j]);s++;}}printf("總共有%d種可能”,s);return0;在Vc++6.0中的輸出結(jié)果是:1+5+9=151+6+8=152+4+9=152+5+8=152+6+7=153+4+8=153+5+7=154+5+6=15總共有8種可能Pressanykeytocontinue*/ttinclude<stdio.h>intmain(void)(inti;for(i=0;i<10;++i)printf("/d\n",i);return0;在Vc++6.0中的輸出結(jié)果是:0include<stdio.h>include<math.h>intmain(void){inta,b,c;floats,area;printf("請(qǐng)輸入a,b,c:\n");scanf("%d,%d,%d",&a,&b,&c);s=(a+b+c)*(l.0/2);area=sqrt(s*(s-a)*(s-b)*(s-c));printf("輸出三角形的面積%4.2f\n",area);return0;在Vc++6.0中的輸出結(jié)果是:請(qǐng)輸入a,b,c:3,4,5輸出三角形的面積6.00Pressanykeytocontinueinclude<stdio.h>#include<math.h>intmain(void)inta,b,c,d,e,f;a=1,b=2,c=3,d=9,e=-5,f=100;if(a>b)printf("%d\n",a);elseprintf("%d\n”,b);if(c>d)printf("%d\n",c);elseprintf(為d\n”,d);if(e>f)printf(級(jí)d\n”,e);elseprintf("%d\n”,f);return0;在Vc++6.0中的輸出結(jié)果是:29100Pressanykeytocontinue#include<stdio.h>voidmax(inti,intj)//void表示函數(shù)沒(méi)有返回值max是函數(shù)的名字i和j是形式參數(shù)(if(i>j)printf("%d\n',i);elseprintf("%d\n",j);#include<math.h>intmain(void){inta,b,c,d,e,f;a=1,b=2,c=3,d=9,e=-5,f=100;max(a,b);max(c,d);max(e,f);return0;在Vc++6.0中的輸出結(jié)果是:29100Pressanykeytocontinue*/include<stdio.h>intf(void)〃void表示該函數(shù)不能接受數(shù)據(jù)int表示函數(shù)返回值是int類型的數(shù)據(jù)return10J〃向主調(diào)函數(shù)返回!0)intmain(void)fintj=88;j=f0;printf("%d\n",j);return0;)/*在Vc++6.0中的輸出結(jié)果是:10Pressanykeytocontinueinclude<stdio.h>include<math.h>intmain(void){longn=0;floata=l;floatsum=0;floatj;while(fabs(a)>le-6):{sum+=a;n++;if(n%2==0)j=l.0;elsej=-l.0;a=j/(2*n+l);Isum*=4;printf("答案是:%f\return0;)在Vc++6.0中的輸出結(jié)果是:答案是:3.141594Pressanykeytocontinue#include<stdio.h>intf()(return10.5J〃因?yàn)楹瘮?shù)的返回類型為int,所以最終返回10}intmain(void){inti=99;doublex=66;x=f();printf(訣lf\n”,x);return0;/*在Vc++6.0中的輸出結(jié)果是:10.000000Pressanykeytocontinue*/include<stdio.h>voidf(void){inti;for(i=0;i<5;++i){printf("大家辛苦了!'n");break; 〃break用來(lái)終止循環(huán)的}printf("同志們好!、n");)intmain(void){f();return0;)/*在Vc++6.0中的輸出結(jié)果是:大家辛苦了!同志們好!Pressanykeytocontinue*/include<stdio.h>voidf(void){inti;for(i=0;i<5;++i){printf("大家辛苦了!'n");return; "return用來(lái)終止函數(shù)的前面是void的話return后面不能加任何值printf("同志們好!'n");)intmain(void){f();return0;)/*在Vc++6.0中的輸出結(jié)果是:大家辛苦了!Pressanykeytocontinueinclude<stdio.h>intmain(void){intx;inty;intc;x=5;y=10;c=++x+y—;printf("c=%d\n”,c);return0;在Vc++6.0中的輸出結(jié)果是:c=16Pressanykeytocontinueinclude<stdio.h>intmain(void){intx;inty;intc;x=5;y=10;c=x+++y——;printf("c=%d\n”,c);return0;在Vc++6.0中的輸出結(jié)果是:c=15Pressanykeytocontinue*/include<stdio.h>intmain(void)(printfC%3s,%7.2s,%.4s,%-5.3s\n","CHINA","CHINA","CHINA","CHINA");return0;在Vc++6.0中的輸出結(jié)果是:CHINA,CH,CHIN,CHIPressanykeytocontinue判斷ー個(gè)數(shù)是不是素?cái)?shù)include<stdio.h>intmain(void)(intval;inti;scanf("%d”,&val);for(i=2;i<val;++i){if(val%i==0)break;Iif(i==val)〃因?yàn)槿绻鹖不是素?cái)?shù)i的值一定不會(huì)加到val,在之前就會(huì)被break終止printf("YES!\n");elseprintf("N0!\n");return0;11YES!Pressanykeytocontinue判斷ー個(gè)數(shù)是不是素?cái)?shù)include<stdio.h>boolIsPrime(intval) 〃真假用bool表示,素?cái)?shù)用IsPrime表示{inti;for(i=2;i<val;++i)(if(val%i==0)break;if(i==val) 〃因?yàn)槿绻鹖不是素?cái)?shù)i的值一定不會(huì)加到val,在之前就會(huì)被break終止returntrue;elsereturnfalse;intmain(void){intm;scanf("%d",&m);if(IsPrime(m))printf("YES!\n");elseprintf("N0!\n");return0;)/*在Vc++6.0中的輸出結(jié)果是:11YES!Pressanykeytocontinue*/include<stdio.h>intmain(void)scanf("%d",&i);printf("i=%d\n”,i);if(i>=90)printf("A\n");elseif(i>=80)printf("B\n");elseif(i>=70)printf("C\n");elseif(i>=60)printf("D\n");elseprintf("E\n");return0;在Vc++6.0中的輸出結(jié)果是:90i=90APinclude<stdio.h>intmain(void)inta=l,b=2,c=3,d=0;if(a==l&&b++==2)if(b!=2IIc—!=3)printf(,,%d,%d,%d\n”,a,b,c);elseprintf("%d,%d,%d\n”,a,b,c);return0;在Vc++6.0中的輸出結(jié)果是:1,3,3Pressanykeytocontinueinclude<stdio.h>intf(inti)intmain(void)inti=99;printf("%d\n”,i);i=f⑸;printf("%d\n",i);return0;在Vc++6.0中的輸出結(jié)果是:9910Pressanykeytocontinueinclude<stdio.h>intmain(void){inti,val,j;scanf("%d”,&val);for(i=2;i〈=val;++i)for(j=2;j〈=i;++j)if(0==i%j)break;}if(j==i)printf("%d\n”,i);}return0;在Vc++6.0中的輸出結(jié)果是:20235711131719Pressanykeytocontinue#include<stdio.h>boolIsPrime(intm)for(i=2;iくm;++i){if(0==m%i)break;)if(i==m)returntrue;elsereturnfalse;)intmain(void)finti,val,j;scanf("%d”,&val);for(i=2;i〈=val;++i){if(IsPrime(i))printf("/d\n”,i);)return0;)/*在Vc++6.0中的輸出結(jié)果是:20235711131719Pressanykeytocontinue#include<stdio.h>intmain(void){inta,b,c,d;a—2,b—3;c=(a++)+(a++)+(a++);d=(++b)+(++b)+(++b);printf("%d%d%d%d\n”,a,b,c,d);return0;在Vc++6.0中的輸出結(jié)果是:56616Pressanykeytocontinue*/#include<stdio.h>structStudent(intage;charsex;charname[100];}i 〃分號(hào)不能省intmain(void)(structStudentst={20,'F',"小娟"};printf("%d%c%s\n",st.age,st.sex,);return0;)/*在Vc++6.0中的輸出結(jié)果是:20F小娟P(guān)ressanykeytocontinue*/#include<stdio.h>structStudentcharsex;charname[100];};〃分號(hào)不能省intmain(void){structStudentst={20,'F',"小娟"};structStudent*pst=&st;printf(z/%d%c%s\n",st.age,st.sex,);printf("%d%c%s\n",pst->age,pst->sex,pst->name);〃pst->age轉(zhuǎn)化成(*pst).age等價(jià)于st.agereturn0;在Vc++6.0中的輸出結(jié)果是:20F小娟20F小娟P(guān)ressanykeytocontinue*/ttinclude<stdio.h>intmain(void)inta,b,c;scanf("%d,%d,%d",&a,&b,&c);printf("%d\n",(a>b?a:b)>c?(a>b?a:b):c);return0;在Vc++6.0中的輸出結(jié)果是:5,4,99Pressanykeytocontinue*/#include<stdio.h>intmain(void)(inti;scanf("%d",&i);if(i%2==0)printf("偶數(shù)");elseprintf("奇數(shù)");return0;}/*在Vc++6.0中的輸出結(jié)果是:20偶數(shù)Pressanykeytocontinue#include<stdio.h>intmain(void)(inta=2,b=-l,c=2;if(a<b)if(b<0)c=0;elsec+=l;printf("%d\n”,c);return0;)/*在Vc++6.0中的輸出結(jié)果是:2Pressanykeytocontinuettinclude<stdio.h>intmain(void)intw=4,x=3,y=2,z=l;printf("%d\n”,(wくx?w:zくy?z:x));return0;/*在Vc++6.0中的輸出結(jié)果是:1Pressanykeytocontinuettinclude<stdio.h>intmain(void)finta=l,b=2,c=3;if(a>c)b=a;a=c;c=b;〃這是三個(gè)語(yǔ)句,if只能控制ー個(gè)語(yǔ)句printf("%d%d%d\n,,>a,b,c);return0;)/*在Vc++6.0中的輸出結(jié)果是:322Pressanykeytocontinue#include<stdio.h>inta,b,c,x;scanf("%d%d%d”,&a,&b,&c);if(a>b)x=a;elsex=b;if(x<c)x=c;printf("最大的數(shù)是%d\n",x);return0;)/*在Vc++6.0中的輸出結(jié)果是:592最大的數(shù)是9Pressanykeytocontinueinclude<stdio.h>intmain(void)Iinta=1;printf("%d\n”,(a=3*a,3+a));return0;在Vc++6.0中的輸出結(jié)果是:6Pressanykeytocontinueinclude<stdio.h>intmain(void){inta=1;printf("%d\n”,(a=3*a,3*a));return0;)/*在Vc++6.0中的輸出結(jié)果是:9Pressanykeytocontinueinclude<stdio.h>intc;〃當(dāng)輸入多個(gè)字符時(shí),多printf("Enteracharacter:");〃當(dāng)輸入多個(gè)字符時(shí),多余字符作廢c=getchar();printf("%c:%d\n",c,c);return0;)/*在Vc++6.0中的輸出結(jié)果是:Enteracharacter:aa:97Pressanykeytocontinueinclude<stdio.h>intmain(void)printf(,z%s%%\n","china");return0;)/*在Vc++6.0中的輸出結(jié)果是:china%include<stdio.h>intmain(void){inti,j;for(i=l;i<=9;++i)for(j=l;j〈=i;++j)printfC,%ld*%ld=%2d\n,/,i,j,i*j);printf(〃、n〃);return0;)/*在Vc++6.0中的輸出結(jié)果是:1*1=12*1=22*2=43*1=33*2=63*3=94*1=44*2=84*3=124*4=165*1=55*2=105*3=155*4=205*5=256*1=66*2=126*3=186*4=246*5=306*6=367*1=77*2=147*3=217*4=287*5=357*6=427*7=498*1=88*2=168*3=248*4=328*5=408*6=488*7=568*8=649*1=99*2=189*3=279*4=369*5=459*6=549*7=639*8=729*9=81Pressanykeytocontinuettinclude<stdio.h>〃只定義了一個(gè)數(shù)據(jù)類型,沒(méi)定義變量,數(shù)據(jù)類型名字為enumWeekdayenumWeekday〃enum是枚舉MonDay,TuesDay,WednesDay,ThursDay,FriDay,SaturDay,SunDay);intmain(void){enumWeekdayd

溫馨提示

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

評(píng)論

0/150

提交評(píng)論