用c语言编写基于链表的长整数的加减乘除法运算的程序

用c语言编写基于链表的长整数的加减乘除法运算的程序,第1张

#include "iostream.h"备伏

void main()

{

int x,y

cout<<"请并冲输入两个整数,整数之间用空格隔开:"<<endl

cin>>x>>y

int he=x+y

int ji=x*y

int jian=x-y

double chu=x/y

cout<<绝滚歼he<<ji<<jian<<chu

}

自定义一个不限定长度的字符串输入函数,在主函数中调用输入数字字符串后求字符串各元素代表的十进制数字之和。举例代码如下:

//#include "stdafx.h"//If the vc++6.0, with this line.

#include "stdio.h"

#include "string.h"

#include "stdlib.h"

char *longets(char *p){

    char *q

    if((q=(char *)malloc(sizeof(int)==4 ? 0xFFFFFF : 0xFFFF))==NULL){

     升或   printf("Failed to create temporary array...\n")

        return NULL

    }

    scanf("%[1234567890]",q)

    if((p=(char *)malloc(strlen(q)+1))==NULL){

   明漏     printf("Failed to create 吵槐伍the actual array...\n")

        return NULL

    }

    strcpy(p,q)

    free(q)

    return p

}

int main(void){

    unsigned i,sum

    char *p=NULL

    printf("Please enter a long integer...\n")

    if(p=longets(p)){

        for(sum=i=0p[i]sum+=p[i++]-'0')

        printf("The result is %u\n",sum)

    }

    free(p)

    return 0

}

#include <stdio.h>

#include <string.h>

int z(char c) return(c==' '?0:c-'0')

void main() {

char a[81],b[81],s[81]

int n,flag

scanf("%s",s)

sprintf(a,"%80s",s)

scanf("%s",s)

sprintf(b,"%80s",s)

for(flag=0,n=79n>橘衡=0n--, flag/圆伏做=10)

s[n]=(flag=z(a[n])+z(b[n])+flag)%10

for(s[80]=flag=n=0n<80n++)

if(flag || s[n]) {

s[n]+='0'

flag=1

} else s[n]='厅搭 '

printf("%s\n",s)

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8199274.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-14
下一篇2023-04-14

发表评论

登录后才能评论

评论列表(0条)

    保存