當前位置:首頁 » 編程語言 » C語言知到智慧樹答案編程新思路
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

C語言知到智慧樹答案編程新思路

發布時間: 2022-06-12 01:58:19

c語言編程求解完整答案 急急急

思路 8 個數;

從小到大排列;

從中間切開; 1 2 3 4 -> 5 6 7 8;

然後一個一個比較符合就加一

試了一下....

#include<stdio.h>
#defineL15000
intmain(void)
{
shortdais[L]={0};
intn,i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%hd",&dais[i]);
inttmp,j;
for(i=0;i<n;i++){
tmp=dais[i];
for(j=i+1;j<n;j++){
if(dais[j]<tmp){
dais[i]=dais[j];
dais[j]=tmp;
tmp=dais[i];
}
}
}
intyin=0;
for(i=n-1;i>=n/2;i--){
for(j=n/2;j>0;j--)
if((2*dais[j-1]<=dais[i])&&(dais[j-1]!=0)){
dais[i]=0;
dais[j-1]=0;
yin++;
break;
}

}
printf("%d",yin);
return0;
}

❷ 急求C語言編程答案!!!高手請進!!1

雖然覺得你給的三個條件有點混亂,但是還是按照其編寫出如下代碼。

#include<stdio.h>

int main()

{
int score[5]={0};
int sum = 0;
int i = 0;

printf("Please input the score of student(enter after each input and start with s1):\n");

for(i=0; i<5; i++)
{
scanf("%d", &score[i]);
sum += score[i];
}

if(sum < 450)
{
printf("Sorry, you can not get the scholarship.\n");
return 0;
}
if(score[0] < 88 || score[1] < 88 || score[2] < 88 || score[3] <88 || score[4] < 88)
{
printf("Sorry, you can not get the scholarship.\n");
return 0;
}
if(score[0] < 95 || score[1] < 95 || score[2] < 95 || score[3] <80 || score[4] < 80)
{
printf("Sorry, you can not get the scholarship.\n");
return 0;
}

printf("Congralations! You will get the scholarship!\n");

}

❸ c語言編程題目及答案

#include <stdio.h>
#include <math.h>
void main(void)
{
double a;

double b;

double c;/* 以上三個變數分別對應三邊 */

double sin_c;/* c邊對應角的正玄值 */

double cos_c;/*c邊對應角的余玄值*/

double cos_a;

double area; /* 三角形的面積 */

printf("輸入a,b,c:");

scanf("%lf, %lf, %lf", &a, &b, &c);

if(((a+b)>c) && (a-b)<c)
{
printf("三邊能夠成三角形\n.");

cos_c = (a*a + b*b -c*c)/(2*a*b);

cos_a = (b*b + c*c - a*a)/(2*b*c);

if ((cos_c > 0) && (cos_a >0))
{
printf("三角形是銳角三角形。\n");
}

else if ((cos_c < 0) || (cos_a < 0))
{
printf("三角形是鈍角三角形\n");
}
else
{
printf("三角形是直角三角形\n");
}

sin_c = sqrt(1- cos_c*cos_c);

area = a*b*sin_c/2;

printf("三角形的面積是%f.\n",area);
}
else
{
printf("三邊不能構成三角形\n");
}
}

❹ c語言編程題答案

#include <stdio.h>
int Fib (int n);//函數聲明
void main ()
{
int i,n;
printf ("input the n: ");
scanf ("%d",&n);
printf ("斐波契數列的前%d項為:\n",n);//輸入項數
for (i=0;i<=n;i++)
printf ("%d ",Fib (i));
printf ("\n");
}
int Fib (int n)
{
if (n==0||n==1)
return 1;
return Fib(n-2)+Fib(n-1);
}

❺ 求智慧樹C語言第二章測試題答案!急

這種資源建議去官網論壇或者一些其他比較知名的大論壇里咨詢
答題不易,互相理解,您的採納是我前進的動力
如果我的回答沒能幫助您,請繼續追問
您也可以向我們團隊發出請求,會有更專業的人來為您解答

