教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 求职职场 >

c语言程序综合设计cpp文件

来源:网络收集 时间:2026-09-11
导读: c语言程序综合设计代码 1 #include stdio.h #include malloc.h #define LEN sizeof(struct node) struct node { double num; struct node * next; }; int n1=0; int n2=0; int len = 0; struct node * create_list(struct node * head,int n,int flag) { str

c语言程序综合设计代码

1

#include <stdio.h> #include <malloc.h>

#define LEN sizeof(struct node) struct node {

double num;

struct node * next; }; int n1=0; int n2=0;

int len = 0;

struct node * create_list(struct node * head,int n,int flag)

{

struct node * p1,* p2;

printf("请输入数列,以回车键结束一个数字的输入,以ctrl+z结束一数列的输入.\n"); p1 = p2 = (struct node *)malloc(LEN); while(scanf("%lf",&p1->num) != EOF) { n++;

if(n==1) head = p1; else p2->next = p1; p2 = p1;

p1 = (struct node *)malloc(LEN);

}

p2->next = NULL; free(p1);

if (flag == 1) n1 = n; if (flag == 2) n2 = n; return(head); }

struct node * convert_list(struct node * head) {

struct node * p1,* p2; double t;

p1 = p2 = (struct node *)malloc(LEN); p1 = p2 = head; while(p1 != NULL) {

p2 = p1->next;

while(p2 != NULL){

if(p1->num < p2->num){ t = p1->num;

c语言程序综合设计代码

p1->num = p2->num; p2->num = t; }

p2 = p2->next; }

p1 = p1->next; }

free(p1);free(p2); return(head); }

int main(){

struct node * head,* head1,* head2,* temp,* p,* p1,* p2;

head = head1 = head2 = temp = p = p1 = p2 = (struct node *)malloc(LEN); head1 = create_list(head1,n1,1); head2 = create_list(head2,n2,2); head1 = convert_list(head1); head2 = convert_list(head2); temp = head1;

while(temp != NULL){ printf("%5.2f ",temp->num); temp = temp->next; }

printf("\n"); temp = head2;

while(temp != NULL){ printf("%5.2f ",temp->num); temp = temp->next; }

printf("\n");

p1 = head1; p2 = head2; while( (n1 != 0) && (n2 != 0) ){ len++;

if(p1->num >= p2->num){ p->num = p1->num; p1 = p1->next; n1--; }else {

p->num = p2->num; p2 = p2->next; n2--; }

if(len==1) head = p; else temp->next = p; temp = p;

c语言程序综合设计代码

p = (struct node *)malloc(LEN); }

if(n1 == 0) temp->next = p2; if(n2 == 0) temp->next = p1; temp = head;

while(temp != NULL){ printf("%5.2f ",temp->num); temp = temp->next; }

printf("\n");

free(head);free(head1);free(head2);free(temp);free(p);free(p1);free(p2); return 0; }

2

#include<stdio.h> #define N 100000 void main() {

int i,j,n,sum=1,top=0; int a[N]={0},b[N]={0}; scanf("%d",&n); if(n<10) { }

for(i=1;i<=n;i++)

sum*=i;

printf("%d\n",sum);

c语言程序综合设计代码

{

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

sum*=i;

i=0; while(sum) { } top=i-1;

for(j=10;j<=n;j++) {

a[0]*=j; b[0]=a[0]/10; a[0]%=10; for(i=1;i<top;i++) {

a[i]=a[i]*j+b[i-1]; b[i]=a[i]/10; a[i]%=10; a[i]=sum%10; sum/=10; i++;

c语言程序综合设计代码

}

}

}

a[top]=a[top]*j+b[i-1]; b[top]=a[top]/10; a[top]%=10; while(b[top]) { } top++;

a[top]=b[top-1]%10; b[top]=b[top-1]/10;

for(j=0;j<=top;j++) { }

printf("\n");

if(j%50==0) printf("\n"); printf("%d",a[top-j]);

c语言程序综合设计代码

3

#include<stdio.h> int result = 1; int chess[8]; int check( int n ) { int i;

for (i = 1; i <= n - 1; i++) {

if ( (chess[i] == chess[n]) || ((chess[n]-chess[i])==(n-i)) ||((chess[n]-chess[i])==(i-n)) ) return 0; } return 1; }

void show_chess(void) { int i;

printf("第%2d个解决方案:", result++); for (i = 1; i <= 8; i++)

c语言程序综合设计代码

{

printf(" %d ", chess[i]); }

printf("\n"); }

void putchess( int n ) { int i; if (n <= 8){

for (i = 1; i <= 8; i++) {

chess[n] = i; if (check(n) == 1) {

if (n == 8) show_chess(); else

putchess(n + 1); } } } }

c语言程序综合设计代码

int main() { int b; key:

printf("这里是8皇后问题的递归解决方法:printf("请输入数字8\n"); scanf("%d",&b); if(b==8) {

putchess(1); }else {

goto key; } return 0; }

4

\n");

c语言程序综合设计代码

************************** 高斯消元解N元一次方程 ************************** */

#include <stdio.h> #include <math.h> #include <string.h> #define EPS 1e-6 #define N 200 int n;

double gauss[N][N];//存序数矩阵

double answer[N];//用来存有唯一解是的答案

int input() { }

int i,j;

if (scanf("%d",&n)==EOF) return 0; for (i=0;i<n;i++)

for (j=0;j<=n;j++)

scanf("%lf",&gauss[i][j]); return 1;

void swap(double &a,double &b) { }

double c; c=a; a=b; b=c;

/*

********************************* 判断方程是否有解,返回值是0表示无解 返回值是1表示有唯一解 返回值是2表示有无穷多解

********************************* */

int slove_gaussa() {

int i,j,k,p;

for (j=0;j<n;j++) {

c语言程序综合设计代码

}

for (i=j+1;i<n;i++) if (fabs(gauss[i][j])>fabs(gauss[p][j])) p=i; if (fabs(gauss[p][j])<EPS) continue; if (p!=j) { }

for (k=j;k<=n;k++)

swap(gauss[p][k],gauss[j][k]);

for (i=j+1;i<n;i++)

for (k=n;k>=j;k--) gauss[i][k]-=gauss[j][k]*gauss[i][j]/gauss[j][j];

}

bool r=false; for (i=0;i<n;i++) { }

int num1=0,num2=0; for (j=0;j<n;j++) {

if (fabs(gauss[i][j])<EPS) num1++; if (fabs(gauss[j][i])<EPS) num2++;

}

if (num1==n) return 0; if (num2= …… 此处隐藏:4962字,全部文档内容请下载后查看。喜欢就下载吧 ……

c语言程序综合设计cpp文件.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/1700606.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)