本文目錄一覽:
大一初學C語言有若干不會的題,求解
///第一題改錯:
#include stdio.h
mian()
{
int r2=5;//變數名不能為數字開頭,將2r改成r2即可
char _3x=’A’;//同上變數名不能以-號開頭,將-改成_即可,或者改成x3也行
double i=10.5;//不能將關鍵字void作為變數名稱,這裡我把變數名稱命名為i,即改成:double i = 10.5;
printf(“r2=%d, _3x=%c, i =%f\n”,r2,_3x, i);//這句就將上面改過名字替換就行了
}
//第二題:
//計算56,80,79這3個整數的平均值。在工作區下建立工程sy02p2,並建立源程序sy02p2.c,拷備以下代碼到sy02p2.c中,以下程序已經實現計算過程的主要代碼,在(1)和(2)兩處補充相應的變數定義,使得該程序能夠正確執行並顯示出正確結果,提交sy02p2.c到本題答案處。
#include stdio.h
main()
{
int a,b,c;
float s;
a=55;
b=80;
c=79;
s=(a+b+c)*1.0/3;
printf(“s=%f\n”,s);
}
//望採納!!!
關於C語言有幾道題不會,求助大神
C正確,選C——下標從0開始,所以a[2]的值是3,a[a[2]]就是a[3],顯然a[3]是第4個數值是4。
C
A
沒有正確選項,輸出是23
C
C
A
C
C
沒有正確選項,應該是fun(10,12.5);這種形式
B
C語言題目如下,實在不會
/* 第一題如下 */
#include stdio.h
#include stdlib.h
typedef struct Student {
char name[16];
int math;
int english;
int computer;
int average;
} Student;
int compare_student_by_average(const Student *, const Student *);
void get_string(char *, size_t);
#define N 5
int main(void) {
Student students[N];
int i;
for (i = 0; i N; ++i) {
printf(“Enter the name of the student: “);
get_string(students[i].name, 16);
printf(“Enter the math, English and computer of the student: “);
scanf(“%d %d %d%*c”,
students[i].math, students[i].english, students[i].computer);
students[i].average =
(students[i].math + students[i].english + students[i].computer) / 3;
}
qsort(students, N, sizeof(Student),
(int (*) (const void *, const void *))compare_student_by_average);
for (i = 0; i N; ++i) {
if (students[i].average = 60)
printf(“%16s %3d %3d %3d\n”, students[i].name, students[i].math,
students[i].english, students[i].computer);
}
return 0;
}
int compare_student_by_average(const Student *s1, const Student *s2) {
return (s1-average s2-average ? 1 :
(s1-average == s2-average ? 0 : -1));
}
void get_string(char *str, size_t size) {
size_t i = 0;
int ch = 0;
while ((ch = getchar()) != ‘\n’)
if (i size)
str[i++] = (char)ch;
str[i] = ‘\0’;
}
第二題
#include stdio.h
#include stdlib.h
typedef struct Student {
char name[16];
int math;
int english;
int computer;
int average;
} Student;
int compare_student_by_average(const Student *, const Student *);
void get_string(char *, size_t);
int main(void) {
Student *students;
int i, N;
printf(“Enter the number of the students: “);
scanf(“%d%*c”, N);
students = malloc(sizeof(Student) * N);
for (i = 0; i N; ++i) {
printf(“Enter the name of the student: “);
get_string(students[i].name, 16);
printf(“Enter the math, English and computer of the student: “);
scanf(“%d %d %d%*c”,
students[i].math, students[i].english, students[i].computer);
students[i].average =
(students[i].math + students[i].english + students[i].computer) / 3;
}
qsort(students, N, sizeof(Student),
(int (*) (const void *, const void *))compare_student_by_average);
for (i = 0; i N; ++i)
printf(“%16s %3d %3d %3d\n”, students[i].name, students[i].math,
students[i].english, students[i].computer);
return 0;
}
int compare_student_by_average(const Student *s1, const Student *s2) {
return (s1-average s2-average ? 1 :
(s1-average == s2-average ? 0 : -1));
}
void get_string(char *str, size_t size) {
size_t i = 0;
int ch = 0;
while ((ch = getchar()) != ‘\n’)
if (i size)
str[i++] = (char)ch;
str[i] = ‘\0’;
}
關於C語言作業有幾道題不會,求助
單選題:
1、以下可作為函數 fopen 中第一個參數的正確格式是
C
A、c:\user\file.txt
B、”c:\user\file.txt”
C、”c:\\user\\file.txt
D、c:user\file.txt
2、已知結構體類型定義和變數說明,下面賦值語句中正確的是_____。 struct complex { float re,im; }z;
D 應該是z.re=10.0
A、re=10.0;
B、complex.re=10.0;
C、z→re=10.0;
D、zre=10.0
3、以下敘述中正確的是_____。
B
A、全局變數的作用域一定比局部變數的作用域範圍大
B、靜態(static)類別變數的生存期貫穿於整個程序的運行期間
C、函數的形參都屬於全局變數
D、未在定義語句中賦初值的auto變數和static變數的初值都是隨機值
4、下列敘述中錯誤的是______。
A
A、主函數中定義的變數在整個程序中都是有效的
B、在其它函數中定義的變數在主函數中也不能使用
C、形式參數也是局部變數
D、複合語句中定義的變數只在該複合語句中有效
5、在一個C源程序文件中,若要定義一個只允許在該源文件中所有函數使用的變數,則該變數需要使用的存儲類別是______。
C
A、extern
B、register
C、auto
D、statlc
判斷題:
1、 已知char ch[]=「good!!!」;則字元數組ch的長度是7。
錯
2、變數的指針就是指向該變數指針變數的值。
錯
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/159206.html