Ⅰ C語言程序設計 編程題
1、
#include <stdio.h>
void main()
{
int a,b,c;
printf("輸入年月:\n");
scanf("%d%d",&a,&b);
switch(b)
{
case 2:c=(a%400==0||(a%100!=0&&a%4==0))?29:28;break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:c=31;break;
case 4:
case 6:
case 9:
case 11:c=30;break;
}
printf("%d年%d月一共有%d天\n",a,b,c);
}
2、
#include <stdio.h>
void main()
{
int m,i;
printf("請輸入一個整數:\n");
scanf("%d",&m);
for(i=2;i<m;i++)
if(m%i==0)
{printf("%d不是質數\n",m);break;}
if(i==m)
printf("%d是質數\n",m);
}
3、沒啥技術性,就是格式問題
#include <stdio.h>
void main()
{
int i,j;
for(i=1;i<=10;i++)
{
for(j=1;j<=10;j++)
printf("%5d",10*(i-1)+j);
printf("\n");
}
}
4、沒太懂你的意思,是從1900年到2010年?
#include <stdio.h>
void main()
{
int i,j=0;
for(i=1900;i<=2010;i++)
if(i%400==0||(i%100!=0&&i%4==0))
j++;
printf("閏年個數為%d\n",j);
}
5、沒看到你的公式啊
6、這個我是相當的無語了
#include <stdio.h>
void main()
{
int i,j;
printf(" ");
for(i=1;i<10;i++)
printf("%5d",i);
printf("\n");
for(i=1;i<10;i++)
{
printf("%d",i);
for(j=1;j<=i;j++)
printf("%5d",i*j);
printf("\n");
}
}
7、
#include <stdio.h>
void main()
{
int i,j,k,a[20];
for(i=0;i<20;i++)
scanf("%d",&a[i]);
for(i=0;i<19;i++)
for(j=0;j<19-i;j++)
{
if(a[j]<a[j+1])
{k=a[j];a[j]=a[j+1];a[j+1]=k;}
}
for(i=0;i<20;i++)
printf("%d\t",a[i]);
}
8、我沒聽說過選擇法啊,完全不懂。
Ⅱ 跪求C語言程序設計課後習題答案及C語言程序設計習題解答與實驗指導答案。
第一部分習題解答
第1章引言習題解答1
第2章基本的程序語句習題解答2
第3章程序的簡單演算法制定習題解答6
第4章分支結構習題解答11
第5章循環結構習題解答19
第6章函數和宏定義習題解答30
第7章數組習題解答38
第8章指針習題解答48
第9章構造數據類型習題解答56
第10章文件操作習題解答65
第11章位運算習題解答73
第二部分實驗
第1章引言實驗79
1.1目的和要求79
1.2實驗練習79
1.3綜合練習83
第2章基本的程序語句實驗83
2.1目的和要求83
2.2相關知識83
2.3實驗練習84
2.4綜合練習90
第3章程序的簡單演算法制定實驗91
3.1目的和要求91
3.2實驗練習91
第4章分支結構實驗96
4.1目的和要求96
4.2相關知識96
4.3實驗練習97
4.4綜合練習105
第5章循環結構實驗107
5.1目的和要求107
5.2相關知識107
5.3實驗練習108
5.4綜合練習118
第6章函數和宏定義實驗120
6.1目的和要求120
6.2相關知識121
6.3實驗練習122
6.4綜合練習126
第7章數組實驗127
7.1目的和要求127
7.2相關知識128
7.3實驗練習129
7.4綜合練習134
第8章指針實驗136
8.1目的和要求136
8.2相關知識136
8.3實驗練習137
8.4綜合練習144
第9章構造數據類型實驗145
9.1目的和要求145
9.2相關知識145
9.3實驗練習147
9.4綜合練習153
第10章文件操作實驗155
10.1目的和要求155
10.2相關知識156
10.3實驗練習157
10.4綜合練習164
第11章位運算實驗165
11.1目的和要求165
11.2相關知識165
11.3實驗練習166
11.4綜合練習168
第三部分其他
第12章集成開發環境介紹170
12.1Turbo C的安裝及使用170
12.1.1Turbo C的安裝170
12.1.2Turbo C簡介170
12.1.3Turbo C的使用173
12.2Borland C++的安裝及使用175
12.2.1Borland C++的安裝175
12.2.2編輯、編譯和運行程序175
第13章常見編譯錯誤信息176
13.1致命錯誤177
13.2一般錯誤177
13.3警告185
Ⅲ c語言程序設計課後習題解答與實驗指導
#include<stdio.h>
int max(int x,int y,int z)
{
int t;
t=x>y?x:y;
t=t>z?t:z;
return(t);
}
int min(int x ,int y,int z)
{
int t;
t=x<y?x:y;
t=t<z?t:z;
return(t);
}
int aver(int x ,int y,int z)
{
int t;
t=(x+y+z)/3;
return(t);
}
void main()
{ int x,y,z,a,b,c;
scanf("%d,%d,%d",&x,&y,&z);
a=(*max)(x,y,z);
b=(*min)(x,y,z);
c=(*aver)(x,y,z);
printf("%d,%d,%d\n",a,b,c);
}
建議改成:
#include<stdio.h>
int max(int x,int y,int z)
{
int t;
t=x>y?x:y;
t=t>z?t:z;
return(t);
}
int min(int x ,int y,int z)
{
int t;
t=x<y?x:y;
t=t<z?t:z;
return(t);
}
float aver(int x ,int y,int z)
{
int t;
t=(float)((x+y+z)/3.0);
return(t);
}
void main()
{ int x,y,z,a,b;float c;
scanf("%d,%d,%d",&x,&y,&z);
a=(*max)(x,y,z);
b=(*min)(x,y,z);
c=(*aver)(x,y,z);
printf("max=%d\nmin=%d\naver=%g\n",a,b,c);
}
Ⅳ c語言編程題
#include <stdio.h>
#include <math.h>
int main()
{
double x,y;
scanf("%lf",&x);
if(x<=-2)
y=-pow(exp(1),2*x+1)+3;
else if(x<=3)
y=2*x-1;
else
y=2*log10(3*x+5)-11;
printf("%lf ",y);
return 0;
}
Ⅳ c語言程序設計編程題
練習1.
#include<stdio.h>
#include<math.h>
int main()
{
float a,b,c,d,e;
printf("請輸入第一個角度數:");
scanf("%f",&a);
printf(" 請輸入第二個角度數:");
scanf("%f",&b);
c = 180 - a - b;
d = 3.141592/180;
e = sin(a*d) + sin(b*d) + sin(c*d);
printf(" 第三個角的度數為%f ",c);
printf(" 三個角的正弦和為%f ",e);
return 0;
}
Ⅵ C語言程序設計編程題
#include <stdio.h>
#define N 100
struct student
{
int num;
char name[20];
int sex;
int age;
float score[3];
};
void count(struct student *stu,int n,float *sum,float *avg)
{
int i=0,j=0;
for(i=0;i<n;i++)
{
sum[i]=0;
for(j=0;j<3;j++)
{
sum[i]+=stu[i].score[j];
}
avg[i]=sum[i]/3;
}
}
void main()
{
struct student stu[N];
int i,n;
float sum[N],avg[N];
printf("請輸入學生個數:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("請輸入第%d個學生信息:\n",i+1);
printf("學號:");
scanf("%d",&(stu[i].num));
printf("姓名:");
scanf("%s",&(stu[i].name));
printf("性別(男=0,女=1):");
scanf("%d",&(stu[i].sex));
printf("年齡:");
scanf("%d",&(stu[i].age));
printf("第一門課程成績:");
scanf("%f",&(stu[i].score[0]));
printf("第二門課程成績:");
scanf("%f",&(stu[i].score[1]));
printf("第三門課程成績:");
scanf("%f",&(stu[i].score[2]));
}
count(stu,n,sum,avg);
printf("學號\t姓名\t性別\t年齡\t課程1\t課程2\t課程3\t總分\t平均分\n");
for(i=0;i<n;i++)
{
printf("%5d ",stu[i].num);
printf("%5s ",stu[i].name);
printf("%5s ",stu[i].sex==0?"男":"女");
printf("%6d ",stu[i].age);
printf("%6.2f ",stu[i].score[0]);
printf("%6.2f ",stu[i].score[1]);
printf("%6.2f ",stu[i].score[2]);
printf("%6.2f %6.2f\n",sum[i],avg[i]);
}
}
Ⅶ C語言程序設計 清華大學出版社 黃維通 馬力妮 編著
可以,但是還要學習許多別的知識,如數據結構,演算法,網路,硬體等等。
Ⅷ c語言程序設計課後習題解答第3版
http://wenku..com/view/3ce7511810a6f524ccbf8508.html
自己下載
很容易
Ⅸ c語言程序設計習題!!10道
1. 在C程序中,只能用於整型變數的運算符是___ 求余(%)___。
2. 在C語言中,char類型變數占 2 個位元組。
3. 若a已定義為double類型,請寫出從鍵盤給a輸入數據的語句 scanf("%lf",&a); 。
4. 為使以下程序能正確運行,請填空。
#include<stdio.h>
#include<math.h>
main()
{ double x, y;
scanf("%lf%lf",&x,&y);
printf("y=%f\n", pow(x,y));}
5. 以下程序執行後的輸出結果是 -2 。
main()
{ int m=3,n=4,x;
x=-m++;
x=x+8/++n;
printf("%d\n",x); }
6. 以下程序的輸出結果是 10 20 0 。
main()
{ int a,b,c;
a=10; b=20; c=(a%b<1)||(a/b>1);
printf("%d %d %d\n",a,b,c); }
7. 以下程序中調用fun函數,對主函數x和y中的值進行對調。請填空。
void fun( double *a, double *b)
{ double x;
x=*a; *a=*b ; *b=x ; }
main()
{ double x,y;
printf(「Enter x, y : 「); scanf(「%lf%lf」,&x,&y);
fun( x,y);
printf(「x=%f y=%f\n」,x,y );}
8. C語言規定:字元串以 '\0' 作為結束標志。
9. 以下程序的輸出結果是 3 。
long fun( int n)
{ long t;
if ( n==1 || n==2 ) t=1;
else t=fun(n-1) + fun(n-2);
return ( t );
}
main( )
{ printf(「%d\n」,fun(4) );}
10. 設有定義:
struct date
{ int year, month, day ; } d1;
請寫出利用輸入語句,為變數d1中的year成員從鍵盤輸入數值的語句 scanf ("%d",&(d1.year)); 。
Ⅹ C語言課後編程題
#include<stdio.h>
intfunction(intx);
intmain(void)
{
intx,y;
printf("Enterx:");
scanf("%d",&x);
y=function(x);
printf("y=%d ",y);
}
intfunction(intx)
{
if(x==0)
return10;
elseif(x>0)
return2*x+1;
else
return-7*x*x*x+3;
}