當前位置:首頁 » 編程語言 » 求大神解答c語言
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

求大神解答c語言

發布時間: 2022-04-29 11:39:19

1. 求大神講解一下c語言定義的問題

定義數組時,是 數組名 [常量表達式]
但是現在很多編譯器做了擴展,可以設置成可變的數組,不會報錯,可能會引起內存溢出

2. c語言的題,求大神解答

解:1、A項錯誤:有些不可見字元可放入緩沖區,例如:回車、空格。
B項錯誤:有些輸入函數有緩沖區,有些沒有,例如:getchar() 有緩沖區,getch() 無緩沖區,getche() 無緩沖區。
C項錯誤:緩沖區不需要定義。
所以選D。
2、getchar()函數有緩沖區。getchar函數的返回值是用戶輸入的字元的ASCII碼,若文件結尾則返回-1(EOF),且將用戶輸入的字元回顯到屏幕。如用戶在按回車之前輸入了不止一個字元,其他字元會保留在鍵盤緩存區中,等待後續getchar調用讀取。也就是說,後續的getchar調用不會等待用戶按鍵,而直接讀取緩沖區中的字元,直到緩沖區中的字元讀完後,才等待用戶按鍵。
該程序調用getchar()函數三次,所以getchar()函數依次讀取前三個輸入的數據,空格也算,所以選B。
3、回車是用\n表示,且((c=getchar())!='\n')注意這里的圓括弧不能丟,因為!=的優先順序比=高,如果去掉了外面的括弧就等價於 c = (getchar()!='\n')。所以選C。

3. C語言急求大神解答

void process(char s1[], char s2[], char s3[])
{
int n = 0;
char* str[2] = { s1,s2 };
for (int i = 0; i < 2; i++)
{
char* p = str[i];
for (int j = 0; *p != 0; j++)
{
s3[n] = *p;
p++;
n++;
}
}
s3[n] = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (s3[j] > s3[j + 1])
{
int t = s3[j];
s3[j] = s3[j + 1];
s3[j + 1] = t;
}
}
}
}

4. C語言編程題,求大神解答!!!!

按照題目要求用二分法求方程的實根的C語言程序如下

#include <stdio.h>

#include <math.h>

double f(double x) {return 2*x*x*x - 4*x*x + x - 2;}

int main(){

double root, x1 = 0, x2 = 10,y;

root = x1+(x2-x1)/2;

y = f(root);

while(fabs(y) > 1e-6) {

if(y > 0) x2 = root;

else x1 = root;

root = x1+(x2 - x1)/2;

y = f(root);

}

printf("%.2f ",root);

return 0;

}

5. c語言程序編寫問題,求大神解答!!!求求了急!!!萬分感謝

#include <stdio.h>

char *func(char *s)

{

char *p,*q,t;

for(q=s;*q;q++);

for(q--,p=s;p<q;p++,q--)

{

t=*p;

*p=*q;

*q=t;

}

return s;

}

int main()

{

char s[100];

scanf("%[^ ]",s);

puts(func(s));

return 0;

}

6. C語言問題,求大神解答

#include<stdio.h>


void main()

{

char ch;

int a;

ch=getchar();

if(ch>='a'&&ch<='z')

ch='1';

if(ch>='A'&&ch<='Z')

ch='2';

if(ch==' ')

ch='3';

switch(ch)

{

case'1':

printf("小寫字母 ");

break;

case'2':

printf("大寫字母 ");

break;

case'3':

printf("空格 ");

break;

default:

printf("其他");

}

}

7. c語言,求大神解答。

#include "stdio.h"

int main()


{

int a[10],i,j,num=0,max,max_num;

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

{

scanf("%d",&a[i]);

if(a[i]%2==1)

num++;

}

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

{

max=a[0];

max_num=0;

for (j=0;j<9-i;j++)

{

if(max<a[j+1])

{

max=a[j+1];

max_num=j+1;

}

}

if(max_num!=9-i)

{

a[max_num]=a[9-i];

a[9-i]=max;

}

}

printf("奇數個數為%d ",num);

printf("排序後數組: ");

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

printf("%d ",a[i]);

printf(" ");

return 0;

}

8. 求大神解答C語言編程

#include <stdio.h>
#include <stdlib.h>

//定義一個結構體保存裁判id和分數
typedef struct{
unsigned char judegId;//裁判ID
unsigned char judegScore;//裁判給的分數
}judge;

