本文目录一览:
- 1、cannot open Debug/chapter3.exe for writing
- 2、C语言数组任务(3),快速采纳
- 3、c语言求一个 3×3的整型矩阵对角线元素之和
- 4、图书信息管理系统C语言
cannot open Debug/chapter3.exe for writing
把这个Debug文件夹删掉,重新编译源文件, 会自动生成Debug目录的…
(如果删不掉, 建议把c++编译器关掉在删)
C语言数组任务(3),快速采纳
#include stdio.h
#include string.h
void putout(int result[], int n=16);
void moveforward(int result[], int n)
{
if( n==0) return;
int i;
for(i=n; i=16; ++i) result[i-n] = result[i];
for(i=16-n; i16; ++i)result[i] = 0;
}
void getMul(int result[], int param[], int n=8)
{
int i, j;
int *tmp = new int[16];
int *param_tmp = new int[8];
for(i=0; i16; ++i)
{
tmp[i] = 0;
if(i=8) param_tmp[i-8] = result[i];
}
for(i=0; i16; ++i) result[i] = 0;
for(i=0; in; ++i)
{
for(j=0; j16; ++j) tmp[j] = 0;
for(j=0; j8; ++j) tmp[j+8] = param_tmp[j]*param[7-i];
for(j=15; j=0; –j)
{
if(tmp[j]=10)
{
if(j0) tmp[j-1] += tmp[j]/10;
tmp[j] = tmp[j]%10;
}
}
moveforward(tmp, i);
for(j=15; j=0; –j)
{
result[j] += tmp[j];
if(result[j]=10)
{
if(j0) result[j-1] += result[j]/10;
result[j] = result[j]%10;
}
}
}
}
void putout(int result[], int n)
{
int i(0);
while(result[i] == 0) ++i;
//printf(“result:”);
for(; i n; ++i) printf(“%d”,result[i]);
//printf(“\n”);
}
void main()
{
char param1[9], param2[9];
int result[16], param[8];
printf(“Input two number:”);
scanf(“%s”, param1);
scanf(“%s”, param2);
int i, j(0);
for(i=0; i16; ++i)
{
if(i8) param[i] = 0;
result[i] = 0;
}
j=0;
for(i=strlen(param1)-1; i=0; –i, j++) result[15-j] = param1[i]-‘0’;
j=0;
for(i=strlen(param2)-1; i=0; –i, j++) param[7-j] = param2[i]-‘0’;
getMul(result, param, strlen(param2));
printf(“%s*%s=”, param1, param2);
putout(result);
printf(“\n”);
}
c语言求一个 3×3的整型矩阵对角线元素之和
c语言求一个3×3的整型矩阵对角线元素之和步骤如下:
1、打开Dev-c++软件,点击“新建源代码”。
2、具体程序如下:
#include stdio.h
int main()
{
int a[3][5]={{1,2,3},{4,5,6},{7,8,9}};
int i,j,sum,m=0,sum1=0,sum2=0;
printf(“array a:\n”);
for(i=0;i3;i++)
{
for(j=0;j3;j++)
{
printf(“%4d”,a[i][j]);
m=m+1;
}
if(m%3==0)
printf(“\n”);
}
sum1=a[0][0]+a[1][1]+a[2][2];
sum2=a[0][2]+a[1][1]+a[2][0];
sum=sum1+sum2;
printf(“对角线元素之和为%d”,sum);
return 0;
}
3、此次我们的程序最终目的是求出3×3的整型矩阵对角线元素之和,所以我们首先要向计算机输入我们3×3矩阵中的所有元素。
4、其次,我们要对输入的矩阵的元素进行放置于相应的位置,以便于我们之后的计算其对角元素之和。
5、再次,我们需要向计算机指出要计算机计算出哪些元素之和和需要计算元素的具体位置在哪儿。
6、这里需要说明一下,我们需要定义三个累积和sum1,sum2,sum来进行计算后的结果的暂时存储。
7、其中:if(m%3==0)表示要求最后输出的结果呈输出3个数之后进行换行。
8、当我们的程序写完之后,点击运行即可求出我们所要求出的结果了。
图书信息管理系统C语言
自己写的!
题目和你们一样!
#includestdio.h
#includemath.h
#includestring.h
#includestdlib.h
struct books_list
{
char author[20]; /*作者名*/
char bookname[20]; /*书名*/
char publisher[20]; /*出版单位*/
char pbtime[15]; /*出版时间*/
char loginnum[10]; /*登陆号*/
float price; /*价格*/
char classfy[10]; /*分类号*/
struct books_list * next; /*链表的指针域*/
};
struct books_list * Create_Books_Doc(); /*新建链表*/
void InsertDoc(struct books_list * head); /*插入*/
void DeleteDoc(struct books_list * head , int num);/*删除*/
void Print_Book_Doc(struct books_list * head);/*浏览*/
void search_book(struct books_list * head); /*查询*/
void info_change(struct books_list * head);/*修改*/
void save(struct books_list * head);/*保存数据至文件*/
/*新建链表头节点*/
struct books_list * Create_Books_Doc()
{
struct books_list * head;
head=(struct books_list *)malloc(sizeof(struct books_list)); /*分配头节点空间*/
head-next=NULL; /*头节点指针域初始化,定为空*/
return head;
}
/*保存数据至文件*/
void save(struct books_list * head)
{
struct books_list *p;
FILE *fp;
p=head;
fp=fopen(“data.txt”,”w+”); /*以写方式新建并打开 data.txt文件*/
fprintf(fp,”┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓\n”); /*向文件输出表格*/
fprintf(fp,”┃登录号┃ 书 名 ┃ 作 者┃ 出版单位 ┃ 出版时间 ┃分类号┃ 价格 ┃\n”);
fprintf(fp,”┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫\n”);
/*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/
while(p-next!= NULL)
{
p=p-next;
fprintf(fp,”┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃\n”,p-loginnum,p-bookname,p-author,p-publisher,p-pbtime,p-classfy,p-price);
}
fprintf(fp,”┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\n”);
fclose(fp);
printf(” 已将图书数据保存到 data.txt 文件\n”);
}
/*插入*/
void InsertDoc(struct books_list *head)
{
/*定义结构体指针变量 s指向开辟的新结点首地址 p为中间变量*/
struct books_list *s, *p;
char flag=’Y’; /*定义flag,方便用户选择重复输入*/
p=head;
/*遍历到尾结点,p指向尾结点*/
while(p-next!= NULL)
{
p=p-next;
}
/*开辟新空间,存入数据,添加进链表*/
while(flag==’Y’||flag==’y’)
{
s=(struct books_list *)malloc(sizeof(struct books_list));
printf(“\n 请输入图书登陆号:”);
fflush(stdin);
scanf(“%s”,s-loginnum);
printf(“\n 请输入图书书名:”);
fflush(stdin);
scanf(“%s”,s-bookname);
printf(“\n 请输入图书作者名:”);
fflush(stdin);
scanf(“%s”,s-author);
printf(“\n 请输入图书出版社:”);
fflush(stdin);
scanf(“%s”,s-publisher);
printf(“\n 请输入图书出版时间:”);
fflush(stdin);
scanf(“%s”,s-pbtime);
printf(“\n 请输入图书分类号:”);
fflush(stdin);
scanf(“%s”,s-classfy);
printf(“\n 请输入图书价格:”);
fflush(stdin);
scanf(“%f”,s-price);
printf(“\n”);
p-next=s; /*将新增加的节点添加进链表*/
p=s; /*p指向尾节点,向后移*/
s-next=NULL;
printf(” ━━━━ 添加成功!━━━━”);
printf(“\n 继续添加?(Y/N):”);
fflush(stdin);
scanf(“%c”,flag);
printf(“\n”);
if(flag==’N’||flag==’n’)
{break;}
else if(flag==’Y’||flag==’y’)
{continue;}
}
save(head); /*保存数据至文件*/
return;
}
/*查询操作*/
void search_book(struct books_list *head)
{
struct books_list * p;
char temp[20];
p=head;
if(head==NULL || head-next==NULL) /*判断数据库是否为空*/
{
printf(” ━━━━ 图书库为空!━━━━\n”);
}
else
{
printf(“请输入您要查找的书名: “);
fflush(stdin);
scanf(“%s”,temp);
/*指针从头节点开始移动,遍历至尾结点,查找书目信息*/
while(p-next!= NULL)
{
p=p-next;
if(strcmp(p-bookname,temp)==0)
{
printf(“\n图书已找到!\n”);
printf(“\n”);
printf(“登录号: %s\t\n”,p-loginnum);
printf(“书名: %s\t\n”,p-bookname);
printf(“作者名: %s\t\n”,p-author);
printf(“出版单位: %s\t\n”,p-publisher);
printf(“出版时间: %s\t\n”,p-pbtime);
printf(“分类号: %s\t\n”,p-classfy);
printf(“价格: %.2f\t\n”,p-price);
}
if(p-next==NULL)
{
printf(“\n查询完毕!\n”);
}
}
}
return;
}
/*浏览操作*/
void Print_Book_Doc(struct books_list * head)
{
struct books_list * p;
if(head==NULL || head-next==NULL) /*判断数据库是否为空*/
{
printf(“\n ━━━━ 没有图书记录! ━━━━\n\n”);
return;
}
p=head;
printf(“┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓\n”);
printf(“┃登录号┃ 书 名 ┃ 作 者┃ 出版单位 ┃ 出版时间 ┃分类号┃ 价格 ┃\n”);
printf(“┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫\n”);
/*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/
while(p-next!= NULL)
{
p=p-next;
printf(“┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃\n”,p-loginnum,p-bookname,p-author,p-publisher,p-pbtime,p-classfy,p-price); /*循环输出表格*/
}
printf(“┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\n”);
printf(“\n”);
}
/*修改操作*/
void info_change(struct books_list * head)
{
struct books_list * p;
int panduan=0; /*此变量用于判断是否找到书目*/
char temp[20];
p=head;
printf(“请输入要修改的书名:”);
scanf(“%s”,temp);
while(p-next!= NULL)
{
p=p-next;
if(strcmp(p-bookname,temp)==0)
{
printf(“\n 请输入图书登陆卡号:”);
fflush(stdin);
scanf(“%s”,p-loginnum);
printf(“\n 请输入图书书名:”);
fflush(stdin);
scanf(“%s”,p-bookname);
printf(“\n 请输入图书作者名:”);
fflush(stdin);
scanf(“%s”,p-author);
printf(“\n 请输入图书出版社:”);
fflush(stdin);
scanf(“%s”,p-publisher);
printf(“\n 请输入图书出版时间:”);
fflush(stdin);
scanf(“%s”,p-pbtime);
printf(“\n 请输入图书分类号:”);
fflush(stdin);
scanf(“%s”,p-classfy);
printf(“\n 请输入图书价格:”);
fflush(stdin);
scanf(“%f”,p-price);
printf(“\n”);
panduan=1;
}
}
if(panduan==0)
{
printf(“\n ━━━━ 没有图书记录! ━━━━\n\n”);
}
return;
}
/*删除操作*/
void DeleteDoc(struct books_list * head)
{
struct books_list *s,*p; /*s为中间变量,p为遍历时使用的指针*/
char temp[20];
int panduan; /*此变量用于判断是否找到了书目*/
panduan=0;
p=s=head;
printf(” [请输入您要删除的书名]:”);
scanf(“%s”,temp);
/*遍历到尾结点*/
while(p!= NULL)
{
if(strcmp(p-bookname,temp)==0)
{
panduan++;
break;
}
p=p-next;
}
if(panduan==1)
{
for(;s-next!=p;) /*找到所需删除卡号结点的上一个结点*/
{
s=s-next;
}
s-next=p-next; /*将后一节点地址赋值给前一节点的指针域*/
free(p);
printf(“\n ━━━━ 删除成功! ━━━━\n”);
}
else /*未找到相应书目*/
{
printf(” 您输入的书目不存在,请确认后输入!\n”);
}
return;
}
int main(void)
{
struct books_list * head;
char choice;
head=NULL;
for(;;) /*实现反复输入选择*/
{
printf(” ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n”);
printf(” ┃ ┃ socat 图书管理系统 ┃ ┃\n”);
printf(” ┃ ┗━━━━━━━━━━━━━━━━━━━┛ ┃\n”);
printf(” ┃ ●[1]图书信息录入 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ ●[2]图书信息浏览 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ ●[3]图书信息查询 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ ●[4]图书信息修改 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ ●[5]图书信息删除 ┃\n”);
printf(” ┃ ┃\n”);
printf(” ┃ ●[6]退出系统 ┃\n”);
printf(” ┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”);
printf(” 请选择:”);
fflush(stdin);
scanf(“%c”,choice);
if(choice==’1′)
{
if(head==NULL)
{
head=Create_Books_Doc();
}
InsertDoc(head);
}
else if(choice==’2′)
{
Print_Book_Doc(head);
}
else if(choice==’3′)
{
search_book(head);
}
else if(choice==’4′)
{
info_change(head);
}
else if(choice==’5′)
{
DeleteDoc(head);
}
else if(choice==’6′)
{
printf(“\n”);
printf(” ━━━━━━━━ 感谢使用图书管理系统 ━━━━━━━━\n”);
break;
}
else
{
printf(” ━━━━ 输入错误,请重新输入!━━━━”);
break;
}
}
return 0;
}
原创文章,作者:BWYK,如若转载,请注明出处:https://www.506064.com/n/141132.html