當前位置:首頁 » 編程語言 » c語言程序設計例題

c語言程序設計例題

發布時間: 2022-05-27 08:41:58

⑴ 誰給一些 簡單的c語言程序設計題 ,

1.
已知
a,b
均是整型變數,寫出將
a,b
兩個變數中的值互換的程序來。

2.

a=3,b=4,c=5,x=1.2,y=2.4,z=-3.6,u=51274,n=128765,c1='a',c2='b'
。想得到以下的輸出格式和結果,請寫出程序(包括定義變數類型和設計輸出)。
a=
3
b=
4
c=
5
x=1.200000,y=2.400000,z=-3.600000
x+y=
3.60
y+z=-1.20
z+x=-2.40
u=
51274
n=
128765
c1='a'
or
97(ASCII)
c2='b'
or
98(ASCII)

3.
設圓半徑
r=1.5
,圓柱高
h=3
,求圓周長,圓面積,圓球表面積,圓球體積,圓柱體積。

4.
編程序:用
getchar
函數讀入兩個字元給
c1,c2
,然後分別用
putchar

printf
函數輸出這兩個字元。並思考以下問題:
(1)
變數
c1,c2
應定義為字元型或整型?或兩者皆可?
(2)
要求輸出
C1

C2
值的
ASCII
碼,應如何處理?用
putchar
函數還是
printf
函數?
(3)
整型變數與字元型變數是否在任何情況下都可以互相替代?如:

char
c1,c2

int
c1,c2

是否無條件地等價?

⑵ c語言程序設計題

1、
#include 「stdio.h」
main()
{
double r;
double pi=3.14159;
printf("請輸入圓的半徑:");
scanf("%lf",&r);
printf("圓的周長為:%.2lf",2*pi*r);
printf("圓的面積為:%.2lf",pi*r*r);
getch();
}

2、
#include 「stdio.h」
main()
{
char c;
printf("請輸入一個大寫字母:");
scanf("%c",&c);
printf("小寫字母為:%c",c+32);
getch();
}

3、
#include 「stdio.h」
#include "math.h"
main()
{
double a,b,c;
double p;
double area;
printf("請分別輸入三條邊的長度:");
scanf("%lf %lf %lf",&a,&b,&c);
p=(a+b+c)/2;
area=sqrt( p*(p-a)*(p-b)*(p-c));
printf("三角形的面積為:%.2lf",area);
getch();
}

⑶ c語言程序設計編程題目:請 :編寫完成對學生相關信息的要求:1.定義一個結構體類型student,其中包括三個成

#include <stdio.h>

#include <stdlib.h>

#define STU_NUM 10 /*宏定義學生的數量*/

struct student /*定義一個結構體用來存放學生學號、三門課成績、總分及平均成績*/

{

char stu_id[20]; /*學生學號;*/

float score[3]; /*三門課成績;*/

float total; /*總成績;*/

float aver; /*平均成績;*/

};

/*排序用一個函數來實現*/

void SortScore(student *stu,int n)

{

student stud;

for(int i = 0; i < n-1; i++)

for(int j = i+1 ; j < n; j++)

{

if(stu[i].total < stu[j].total)

{

stud = stu[i];

stu[i] = stu[j];

stu[j] = stud;

}

}

}

int main( )

{

student stu[STU_NUM]; /*創建結構體數組中有10個元素,分別用來保存這10個人的相關信息。*/

/*輸入這十個學生的相關信息*/

for(int i = 0; i<STU_NUM; i++)

{

printf("請輸入第%d個學生的學號:",i+1);

scanf("%s",&stu[i].stu_id);

printf("輸入第%d個學生的數學成績:",i+1);

scanf("%f",&stu[i].score[0]);

printf("輸入第%d個學生的英語成績:",i+1);

scanf("%f",&stu[i].score[1]);

printf("輸入第%d個學生的計算機成績:",i+1);

scanf("%f",&stu[i].score[2]);

stu[i].total = stu[i].score[0]+stu[i].score[1]+stu[i].score[2];

stu[i].aver = stu[i].total/3;

}

printf("\n");

SortScore(stu,STU_NUM);/*調用排序函數*/

/*輸出排序後的各學生的成績*/

for(i = 0 ; i < STU_NUM; i++)

{

printf("序號: %d\t",i);

printf("學號:%s\t",stu[i].stu_id);

printf("數學:%f\t",stu[i].score[0]);

printf("英語:%f\t",stu[i].score[1]);

printf("計算機:%f\t",stu[i].score[2]);

printf("平均成績:%f\t",stu[i].aver);

printf("總分:%f\t",stu[i].total);

printf("\n\n");

}

return 0;

}