int main()
{
judge jg[10];
int i;
int score;
for(i = 0;i < 10;i++)
{
printf("請輸入裁判%d打的分數\n",i+1);
scanf("%d",&score);
getchar();
if(score <= 0 || score > 100)
{
printf("輸入分數無效,重新輸入,分數要求1-100!\n");
printf("請輸入裁判%d打的分數\n",i+1);
scanf("%d",&score);
getchar();
if(score <= 0 || score > 100)
{
printf("無效輸入,程序退出!\n");
return -1;
}
}
jg[i].judegId = i;
jg[i].judegScore = score;
}

//對數組從分數低到分數高排序
for(i = 0;i < 9;i++)
{
if(jg[i].judegScore > jg[i+1].judegScore)
{
unsigned char tmpId = jg[i].judegId;
unsigned char tmpScore = jg[i].judegScore;
jg[i].judegId = jg[i+1].judegId;
jg[i].judegScore = jg[i+1].judegScore;
jg[i+1].judegScore = tmpScore;
jg[i+1].judegId = tmpId;
}
}
//列印所有得分
printf("選手得分為:\n");
for(i = 0;i < 10;i++)
{
printf("%d ",jg[i].judegScore);
}
printf("\n");

//計算評價得分
unsigned short sum = 0;
for(i = 1;i < 9;i++)
{
sum+=jg[i].judegScore;
}
unsigned char average = sum/8;
printf("去掉最高分%d,最低分%d,評價得分為%d分\n",jg[9].judegScore,jg[0].judegScore,average);

unsigned char fairIndex0 = 0;
unsigned char unfairIndex = 0;
//查找與平均值差距最小的
for(i = 1;i < 10;i++)
{
//abs為求絕對值函數
if(abs(jg[i].judegScore-average) < abs(jg[fairIndex].judegScore-average))
{
fairIndex = i;
}
}
printf("最公平的教練是%d,打分為%d\n",jg[fairIndex].judegId,jg[fairIndex].judegScore);

//查找與平均分差距最大的
for(i = 1;i < 10;i++)
{
if(abs(jg[i].judegScore-average) > abs(jg[unfairIndex].judegScore-average))
{
unfairIndex = i;
}
}
printf("最不公平的教練是%d,打分為%d\n",jg[unfairIndex].judegId,jg[unfairIndex].judegScore);
return 0;
}

//留一個問題給你,可能有兩個裁判是最公平或者最不公平的,這個自己想想怎麼做

9. c語言編程 求大神解答!

#include<stdio.h>

int main()

{//輸入UUURR,等價於上上上右右;(0,0)→(2,3)

int x=0,y=0;

int n;

char ch;

scanf("%d",&n);

getchar();//吃掉回車符

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

{

ch=getchar();//結束一個代表方向的字元

getchar();//吃掉回車符

if(ch=='L')//左

x--;

if(ch=='R')//右

x++;

if(ch=='U')//上

y++;

if(ch=='D')//下

y--;

}

printf("%d %d",x,y);

}

10. C語言問題,求大神解答

//Node* head表示頭指針

//頭指針指向頭結點,頭結點的值無用,頭結點的指針指向鏈表內第一個元素

//當NULL == head->next時鏈表為空,當NULL == head時鏈表為無效鏈表

#include <stdio.h>

#include <stdlib.h>


typedef struct Node {

int val;

struct Node* next;

}Node;


void* _malloc(size_t size) {

void* res = malloc(size);

if (NULL == res) {

printf("內存不足,程序正在退出 ");

exit(1);

}

return res;

}


void Append(Node* node, int val) {

Node* next = node->next;

node->next = _malloc(sizeof(Node));

node->next->val = val;

node->next->next = next;

}

void SortInsert(Node* head, int val) {

if (NULL != head) {

Node* last;

for (;;) {

last = head;

head = head->next;

if (NULL == head || head->val >= val) {

break;

}

}

Append(last, val);

}

}

void EraseP(Node* last) {

if (NULL != last && NULL != last->next) {

Node* next = last->next->next;

free(last->next);

last->next = next;

}

}

void Erase(Node* head, int n) {

while (n-- > 0 && NULL != head) {

head = head->next;

}

if (NULL != head) {

EraseP(head);

}

}


void ShowAll(Node* head) {

if (NULL != head) {

while (NULL != (head = head->next)) {

printf("%d -> ", head->val);

}

printf(" ");

}

}


int main(int argc, char* argv[]) {

Node* head = _malloc(sizeof(Node));

head->next = NULL;


SortInsert(head, 4); ShowAll(head);

SortInsert(head, 0); ShowAll(head);

SortInsert(head, 1); ShowAll(head);

SortInsert(head, 3); ShowAll(head);

SortInsert(head, 2); ShowAll(head);


printf(" ");


Erase(head, 3); ShowAll(head);

Erase(head, 3); ShowAll(head);

Erase(head, 0); ShowAll(head);

Erase(head, 1); ShowAll(head);

Erase(head, 0); ShowAll(head);


return 0;

}

運行截圖