❻ 急求c語言編程答案

// test.cpp : 定義控制台應用程序的入口點。
//

// test1.cpp : Defines the entry point for the console application.
//
// test.cpp : Defines the entry point for the console application.

# include "stdafx.h"
# include "stdio.h"
# include "stdlib.h"
# include <iostream>
# include <fstream>
# include <iomanip> /*需引用的頭文件*/
using namespace std;

struct node /*定義結點結構體保存結點信息*/
{
struct student /*定義結構體變數student保存學生的信息*/
{
char studentnumber[10]; /*學生學號*/
char studentname[5]; /*學生姓名*/
struct course /*定義結構體變數Course保存課程信息*/
{
float course1; //*********************************
float course2;
float course3; //各門課程的分數和平均分
float averagemark; //*****************************
};struct course allcourse;
};struct student stu;
struct node *next;
};

node *top;

struct node *createlist(char info[2][9],float marksinfo[]) //**************************
{

static struct node *new_node,*current_node;

new_node=(struct node *)new(node); /*建立新的結點*/
strcpy(new_node->stu.studentnumber,info[0]);
strcpy(new_node->stu.studentname,info[1]);
new_node->stu.allcourse.course1=marksinfo[0];
new_node->stu.allcourse.course2=marksinfo[1];
new_node->stu.allcourse.course3=marksinfo[2]; //對結點的元素付值
new_node->stu.allcourse.averagemark=(marksinfo[0]+
marksinfo[1]+marksinfo[2])/3;
new_node->next=NULL;
if (top==NULL)
{
top=new_node;
current_node=top;
}

current_node->next=new_node; /*指向新的結點*/
current_node=new_node; /*總指向新的結點*/
return top; //*****************************
}
void studentaverage(node *top) /*顯示平均分函數*/
{
int i=0,maxcount=0; /*結點的數目maxcount*/
char response='y';
struct node *t=top;

fstream readcount("countsave.txt",ios::in); /*定義文件流*/
readcount>>maxcount; /*將文件信息讀入變數Maxcount*/
system("cls"); /*清屏*/

cout.flags(ios::left); /*輸出格式為左對齊*/
cout<<setw(14)<<"學號"<<setw(14)<<"姓名"<<setw(14)<<"課程1"<<setw(14)
<<"課程2"<<setw(14)<<"課程3"<<"平均分"<<endl;

for (i=0;i<maxcount;i++)
{
t=top;
top=top->next;

cout.flags(ios::left);

cout<<setw(14)<<t->stu.studentnumber<<setw(14)<<
t->stu.studentname<<setw(14)<<t->stu.allcourse.course1<<setw(14)<<t->stu.allcourse.course2
<<setw(14)<<t->stu.allcourse.course3<<setw(14)<<t->stu.allcourse.averagemark<<endl;
}

system("pause");
}

