分数相加减(c++)

#include <iostream>
using namespace std;
int gy(int a,intk1)
{intmin;
if(a>k1)min=k1;
else min=a;
    while(min)
    {  if(a%min==0&&k1%min==0)
           {if(k1/min==1) cout<<a/min<<endl;
               elsecout<<a/min<<‘/‘<<k1/min<<endl;
            break;  
            }
         min--;
    }
return0;
}
int main()
{inta,b,c,d,k1,g;
    charx1,j1,j2;
    while(cin>>a>>j1>>b>>x1>>c>>j2>>d)
    {k1=b*d;
    a=a*d;c=b*c;
    if(x1==‘-‘)
        {a=a-c;
        if(a==0)
            cout<<‘0‘<<endl;
        if(a<0){a=-a;cout<<"-";gy(a,k1);}
        else{gy(a,k1);}
         }
         if(x1==‘+‘)
         {a=c+a;
         if(a==0)
            cout<<‘0‘<<endl;
         elsegy(a,k1);
         }
}
    cout<<endl;
return0;
}
时间: 2024-08-24 23:11:45

分数相加减(c++)的相关文章

分数相加减的代码(c++)

#include <iostream> using namespace std; int gy(int a,int k1) {int min; if(a>k1)min=k1; else min=a;     while(min)     {   if(a%min==0&&k1%min==0)            {if(k1/min==1) cout<<a/min<<endl;                else cout<<a/

C语言关于利用sscanf实现字符串相加减

#include<stdio.h>#include<string.h>void main(){ int a; int b; char str1[10] = "99999"; char str2[10] = "1111111"; char str[30]; int k = 0, i = 0, j = 0; for (k = 0; k < 30&&i<strlen(str1);){ str[k++] = str1[i+

长整数相加减

1 #include<stdio.h> 2 #include<string> 3 using namespace std; 4 5 const int N=30; 6 int min(int n,int m)//返回两个数中的最小一个数 7 { 8 return (n<m) ? n : m; 9 } 10 11 int max(int n,int m)//返回两个数中的最大一个数 12 { 13 return (n>m) ? n : m; 14 } 15 16 void

链表解大数据相加减相乘

/*题意:大数相加减相乘单链表的运用*/#include<stdio.h>#include<stdlib.h>#include<string.h> char c;int flag; typedef struct node{ char data; struct node *next;} Node; Node *a[10]; Node *create_link(){ Node *head,*p; head=p=NULL; char m; while(1) { scanf(&

分数相加的例题

方法为:a/b+c/d=( (a*d)+(b*c) )/(b*d) (1).h文件#import <Foundation/Foundation.h> @interface Fraction : NSObject  //fraction分数 @property int numerator,denominator;//denominator分母 numerator分子-(void)print;-(void)setTo:(int)n over :(int)d;-(double) convertToN

js实现日期的相加减、以及日期的比较

// js实现日期的相加减 function dateOperator(date, days, operator) { date = date.replace(/-/g, "/"); //更改日期格式 var nd = new Date(date); nd = nd.valueOf(); if (operator == "+") { nd = nd + days * 24 * 60 * 60 * 1000; } else if (operator == "

java处理日期时间 相加减大全

java处理日期时间 相加减 JAVA处理日期时间常用方法: 1.java.util.Calendar Calendar 类是一个抽象类,它为特定瞬间与一组诸如 YEAR.MONTH.DAY_OF_MONTH.HOUR 等 日历字段之间的转换提供了一些方法,并为操作日历字段(例如获得下星期的日期)提供了一些方法.瞬间可用毫秒值来表示,它是距历元(即格林威治标准时间 1970 年 1 月 1 日的 00:00:00.000,格里高利历)的偏移量. 例: Java代码 1. Calendar cal

C++ string 实现大整数相加减

任意两个大整数的加减算法,可自动判断正负号,代码如下: #include <iostream> #include <vector> #include <cstring> #include <algorithm> #include <string> using namespace std; string BigInegerAdd(string s1, string s2) // s1+s2; { int len = s1.size()>s2.

Leetcode 592.分数加减运算

分数加减运算 给定一个表示分数加减运算表达式的字符串,你需要返回一个字符串形式的计算结果. 这个结果应该是不可约分的分数,即最简分数. 如果最终结果是一个整数,例如 2,你需要将它转换成分数形式,其分母为 1.所以在上述例子中, 2 应该被转换为 2/1. 示例 1: 输入:"-1/2+1/2" 输出: "0/1"  示例 2: 输入:"-1/2+1/2+1/3" 输出: "1/3" 示例 3: 输入:"1/3-1/