註:(源程序中主要標識符含義說明)

#define STU_NUM 10 /*宏定義學生的數量*/

struct student /*定義一個結構體用來存放學生學號、三門課成績、總分及平均成績*/

{

char stu_id[20]; /*學生學號;*/

float score[3]; /*三門課成績;*/

float total; /*總成績;*/

float aver; /*平均成績;*/

}

⑷ 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>

int main()

{ char c;

printf("Please input a char:");

c=getchar();

printf("%c,%d ",c,c);

printf("%c,%d ",c-32,c-32);

return 0;

}

⑹ 計算機二級c語言程序設計有哪些題型

全國計算機二級C語言程序設計包括40個單選題(每題一分)和三道操作題(60分)。

單選題中1~10題為二級公共基礎知識,單選題的11~40題是C語言的內容。

操作題包括程序填空(18分)、程序改錯(18分)和編程題(24分)各一題。

程序填空是將一個完整的程序,扣掉兩到三處,讓考生將它填寫完整。由於每位考生具體抽到的題目不同,程序填空有2到3個空要填。

程序改錯也是一個完整的程序,其中有2~3處錯誤要求考生將他們改正。

編程題是要求考生編寫一個程序,然後運行出題干要求的結果。題目中主函數main()會完整給出,在主函數中將調用fun()函數,fun函數由考生自己編寫。編程題以運行結果給分,所編寫完成後必須運行,否則沒分。

二級C語言程序設計考試涉及公共基礎知識和C語言兩塊。公共基礎知識內容包括數據結構與演算法、程序設計基礎、軟體工程基礎、資料庫設計基礎四部分。考10個單選每個1分。

C語言有基礎知識(C語言概述、常量與變數、數據類型、運算符和表達式),編程三大結構(順序結構、選擇結構、循環結構),數組、函數和指針,其他內容(預處理命令、結構體和共用體、位運算、文件)四大部分內容。重點是第二、三部分。

⑺ c語言程序設計題目

選A。
B是定義一個宏,近似地看作常量。
C是定義一個整形變數m_Long

⑻ C語言程序設計題

voidfun(intnumber,charstr[])
{

/**********Program**********/
inti=0;
while(number)
{
str[i++]=number%2+'0';
number/=10;
}
/**********End**********/

}

⑼ C語言程序設計試題