void courseaverage(node *top)/*顯示每門課程的平均分*/
{
int maxcount;
node *t=top;
float courseaverage_1=0.00;//********************************
float courseaverage_2=0.00;// 保存各門平均分的變數
float courseaverage_3=0.00;//********************************

fstream readcount("countsave.txt",ios::in);
readcount>>maxcount;
system("cls");

for (int i=0;i<maxcount;i++) //********************************************************************
{
t=top;
top=top->next; //遍歷結點累加各門課程分數求平均值
float(courseaverage_1)+=float(t->stu.allcourse.course1);
courseaverage_2+=t->stu.allcourse.course2;
courseaverage_3+=t->stu.allcourse.course3;
} //********************************************************************

cout.flags(ios::left);
cout<<setw(25)<<"課程1"<<setw(25)<<"課程2"<<setw(25)<<"課程3"<<endl;

cout<<setw(25)<<float(courseaverage_1/(maxcount+1))<<setw(25)<<
courseaverage_2/float(maxcount+1)<<setw(25)<<courseaverage_3/float(maxcount+1)<<endl;

system("pause");
}
void orderWithAverageMark(node *top)/*按平均分排序*/
{

struct node *t=top;
static struct node *t0=top; /*保存結點的頭*/
float averagemark_1=0.00;
float averagemark_2=0.00;
static char temp[10]; /*保存字元串的中間變數*/
float temp0; /*整型變數的中間變數*/
int maxcount;
int i;
bool flag; /*判斷冒泡演算法是否結束*/

fstream readcount("countsave.txt",ios::in||ios::out);
readcount>>maxcount;
//*****************************************************************************
//冒泡排序
//if (count
for(int j=0;j<maxcount;j++)
{

top=t0; //結點指針指向表頭,執行下一次排序

for (i=0;i<(maxcount-1);i++)
{
flag=false;
t=top;
averagemark_1=t->stu.allcourse.averagemark;
averagemark_2=top->next->stu.allcourse.averagemark;

if (averagemark_1<=averagemark_2)
{ //****************************************************************
strcpy(temp,t->stu.studentnumber);
strcpy(t->stu.studentnumber,top->next->stu.studentnumber);
strcpy(top->next->stu.studentnumber,temp);

strcpy(temp,t->stu.studentname);
strcpy(t->stu.studentname,top->next->stu.studentname);
strcpy(top->next->stu.studentname,temp);

temp0=t->stu.allcourse.course1;
t->stu.allcourse.course1=top->next->stu.allcourse.course1; //交換兩結點的各數值
top->next->stu.allcourse.course1=temp0;

temp0=t->stu.allcourse.course2;
t->stu.allcourse.course2=top->next->stu.allcourse.course2;
top->next->stu.allcourse.course2=temp0;

temp0=t->stu.allcourse.course3;
t->stu.allcourse.course3=top->next->stu.allcourse.course3;
top->next->stu.allcourse.course3=temp0;

temp0=t->stu.allcourse.averagemark;
t->stu.allcourse.averagemark=top->next->stu.allcourse.averagemark;
top->next->stu.allcourse.averagemark=temp0; //*************************************************************
flag=true;
}

top=top->next;
}
}
//********************************************************************************************
}

int menu()//主菜單
{
int choice;
cout<<"*******************************************************************************"<<endl;
cout<<"* *"<<endl;
cout<<"* 1. 輸入學生信息 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 2. 顯示學生平均分 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 3. 顯示每門課的平均分 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 4. 顯示總分在某平均分以上的學生 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 5. 保存數據 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 0. 退出 *"<<endl;
cout<<"* *"<<endl;
cout<<"*******************************************************************************"<<endl;
cout<<" "<<endl;
cout<<" 請選擇:";

loop:cin>>choice;

if (choice>=0&&choice<=5)
return choice;
else
goto loop;

}
int findstdentnumber(node *top,char namestr[5])
{
node *t=top;
int count;

fstream readcount("countsave.txt",ios::in);
readcount>>count;

for (int i=0;i<count;i++)
{
t=top;
top=top->next;
if (strcmp(namestr,t->stu.studentnumber)==0)
{
return 1;
}
}
return 0;
}

