A. 一道c語言編程題,各位大神幫幫忙啊!
代碼如下:
#include<stdio.h>
#include<stdlib.h>
intmain()
{
intscore=0,sum=0,max=0,min=100,count=0,aver=0;
printf("請輸入學生成績:");
scanf("%d",&score);
while(score>=0&&score<=100){
sum+=score;
if(score>max){
max=score;
}
if(score<min){
min=score;
}
count++;
scanf("%d",&score);
}
printf("共錄入了%d個學生成績。 ",count);
printf("最高分:%d ",max);
printf("最低分:%d ",min);
printf("平均分:%d ",sum/count);
system("pause");
return0;
}
B. C語言編程題,有請大神幫助下
#include"stdio.h"
#include<string.h>
struct{
charw[21];
intn;
}t[100000];
chars[100000][21];
intmain(intargc,char*argv[]){
intN,i,j,k,x;
printf("PleaseenterN(int0<N<100001)... N=");
if(scanf("%d",&N)!=1||N<1||N>100000){
printf("Inputerror,exit... ");
return0;
}
printf("Pleaseenter%dstrings... ",N);
for(i=0;i<N;scanf("%20s",s[i++]));//輸入字元串
for(strcpy(t[0].w,s[0]),t[0].n=k=i=1;i<N;i++){
for(j=0;j<k;j++)
if(strcmp(s[i],t[j].w)==0){
t[j].n++;
break;
}
if(j>=k){
strcpy(t[k].w,s[i]);
t[k++].n=1;
}
}
printf("----------------- ");
for(i=1;i<=k;i++){
for(x=j=0;j<k;j++)
if(t[j].n==i)
x++;
if(x)
printf("%d%d ",i,x);
}
return0;
}
運行樣例:
C. C語言編程題,求大神!!!
按照你的要求編寫的用牛頓迭代法求解方程的根的C語言程序如下
#include<stdio.h>
#include<math.h>
int main(){
double x=0,x0;
do{
x0=x;
x=x0-(cos(x)-x)/(-sin(x)-1);
}while(fabs(x-x0)>=1e-5);
printf("%.2f",x);
return 0;
}
D. C語言程序編程題,求大神幫幫忙
#include<stdio.h>
int main()
{ struct stu
{ int id;
char name[11];
int a,b,c;
} t,st[5];
int i,j;
FILE *fp1,*fp2;
if((fp1=fopen("d:\stud.dat","r"))==NULL)
{ printf("f1 open error! ");
return 1;
}
if((fp2=fopen("d:\studsort.dat","w"))==NULL)
{ printf("f2 open error! ");
return 2;
}
for(i=0; i<5; i++)
fscanf(fp1,"%d%s%d%d%d",&st[i].id,st[i].name,&st[i].a,&st[i].b,&st[i].c);
for(i=0; i<4; i++)
for(j=0; j<4-i; j++)
if(st[j].a+st[j].b+st[j].c<st[j+1].a+st[j+1].b+st[j+1].c)
{ t=st[j];
st[j]=st[j+1];
st[j+1]=t;
}
for(i=0; i<5; i++)
{ printf("%d %10s %4d %4d %4d %7.2f ",st[i].id,st[i].name,st[i].a,st[i].b,
st[i].c,(st[i].a+st[i].b+st[i].c)/3.0);
fprintf(fp2,"%d %10s %4d %4d %4d %7.2f ",st[i].id,st[i].name,st[i].a,st[i].b,
st[i].c,(st[i].a+st[i].b+st[i].c)/3.0);
}
fclose(fp1);
fclose(fp2);
return 0;
}
E. C語言編程題,求助大神
#include <iostream>
#include <time.h>
unsigned int CalcDayOfMonth(unsigned int year, unsigned int month);
bool IsLeapYear(unsigned int year);
struct Time
{
unsigned int year;
unsigned int month;
unsigned int day;
void setTime(unsigned int y = 1900, unsigned int m = 1, unsigned int d= 1)
{
year = y; month = m;
if (d > CalcDayOfMonth(year, month))
day = CalcDayOfMonth(year, month);
else
day = d;
}
Time operator-(Time& t)
{
Time tmp;
if (t > * this)
{
tmp = t;
t = *this;
*this = tmp;
}
else
tmp = *this;
if (tmp.day >= t.day)
{
tmp.day -= t.day;
}
else
{
tmp.day = CalcDayOfMonth(tmp.year, tmp.month-1) + tmp.day-t.day;
tmp.month--;
}
if (tmp.month >= t.month)
tmp.month -= t.month;
else
{
tmp.month = tmp.month + 12 - t.month;
tmp.year--;
}
tmp.year -= t.year;
Time tmp1 = t;
int d=0;
while (!(*this==tmp1))
{
tmp1.day++;
d++;
if (CalcDayOfMonth(tmp1.year, tmp1.month) < tmp1.day)
{
tmp1.day = 1;
tmp1.month++;
}
if (tmp1.month > 12)
{
tmp1.month = 1;
tmp1.year++;
}
}
printf("累計相差:%d天 ", d);
return tmp;
}
bool operator==(Time& t)
{
bool b=this->day == t.day && this->month == t.month && this->year == t.year;
return b;
}
bool operator>(Time& t)
{
if (this->year > t.year)
return true;
else if (this->year == t.year)
{
if (this->month > t.month)
return true;
else if (this->month == t.month)
{
if (this->day > t.day)
return true;
else
return false;
}
else
return false;
}
else
return false;
}
};
void show(Time t)
{
printf_s("%d年-%u月-%u日 ", t.year, t.month, t.day);
}
bool IsLeapYear(unsigned int year)
{
if ((year % 400 == 0) || (year % 100 != 0) && (year % 4 == 0))
return true;
return false;
}
unsigned int CalcDayOfMonth(unsigned int year, unsigned int month)
{
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 4:
case 6:
case 9:
case 11:
return 30;
case 2:
return IsLeapYear(year) ? 29 : 28;
}
return 0;//返回0則表示月份輸入不正確
}
int main()
{
Time t1, t2;
printf_s("請輸入兩個時間(格式:年 月 日): ");
scanf_s("%u %u %u", &t1.year, &t1.month, &t1.day);
scanf_s("%u %u %u", &t2.year, &t2.month, &t2.day);
show(t1 - t2);
}
F. C語言結構體編程題,求助大神
#include<stdio.h>
typedef struct __student_info
{
char num[10];
char name[10];
float score;
} student_info;
int main(void)
{
student_info info[5];
printf("請輸入5名學生信息(學號 姓名 成績):
");
for(int i = 0; i < 5; i++)
{
scanf("%s %s %f",info[i].num,info[i].name,&info[i].score);
}
float sum = 0;
for(int i = 0; i < 5; i++)
{
sum += info[i].score;
}
float average = sum/5;
printf("高於平均成績的學生信息如下:
");
for(int i = 0; i < 5; i++)
{
if(info[i].score > average)
{
printf("%s %s %.1f
",info[i].num,info[i].name,info[i].score);
}
}
return 0;
}
G. C語言指針編程題,求助大神解答
#include<stdio.h>
int a[200];
void rotateArray(int *a,int n,int m){
m%=n; //這句是防止m大於n 結果會不正確的情況
for(int i=m;i<n;++i)scanf("%d",&a[i]);
for(int i=0;i<m;++i)scanf("%d",&a[i]);
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
rotateArray(a,n,m);
printf("%d",a[0]);
for(int i=1;i<n;++i)printf(",%d",a[i]);
return 0;
}
H. C語言編程題,求助大神!
#include <stdio.h>
#include <string.h>
#define N 10000
int main()
{
FILE *fp1,*fp2,*fp3;
char str1[N],str2[N];
fp1=fopen("D:\666.txt","r");
fp2=fopen("D:\888.txt","r");
fp3=fopen("D:\999.txt","w");
while(fgets(str1,N,fp1)!=NULL)//將文件中的每一個非空字元儲存在數組str1中
while(fgets(str2,N,fp2)!=NULL)//同上
puts(str1);//輸出文件的內容
puts(str2);
strcat(str1,str2);//兩個字元串連接
fprintf(fp3,"%s",str1);//將連接後的字元串寫入第3個文件
fclose(fp1);//關閉文件
fclose(fp2);
fclose(fp3);
return 0;
}