1. 一條簡單語句是以_____;___字元作為結束符的,一條復合語句是分別以___{_____字元和_____}___字元作為開始符和結束符的。
2. 任何一個C++程序至少且只能包含一個_____主___函數,且程序總是從這個函數開始執行,不論這個函數的位置如何。一個函數定義由 函數頭 和 函數體 兩部分組成。
3. C++頭文件和源程序文件的擴展名分別為 .h 和 .cpp。
4. cout與操作符__<<_配合使用才能顯示輸出,cin與操作符_>>_配合使用才能實現輸入。
5. 數據類型int,char,bool,float,double, int * 等的類型長度分別為___4_、1_、_1_、_4、_8___和_____4___。
6. 數值常量46、0173和0x62對應的十進制值分別為_____46___、____123____和______98__。
7. 字元串」It\』s\40a\40C++programe!」中包含有______19____個字元。
8. 若x=5,y=10,則計算y*=++x表達式後,x和y的值分別為____6____和____60____。
9. 若x=25,則計算y=x--表達式後,x和y的值分別為____24____和__25______。
10. 假定x和ch分別為int型和char型,則sizeof(x)和sizeof(ch)的值分別為___4_____和_____1___。
11. 假定x=64,y=88,則x<<2和y>>2的值分別為____128____和___44_____。
12. 假定x是一個邏輯量,則x&&true的值與_____x___的值相同,x||false的值也與_____x___的值相同。
13. 假定x是一個邏輯量,則x&&!x和x||!x的值分別為____0____和____1____。
14. 假定x=10,則表達式x<=10?20:30的值為____20____。
15. 表達式sqrt(81)和pow(6,3)的值分別為________9______和_________216_____。
16. 數學算式(1+x)sin48°和axbex+1對應的算術表達式分別為___(1+x)*sin(48*3.14159/180)_____和_____a*pow(x,b)*exp(x+1)___。
17. 邏輯表達式:a>=x||b>2*y+10的相反式為:___~(a<=x&&2*y+10)_____。
18. 在嵌套的if語句中,每個else關鍵字與它前面最接近的____if____關鍵字相配套。
19. 在for語句中,假定循環體被執行次數為n,則<表達式1>共被計算____n___次,<表達式2>共被計算____n____次,<表達式3>共被計算____n____次。
20. 執行for和while循環時,每次是先進行____條件____的判斷,然後再執行____循環___,執行do循環時則相反。
另外,站長團上有產品團購,便宜有保證

⑽ c語言程序設計例題

題目1
#include "stdio.h"
void main(void)
{
int n=5,m=10,i=1;
long sum=1;
for(;i<=n;i++)
{
sum*=i;
}
printf("\n5!=%d",sum);
for(i=1;i<=10;i++)
{
sum*=i;
}
printf("\n10!=%d",sum);
}
題目2
#include "stdio.h"
#include "string.h"
struct Student
{
char s_Name[25];
long n_Code;
int n_English;
int n_Math;
int n_Computer;
}student_1,student_2;
void main(void)
{
printf("\nStudent1:\nName:");
scanf("%s",&student_1.s_Name);
printf("StudentNum:");
scanf("%d",&student_1.n_Code);
printf("English Score:");
scanf("%d",&student_1.n_English);
printf("Math Score:");
scanf("%d",&student_1.n_Math);
printf("Computer Score:");
scanf("%d",&student_1.n_Computer);

printf("\nStudent2:\nName:");
scanf("%s",&student_2.s_Name);
printf("StudentNum:");
scanf("%d",&student_2.n_Code);
printf("English Score:");
scanf("%d",&student_2.n_English);
printf("Math Score:");
scanf("%d",&student_2.n_Math);
printf("Computer Score:");
scanf("%d",&student_2.n_Computer);

printf("\nStudent1:\nName:%s\nStudent Number:%d\nEnglish Score:%d\nMath Score:%d\nComputer Score:%d\n",student_1.s_Name,student_1.n_Code,student_1.n_English,student_1.n_Math,student_1.n_Computer);
printf("\nStudent2:\nName:%s\nStudent Number:%d\nEnglish Score:%d\nMath Score:%d\nComputer Score:%d\n",student_2.s_Name,student_2.n_Code,student_2.n_English,student_2.n_Math,student_2.n_Computer);

}

熱點內容
銳志哪個配置性價比最高 發布:2025-02-12 17:38:43 瀏覽:918
智能推送演算法 發布:2025-02-12 17:38:41 瀏覽:835
拍照上傳器 發布:2025-02-12 17:34:29 瀏覽:652
androidweb框架 發布:2025-02-12 17:32:45 瀏覽:76
安卓編程賀卡 發布:2025-02-12 17:32:44 瀏覽:838
php獲取資料庫的欄位 發布:2025-02-12 17:29:02 瀏覽:766
伺服器地址消失 發布:2025-02-12 17:23:36 瀏覽:951
後台執行php腳本 發布:2025-02-12 17:21:45 瀏覽:471
spring編程式事務 發布:2025-02-12 17:16:55 瀏覽:398
nginx禁止ip訪問 發布:2025-02-12 17:15:14 瀏覽:274