node *getinfo()
{
char response='y';
char studentinfo[2][9]; //二維數組保存學號和姓名
float studentcoursemark[3]; //保存各科成績
int count=0;
static int count0;

void savestudentinfo(node *);
node *readstudentinfo();
void freelist(node *);

fstream readcount("countsave.txt",ios::in);/*讀出結點值*/
readcount>>count0;
readcount.close();

do
{
loop0: system("cls");
cout<<endl;
cout<<"請輸入學號:";
cin>>studentinfo[0];
cout<<endl;
if(findstdentnumber(top,studentinfo[0]))
{
cout<<"該學號已存在:"<<endl;
system("pause");
strcpy(studentinfo[0]," ");
goto loop0;
}
cout<<"姓名:";
cin>>studentinfo[1];
cout<<endl;
cout<<"課程1:";
cin>>studentcoursemark[0];
cout<<endl;
cout<<"課程2:";
cin>>studentcoursemark[1];
cout<<endl;
cout<<"課程3:";
cin>>studentcoursemark[2];
top=createlist(studentinfo,studentcoursemark);
count++;
cout<<endl;
cout<<"要繼續嗎?(y or n)";
cin>>response;
}while(count>=0&&count<30&&(response=='y'||response=='Y'));

orderWithAverageMark(top); /*對鏈表按學生平均分進行排序*/

fstream savecount("countsave.txt",ios::out);
savecount<<(count+count0);/*保存結點值並累加*/
savecount.close();

savestudentinfo(top); /*保存學生信息到文件*/

return top;
}
void savestudentinfo(node *top) /*保存學生信息*/
{
int i,numberofstudent;
node *head=top;

fstream count("countsave.txt",ios::in);
count>>numberofstudent; /*獲得學生個數*/
count.close();

orderWithAverageMark(head);

fstream student("studentinfosave.txt",ios::out);

system("cls");

//遍歷鏈表,保存信息
for (i=0;i<numberofstudent;i++)
{

head=top;
top=top->next;
student<<head->stu.studentnumber<<" "<<head->stu.studentname<<" "<<
head->stu.allcourse.course1<<" "<<head->stu.allcourse.course2<<" "<<
head->stu.allcourse.course3<<endl;

}
student.close();
//*********************
cout<<" 保存成功!"<<endl;
system("pause");
}
node *readstudentinfo() /*從文件讀取學生信息*/
{
int numberofstudent;
char studentinfo[2][9];
float studentcoursemark[3];

fstream readcount("countsave.txt",ios::in);
fstream readstuinfo("studentinfosave.txt",ios::in);
readcount>>numberofstudent;

for (int i=0;i<numberofstudent;i++)
{

readstuinfo>>studentinfo[0]>>studentinfo[1]>>studentcoursemark[0]>>
studentcoursemark[1]>>studentcoursemark[2];

top=createlist(studentinfo,studentcoursemark);
}

readcount.close();
readstuinfo.close();
return top;
}

void find(node *top)/*查找函數*/
{
int lowmark=0,i=0,count=0;
struct node *t=top;

system("cls");

cout<<"請輸入一個平均分的下限:";
cin>>lowmark;

system("cls");

fstream readcount("countsave.txt",ios::in);
readcount>>count;

cout.flags(ios::left);
cout<<setw(14)<<"學號"<<setw(14)<<"姓名"<<setw(14)<<"課程1"<<setw(14)
<<"課程2"<<setw(14)<<"課程3"<<setw(14)<<"平均分"<<endl;

if(lowmark>=0&&lowmark<=100)
{
for(int j=0;j<count;j++)
{
t=top;
top=top->next;
if(lowmark<=(t->stu.allcourse.averagemark))//****************************顯示滿足條件的信息
{
cout<<setw(14)<<t->stu.studentnumber<<setw(14)<<t->stu.studentname<<setw(14)<<t->stu.allcourse.course1<<setw(14)
<<t->stu.allcourse.course2<<setw(14)<<t->stu.allcourse.course3<<setw(14)<<t->stu.allcourse.averagemark<<endl;
i++;
}
} //****************************
if (i==0)
{
cout<<endl;
system("cls");
cout<<"找不學生信息!"<<endl;
}
cout<<"共找到"<<i<<"條信息!"<<endl;

system("pause");
}
}

void main()
{

top=readstudentinfo(); /*讀取學生信息*/

for(;;)
{
system("cls");

switch(menu())
{

case 1:
top=getinfo();
break;

case 2:
studentaverage(top);
break;

case 3:
courseaverage(top);
break;
case 4:
find(top);
break;
case 5:
savestudentinfo(top);
break;
case 0:
exit(0);
break;

}
}

}

❼ 如何提高C語言解題思路,看到個實際問題,要定義很多變數,但想一會就迷糊了,一看答案就明白了點

