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程序設計實例
可以給你做,但是沒時間,先拿兩分