zoukankan      html  css  js  c++  java
  • 实验一

    #include<stdio.h>
    #include<stdlib.h>

    typedef struct Node{
        int index;
        int ss;
        int xs;
        struct Node *next;
    }Node, *Linkedlist;

    Linkedlist complex_output(int p,int q){
        if(q>0){
            printf("%d+%di ",p,q);
        }
        else if(q<0)
            printf("%d%di ",p,q);
        else
            printf("%d ",p);
        return 0;
    }
    Linkedlist insert(Linkedlist head,Node *node){
        node->next=head;
        head=node;
        return head;
    }

    void output(){
        printf("----------------------------------- ");
        printf("              实验                 ");
        printf("----------------------------------- ");
        printf("1.输入复数 ");
        printf("2.复数求和 ");
        printf("3.复数求差 ");
        printf("4.复数求积 ");
        printf("5.分离实部 ");
        printf("6.分离虚部 ");
        printf("----------------------------------- ");
    }

    void link_output(Linkedlist head){
        Node *current_node = head;
        while(current_node!=NULL){
            //printf("%d.%d+%di",current_node->index,current_node->ss,current_node->xs);
            printf("%d. ",current_node->index);
            complex_output(current_node->ss,current_node->xs);
            current_node=current_node->next;
        }
    }



    Linkedlist find_index(Linkedlist head,int p){
        Node *current_node=head;
        Node *a=NULL;
        while(current_node!=NULL){
            if (current_node->index==p){
                a=current_node;
                return a;
                break;
            }
        }
    }
    void add(Linkedlist head,int p,int q){
        Linkedlist a = find_index(head,p);
        Linkedlist b = find_index(head,q);
        complex_output(a->ss+b->ss,a->xs+b->xs);
    }

    void sub(Linkedlist head,int p,int q){
        Linkedlist a = find_index(head,p);
        Linkedlist b = find_index(head,q);
        complex_output(a->ss-b->ss,a->xs-b->xs);
    }

    void mul(Linkedlist head,int p,int q){
        Linkedlist a = find_index(head,p);
        Linkedlist b = find_index(head,q);
        int c,d;
        c=(a->ss*b->ss)-(a->xs*b->xs);
        d=(a->ss*b->xs)-(a->xs*b->ss);
        complex_output(c,d);
    }

    void cut_ss(Linkedlist head,int p){
        Linkedlist a = find_index(head,p);
        printf("%d ",a->ss);
    }

    void cut_xs(Linkedlist head,int p){
        Linkedlist a = find_index(head,p);
        printf("%d ",a->xs);
    }

    int main()
    {
        Linkedlist linkedlist=NULL;
        output();
        int a;
        int b=0;
        int p,q;
        while(1){
            scanf("%d",&a);
            if(a==1){
                b++;
                printf("添加复数,请输入实部 虚部: ");
                scanf("%d %d",&p,&q);
                Node *node = (Node *)malloc(sizeof(Node));
                node->index=b;
                node->ss=p;
                node->xs=q;
                node->next=NULL;
                linkedlist=insert(linkedlist,node);
                printf("添加成功! ");
                link_output(linkedlist);
            }
            else if (a==2)
            {
                printf("输入求和序号: ");
                scanf("%d%d",&p,&q);
                if(p>b||q>b){
                    printf("错误!请输入: ");
                    continue;
                }
                add(linkedlist,p,q);
            }
            else if (a==3)
            {
                printf("输入求差序号: ");
                scanf("%d%d",&p,&q);
                if(p>b||q>b){
                    printf("错误!请输入: ");
                    continue;
                }
                sub(linkedlist,p,q);
            }
            else if (a==4)
            {
                printf("输入求积序号: ");
                scanf("%d%d",&p,&q);
                if(p>b||q>b){
                    printf("错误!请输入: ");
                    continue;
                }
                mul(linkedlist,p,q);
            }
            else if (a==5)
            {
                printf("输入分离序号: ");
                scanf("%d",&p);
                if(p>b){
                    printf("错误!请输入: ");
                    continue;
                }
                cut_ss(linkedlist,p);
            }
            else if(a==6)
            {
                printf("输入分离序号: ");
                scanf("%d",&p);
                if(p>b){
                    printf("错误!请输入: ");
                    continue;
                }
                cut_xs(linkedlist,p);
            }
        printf("请输入: ");
        }
        return 0;
    }

  • 相关阅读:
    如何完全卸载oracle和删除oracle在注册表中的注册信息
    win10 管理工具中添加 oracle 10g驱动
    failed to install tomcat6 service ,check your setting and permissions
    ORA-28000: the account is locked-的解决办法
    Intellij Idea乱码解决方案
    过三关 Java冒泡排序选择排序插入排序小练习
    Java坦克大战(四)
    Java坦克大战(三)
    Java坦克大战(二)
    Java坦克大战(一)
  • 原文地址:https://www.cnblogs.com/p201821440039/p/11757548.html
Copyright © 2011-2022 走看看