1、c语言综合设计实例
我才做过。。。
#include<stdio.h>
#include<malloc.h>
typedef struct Polynomial{
float coef;
int expn;
struct Polynomial *next;
}*Polyn,Polynomial;
void Insert(Polyn p,Polyn h){
if(p->coef==0) free(p);
else{
Polyn q1,q2;
q1=h;q2=h->next;
while(q2&&p->expn<q2->expn){
q1=q2;
q2=q2->next;
}
if(q2&&p->expn==q2->expn){
q2->coef+=p->coef;
free(p);
if(!q2->coef){
q1->next=q2->next;
free(q2);
}
}
else{
p->next=q2;
q1->next=p;
}
}
}
Polyn CreatePolyn(Polyn head,int m){
int i;
Polyn p;
p=head=(Polyn)malloc(sizeof(struct Polynomial));
head->next=NULL;
for(i=0;i<m;i++){
p=(Polyn)malloc(sizeof(struct Polynomial));
printf("请输入第%d项的系数与指数:",i+1);
scanf("%f %d",&p->coef,&p->expn);
Insert(p,head);
}
return head;
}
void DestroyPolyn(Polyn p){
Polyn q1,q2;
q1=p->next;
q2=q1->next;
while(q1->next){
free(q1);
q1=q2;
q2=q2->next;
}
}
void PrintPolyn(Polyn P){
Polyn q=P->next;
int flag=1;
if(!q) {
putchar('0');
printf("\n");
return;
}
while (q){
if(q->coef>0&&flag!=1) putchar('+');
if(q->coef!=1&&q->coef!=-1){
printf("%g",q->coef);
if(q->expn==1) putchar('X');
else if(q->expn) printf("X^%d",q->expn);
}
else{
if(q->coef==1){
if(!q->expn) putchar('1');
else if(q->expn==1) putchar('X');
else printf("X^%d",q->expn);
}
if(q->coef==-1){
if(!q->expn) printf("-1");
else if(q->expn==1) printf("-X");
else printf("-X^%d",q->expn);
}
}
q=q->next;
flag++;
}
printf("\n");
}
int compare(Polyn a,Polyn b){
if(a&&b){
if(!b||a->expn>b->expn) return 1;
else if(!a||a->expn<b->expn) return -1;
else return 0;
}
else if(!a&&b) return -1;
else return 1;
}
Polyn AddPolyn(Polyn pa,Polyn pb){
Polyn qa=pa->next;
Polyn qb=pb->next;
Polyn headc,hc,qc;
hc=(Polyn)malloc(sizeof(struct Polynomial));
hc->next=NULL;
headc=hc;
while(qa||qb){
qc=(Polyn)malloc(sizeof(struct Polynomial));
switch(compare(qa,qb)){
case 1:
{
qc->coef=qa->coef;
qc->expn=qa->expn;
qa=qa->next;
break;
}
case 0:
{
qc->coef=qa->coef+qb->coef;
qc->expn=qa->expn;
qa=qa->next;
qb=qb->next;
break;
}
case -1:
{
qc->coef=qb->coef;
qc->expn=qb->expn;
qb=qb->next;
break;
}
}
if(qc->coef!=0){
qc->next=hc->next;
hc->next=qc;
hc=qc;
}
else free(qc);
}
return headc;
}
Polyn SubtractPolyn(Polyn pa,Polyn pb){
Polyn h=pb;
Polyn p=pb->next;
Polyn pd;
while(p){
p->coef*=-1;
p=p->next;
}
pd=AddPolyn(pa,h);
for(p=h->next;p;p=p->next)
p->coef*=-1;
return pd;
}
int main(){
int m,n,chouse=0;
Polyn pa=0,pb=0,pc;
printf("请输入a的项数:");
scanf("%d",&m);
pa=CreatePolyn(pa,m);
printf("请输入b的项数:");
scanf("%d",&n);
pb=CreatePolyn(pb,n);
printf("操作提示:\n1.输出多项式a和b\n2.建立多项式a+b\n3.退出\n");
for(;;chouse=0){
printf("请选择执行操作");
scanf("%d",&chouse);
if(chouse==1){
printf("多项式a:");PrintPolyn(pa);
printf("多项式b:");PrintPolyn(pb);continue;
}
if(chouse==2){
pc=AddPolyn(pa,pb);
printf("多项式a+b:");PrintPolyn(pc);
DestroyPolyn(pc);continue;
}
if(chouse==3) break;
if(chouse<1||chouse>3) printf("选择输入错误\n");continue;
}
DestroyPolyn(pa);
DestroyPolyn(pb);
return 0;
}
2、C语言程序设计实例
#include <stdio.h>
#include <stdlib.h>
void invert(int n)
{
if(n==0)
return;
printf("%d", n%10);
invert(n/10);
}
int main(int argc, char **argv)
{
invert(2345);
system("pause");
return 0;
}
3、c语言程序设计实例
这是个宏定义,表示后面那个格式化字符串以FORMAT来代替
4、网页设计的javacsript的图片切换代码, 谁能帮我写个例子 鼠标指向1234的那种, 不需要任何特效
无标题文档 ul{ list-style:none;} li{ display:inline; float:left; margin-left:15px; display:none;} img{border:5px solid #000; width:100px; height:100px;} .pagediv{ clear:both; margin:15px; display:block;} .pagediv a{border:1px solid #c9c9c9; margin-left:5px;}function changepic(num,n){ //num当前要显示的图片 n 图片总数for(i=1;i var menu=document.getElementById("pic"+i); menu.style.display=i==num?"block":"none";}} https://gss0.baidu.com/7LsWdDW5_xN3otqbppnN2DJv/xuan2009pengyo/abpic/item/76e0ea14cf71977ef2de32dc.jpg
" /> https://gss0.baidu.com/7LsWdDW5_xN3otqbppnN2DJv/matlabsky/abpic/item/91c9a0cbb5a2607ef21fe7ba.jpg
" /> 1234
5、那个网站有c语言实例教程?
CSDN,51CTO,脚本之家,码农网,github等等,百度一下,很多网站有程序实例分享的。
6、c语言设计实例
#include <stdio.h>
main()
{ char str[100];
int i;
puts(str);
for(i=0;str[i]!='\0';i++)
{
if (str[i]=='1') str[i]='0';
else str[i]='1';
}
}
7、c程序设计实例
可以给你做,但是没时间,先拿两分