# Structure-05. Mean value of rational number

Source: Internet
Author: User

Structure-05. Mean value of rational number (20) time limit MS Memory limit 65536 KB code length limit 8000 B award Program StandardAuthor Joleen (Tsinghua University)

A program is required to calculate the average of n rational numbers.

Input format:

Enter the 1th line to give the positive integer n (<=100), and the 2nd line in the format "a1/b1 a2/b2 ..." gives a rational number in the form of n fractions, where the numerator and denominator are all integers in the shaping range, and if negative, the negative sign must appear at the front.

Output format:

Outputs the average of n rational numbers in a row in a "A/b" format. Note must be the simplest fractional form of the rational number, and if the denominator is 1, only the molecules are output.

Input Sample 1:
`41/2 1/6 3/6 -5/10`
Output Example 1:
`1/6`
Input Sample 2:
`24/3 2/3`
Output Example 2:
`1`
`1#include <stdio.h>2#include <math.h>3#include <stdlib.h>4#include <string.h>5 intMain ()6 {7     structRational8     {9         intA;Ten         intb; One     }; ARational X, r[ the]; -     inti, N; -scanf"%d", &n); the      for(i =0; I < n; i++) -     { -scanf"%d/%d", &AMP;R[I].A, &r[i].b); -     } +X.A =0; -x.b =1; +      for(i =0; I < n; i++) A     { atX.A = x.a * r[i].b + x.b *r[i].a; -X.B *=r[i].b; -     } -X.B *=N; -     inttemp, H, l; -h = x.a > x.b?x.a:x.b; inL = x.a < x.b?x.a:x.b; -      while(L) to     { +temp = h%l; -h =l; theL =temp; *     } \$     if(H! =0)Panax Notoginseng     { -X.A/=h; theX.B/=h; +     } A     if(X.A = =0) theprintf"%d\n", x.a); +   Else if(x.b = =1) -printf"%d\n", x.a); \$   Else \$printf"%d/%d\n", X.A, x.b); -   return 0; -     return 0; the}`

Structure-05. Mean value of rational number

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.