c语言程序综合设计cpp文件
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字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [求职职场]加法运算定律的运用练习题
- [求职职场]大型石油化工工业过程节能新技术
- [求职职场]2015-2020年中国箱纸板行业分析与投资
- [求职职场]NADEX-IWC5A点焊机故障代码
- [求职职场]英语阅读 非常有用
- [求职职场]鲁卫疾控发〔2012〕2号(联合,印发山东
- [求职职场]2014年莆田公务员行测技巧:数字推理的
- [求职职场]基于最近发展区理论的高中数学课堂有效
- [求职职场]与贸易有关的知识产权协议
- [求职职场]【王风范】微演说·职场演说三
- [求职职场]新时代国珍健康大课堂
- [求职职场]群论期末考试复习题
- [求职职场]施工现场消防安全专项施工方案(范本)-
- [求职职场]初中物理光学知识点归纳完美版
- [求职职场]毕业设计总结与体会范文
- [求职职场]江南大学2018年上半年展示设计第1阶段
- [求职职场]景尚乡民兵参战支前保障方案
- [求职职场]【优质】2019年工会职工之家建设工作总
- [求职职场]数据库技术与应用—SQL Server 2008(第
- [求职职场]汽车变速箱构造与工作原理
- 首钢工业区工业遗产资源保护与再利用研
- 第4课 《大学》节选
- 2016程序文件——检验检测结果发布程序
- 2011年高考试题文言文阅读全解释__2011
- 化学是一门基础的自然科学
- 海外做市商制度的借鉴意义
- 外国建筑史复习资料(
- 七年级下思想品德期末综合测试(二)
- 思政课部2013年上学期教学工作总结
- 电大国际公法任务3 0004
- 《圆的认识》教学设计
- 中国轨道交通牵引变流器行业市场发展调
- 中泰证券#定期报告:坚守时代硬科技和
- 浅论企业财务管理与企业经营投资风险的
- 大功率半导体激光器光纤耦合技术调研报
- 中国传统家具的现状与发展探讨
- Broadcom数字电视芯片助海尔扩展高清电
- 新HSK4词汇练习 超全(五)
- 2013届高考数学单元考点复习12
- 雨霖铃精品课件




