⑴ c語言編程題
給你個思路。
用putchar獲得輸入的字元串,然後判斷單個字元是否是aeiou,同時判斷這是第幾個字元(while((w=getchar())!=EOF,中間設置一個變數累加就可以判斷是第幾個字元)
碰到了aeiou就輸出那個變數。
⑵ 各種求!!!!c語言編程題!!!1
題目已經說的很清楚了,用一個長度為26的int數組存放各個字母的使用頻率,然後不能用if或者switch,只能用ASCII碼來計算,那就搞清楚他們之間的對應關系就行,比如a是97,A是65,假如a後者A的頻率存在數組的0號位置,遍歷輸入串的時候碰到a或者A(也就是ASCII碼值為97或者65)時,0號位置的數就加1,其他類似!當然他還需要你把大寫字母轉換為小寫,這個也只是把大寫字母的ASCII碼值減去32而已,就這么簡單!
至於排序,由於是用數組存儲,數組本身已經可以隨機存儲,所以排序已經變得比較方便了,至於題目要求你用指針數組,那你就按要求做,都差不多,排序建議你用快速排序演算法!
至於輸入串,因為只需要遍歷一遍就可以,所以可以採用數組,也可以用鏈表來存儲,你要用其他結構也行!
⑶ C語言編程題.答案越簡單越好
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define true 1
struct student
{
char name[60];
char ID[7];
int score;
};int dq(struct student st[]);
void xianshi();
void bc(struct student st[]);
void add();
void select();
void zz();
void chazhao();
void xhcz();
void xmcz();
void del();
void xmsc();
void xhsc();
void tj();
void bjg();
void xg();
void xhxg();
void xmxg();
void bca();
void fh();
struct student st[300];
int Number=0;
void main()
{
int choose=0;
FILE *fp=NULL;
char yesorno; if((fp=fopen("C://student.dat","rb"))==NULL)
{
printf("\n=========>提示:文件不存在,是否要創建一個?(y/n)\n");
scanf("%c",&yesorno);
if(yesorno=='y'||yesorno=='Y')
{
fp=fopen("C://student.dat","wb");
fclose(fp);
}
else
exit(0);
}
else
{
Number=dq(st);
}
system("cls");
while(true)
{
xianshi();
printf("\t\t====>請選擇:");
scanf("%d",&choose);
system("cls");
switch(choose)
{
case 0: exit(0);fh();break;
case 1: add();fh();break;
case 2: select();fh();break;
case 3: chazhao();fh();break;
case 4: del();fh();break;
case 5: tj();fh();break;
case 6: bjg();fh();break;
case 7: xg();fh();break;
case 8:zz();fh();break;
case 9:bca();break;
default:break;
}
fflush(stdin);
getchar();
system("cls");
}
} void bca()
{
printf("\t=====程序在運行時已自動保存.....\n");
}void fh()
{
printf("\t===>按Enter鍵返回主菜單\n");
}void xg()
{
int way=0;
printf("請選擇修改查找方式\n");
printf("1 按姓名查找修改\n");
printf("2 按學號查找修改\n");
scanf("%d",&way);
switch(way)
{
case 1: xmxg();break;
case 2: xhxg();break;
default: printf("輸入有誤,結束!\n");break;
}
}
void xmxg()
{
FILE *fp=NULL;
char name[60];
int i=0;
int changeIndex=0;
int index=0;
printf("請輸入要修改的學生姓名:");
scanf("%s",name);
for (i=0;i<Number;i++)
{
if (strcmp(name,st[i].name))
{
changeIndex=i;
}
break;
}
printf("\t姓名\t學號\t成績\n");
printf("\t%s\t%s\t%d\n\n",st[changeIndex].name,st[changeIndex].ID,st[changeIndex].score);
printf("請重新輸入該學生信息");
printf("姓名:");
scanf("%s",st[changeIndex].name);
printf("學號:");
scanf("%s",st[changeIndex].ID);
printf("成績:");
scanf("%d",&st[changeIndex].score);
fp=fopen("C://student.dat","wb");
for (i=0;i<Number;i++)
{
fwrite(&st[i],sizeof(struct student),1,fp);
}
fclose(fp);
}
void xhxg()
{
FILE *fp=NULL;
char id[60];
int i=0;
int changeIndex=0;
int index=0;
printf("請輸入要修改的學生學號:");
scanf("%s",id);
for (i=0;i<Number;i++)
{
if (strcmp(id,st[i].ID))
{
changeIndex=i;
}
break;
}
printf("\t姓名\t學號\t成績\n");
printf("\t%s\t%s\t%d\n\n",st[changeIndex].name,st[changeIndex].ID,st[changeIndex].score);
printf("請重新輸入該學生信息");
printf("姓名:");
scanf("%s",st[changeIndex].name);
printf("學號:");
scanf("%s",st[changeIndex].ID);
printf("成績:");
scanf("%d",&st[changeIndex].score);
fp=fopen("C://student.dat","wb");
for (i=0;i<Number;i++)
{
fwrite(&st[i],sizeof(struct student),1,fp);
}
fclose(fp);
printf("\t=======>修改成功\n");
}void bjg()
{
int i=0;
printf("以下是不及格:\n");
printf("\t姓名\t學號\t成績\n");
for (i=0;i<Number;i++)
{
if (st[i].score<60)
{
printf("\t%s\t%s\t%d\n",st[i].name,st[i].ID,st[i].score);
}
}
}
void tj()
{
int i=0;
double sum=0.0;
for(i=0;i<Number;i++)
{
sum+=st[i].score;
}
printf("全班總分為:%f\n",sum);
printf("平均分為:%f\n",sum/Number);
}
void del()
{
int n=0;
printf("1 按姓名刪除\n");
printf("2 按學號刪除\n");
scanf("%d",&n);
switch(n)
{
case 1: xmsc();break;
case 2: xhsc();break;
}
}
void xmsc()
{
FILE *fp=NULL;
char name[60];
int i=0;
int j=0;
printf("請輸入要刪除的學生姓名:");
scanf("%s",name);
for(i=0;i<Number;i++)
{
if(strcmp(name,st[i].name)==0)
{
for (j=i;j<Number-1;j++)
{
st[j]=st[j+1];
}
Number--;
}
}
fp=fopen("C://student.dat","wb");
for (i=0;i<Number;i++)
{
fwrite(&st[i],sizeof(struct student),1,fp);
}
fclose(fp);
printf("刪除成功;\n");
}void xhsc()
{
FILE *fp=NULL;
char id[60];
int i=0;
int j=0;
printf("請輸入要刪除的學生學號:");
scanf("%s",id);
for(i=0;i<Number;i++)
{
if (strcmp(id,st[i].ID)==0)
{
for (j=i;j<Number-1;j++)
{
st[j]=st[j+1];
}
Number--;
}
}
fp=fopen("C://student.dat","wb");
for (i=0;i<Number;i++)
{
fwrite(&st[i],sizeof(struct student),1,fp);
}
fclose(fp);
printf("刪除成功;\n");
}void chazhao()
{
int n=0;
printf("1 按姓名查找\n");
printf("2 按學號查找\n");
scanf("%d",&n);
switch(n)
{
case 1: xmcz();break;
case 2: xhcz();break;
default: printf("輸入有誤,結束!\n");
break;
}
}void xhcz()
{
char id[7];
int i=0;
printf("請輸入要查找學生學號:");
scanf("%s",id);
system("cls");
printf("\t姓名\t學號\t成績\n");
for(i=0;i<Number;i++)
{
if (strcmp(id,st[i].ID)==0)
{
printf("\t%s\t%s\t%d\n",st[i].name,st[i].ID,st[i].score);
}
}
}
void xmcz()
{
char name[7];
int i=0;
printf("請輸入要查找學生姓名:");
scanf("%s",name);
system("cls");
printf("\t姓名\t學號\t成績\n");
for (i=0;i<Number;i++)
{
if (strcmp(name,st[i].name)==0)
{
printf("\t%s\t%s\t%d\n",st[i].name,st[i].ID,st[i].score);
}
}
}
void zz()
{
printf("\t**********************************************************\n\n");
printf("\t^^^^^^^^^ 《學生成績管理系統》 ^^^^^^^^^^\n\n");
printf("\t^^^^^^^^^ 四川省托普信息技術職業學院 ^^^^^^^^^^\n\n");
printf("\t^^^^^^^^^ 09級計算機網路技術IBM2班 ^^^^^^^^^^\n\n");
printf("\t^^^^^^^^^ 周桂修改 ^^^^^^^^^^\n\n");
printf("\t**********************************************************\n\n");
}
void select()
{
int i=0;
printf("以下是全部學生成績\n");
printf("\t姓名\t學號\t成績\n");
for(i=0;i<Number;i++)
{
printf("\t%s\t%s\t%d\n",st[i].name,st[i].ID,st[i].score);
}
}
void add()
{
int numberTemp=0;
int i=0;
struct student temp;
printf("請輸入要增加學生成績個數:");
scanf("%d",&numberTemp);
for(i=0;i<numberTemp;i++)
{
printf("輸入第%d個同學信息\n",i+1);
printf("姓名:");
scanf("%s",temp.name);
printf("學號:");
scanf("%s",temp.ID);
printf("成績:");
scanf("%d",&temp.score);
st[Number++]=temp;
bc(&temp);
}
printf("添加成功\n");
}
void bc(struct student *st)
{
FILE *fp=NULL;
fp=fopen("C://student.dat","ab+");
fwrite(st,sizeof(struct student),1,fp);
fclose(fp);
}
int dq(struct student st[])
{
FILE *fp=NULL;
int i=0;
fp=fopen("C://student.dat","rb");
while(fread(&st[i],sizeof(struct student),1,fp))
i++;
fclose(fp);
return i;
}
void xianshi()
{
printf("\t*****************************************************************\n");
printf("\t* *\n");
printf("\t* 學生成績管理系統 *\n");
printf("\t* *\n");
printf("\t* [1] 增加學生成績 [2] 查看學生成績 *\n");
printf("\t* [3] 查找學生成績 [4] 刪除學生成績 *\n");
printf("\t* [5] 統計(總成績和平均分)[6] 輸出不及格人數 *\n");
printf("\t* [7] 修改學生信息 [8] 關於作者 *\n");
printf("\t* [9] 保存數據 [0] 退出系統 *\n");
printf("\t*****************************************************************\n");
}
⑷ C語言編程題
參考原始問題
第一問解答:
voidwrite_line(void)
{
intextra_spaces,spaces_to_insert,i,j;
extra_spaces=MAX_LINE_LEN-line_len;
for(i=0;i<line_len;i++){
if(line[i]!='')
putchar(line[i]);
else{
spaces_to_insert=extra_spaces/(num_words-1);
for(j=1;j<=spaces_to_insert+1;j++)
putchar('');
extra_spaces-=spaces_to_insert;
num_words--;
}
}
putchar(' ');
}
//修改為
voidwrite_line(void)
{
staticboolright=true;
intextra_spaces,spaces_to_insert,i,j;
extra_spaces=MAX_LINE_LEN-line_len;
for(i=0;i<line_len;i++){
if(line[i]!='')
putchar(line[i]);
else{
if(right)
spaces_to_insert=extra_spaces/(num_words-1);
else
spaces_to_insert=(extra_spaces+num_words-2)/(num_words-1);
for(j=1;j<=spaces_to_insert+1;j++)
putchar('');
extra_spaces-=spaces_to_insert;
num_words--;
}
}
putchar(' ');
right=!right;
}
第二問解答
voidread_word(char*word,intlen)
{
intch,pos=0;
while((ch=read_char())=='')
;
while(ch!=''&&ch!=EOF){
if(pos<len)
word[pos++]=ch;
ch=read_char();
}
word[pos]='