總的來講解題思路是靠積累出來的,平時從小程序入手慢慢熟練後搞一些大一點的工程,慢慢就會有所提高了。

對於一個問題,就我個人而言,覺得分模塊解決是最容易獲得清晰的解題思路的。
首先是審題,這個我們從小學就做過了,審題一方面要對整個題目有個總體認識,另一方面是我們獲得思路最直接的線索。一般來講,任何一個稍大的C問題都不能通過一個函數解決。即便只需要一個函數,也是要分為多條語句來解決的。如何劃分每個函數的功能,這個可以見仁見智。我經常採用的做法是從題目入手。首先看題目是否存在標點符號。一般來講,一個完整句子可以劃分為一個大塊,有幾個句子就可以分為幾個部分。然後每個部分再通過,逗號,分號等依次劃分為不同的小部分。每個小部分通過分析句子成分,將名詞設為變數或類,將謂語部分寫成函數。這樣一個問題的思路雛形就有了。然後再仔細分析各部分的相關性,刪除或修改不合理的地方,一個問題基本就算解決了。

如果問題較短,可以直接從句子成分入手,分析需要對哪些對象進行哪些處理。如果問題較復雜,可以現將關聯較大的部分整理出來,看成一個整體,然後先分析每個部分之間如何關連,每個部分如何細化。基本上解題思路可以從中得到。

另一方面,對於基礎知識的掌握也有助於解題。如一些常用的演算法,可以很快的想到該如何解決某些問題,又如,對於常用的數據類型要能夠熟練運用。可以第一時間想到哪些對象用哪些數據結構合適,哪些次之,哪些不合理。這些基本知識的熟練可以幫助你在第一時間對程序的整體框架有個認識。

PS:敲了很多,不知道樓主看懂沒。這個東西就是熟能生巧。某個問題遇到一次之後再遇到一次自然很快就想出來了,思路自然也會比第一次清晰很多的。

❽ c語言編程題及答案

【4.1】已知銀行整存整取存款不同期限的月息利率分別為:
0.315% 期限一年
0.330% 期限二年
月息利率 = 0.345% 期限三年
0.375% 期限五年
0.420% 期限八年
要求輸入存錢的本金和期限,求到期時能從銀行得到的利息與本金的合計。

【4.2】輸入年份year和月month,求該月有多少天。判斷是否為閏年,可用如下C語言表達式:year%4==0 && year0!=0 || year@0==0。若表達式成立(即表達式值為1),則year為閏年;否則,表達式不成立(即值為0),year為平年。

【4.3】編寫一個簡單計算器程序,輸入格式為:data1 op data2。其中data1和data2是參加運算的兩個數,op為運算符,它的取值只能是+、-、*、/。

【4.4】輸入n值,輸出如圖所示矩形。

【4.5】輸入n值,輸出如圖所示平行四邊形。

【4.6】輸入n值,輸出如圖所示高為n的等腰三角形。

【4.7】輸入n值,輸出如圖所示高為n的等腰三角形。

【4.8】輸入n值,輸出如圖所示高和上底均為n的等腰梯形。

【4.9】輸入n值,輸出如圖所示高和上底均為n的等腰空心梯形。

【4.10】輸入n值,輸出如圖所示邊長為n的空心正六邊型。

❾ C語言編程,跪求答案!

# include <stdio.h>
main()
{int a[23]={11,19,9,12,5,20,1,18,4,16,6,10,15,2,17,3,14,7,13,8,11,19,9};
int b[20];
for(i=0;i<20;i++)
int d;
int c;
b[i]=a[i]+a[i+1]+a[i+2]+a[i+3];
c=b[0];d=1;
for(i=0;i<20;i++)
if (b[i]>c){c=b[i];d=i+1;}
printf("%d",d)
}
給出起始位置。

❿ 2019智慧樹知到[C語言程序設計]章節答案

在大學答案幫手小程序裡面就能找到
你可以去搜索一下