Sponsored Content
Homework and Emergencies Homework & Coursework Questions GCD Homework. Untraced error with an "if" Post 302598250 by balajesuri on Monday 13th of February 2012 11:56:21 PM
Old 02-14-2012
A humble bash code. And much quicker too.

Code:
#! /bin/bash
y=$1; r=$2
while [ $r -ne 0 ]
do
    gcd=$r
    r=$(($y % $r))
    y=$gcd
done
echo $gcd

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. HP-UX

ERROR: more than one instance of overloaded function "vprintf" has "C" linkage

Hi people! I've got this own library: -------------------------------------------- Personal.h -------------------------------------------- #ifdef __cplusplus extern "C" { #endif #include <stdio.h> #include <stdarg.h> #include <string.h> ... (0 Replies)
Discussion started by: donatoll
0 Replies

3. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

6. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

7. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

8. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

9. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies
mp(3)							     Library Functions Manual							     mp(3)

NAME
madd, msub, mult, mdiv, gcd, invert, rpow, msqrt, mcmp, min, omin, fmin, m_in, mout, omout, fmout, m_out, sdiv, itom - Performs multiple precision integer arithmetic LIBRARY
Object Code Library (libmp.a) SYNOPSIS
#include <mp.h> #include <stdio.h> typedef struct mint { int len; short *val; } MINT; madd( MINT *a, MINT *b, MINT *c ); msub( MINT *a, MINT *b, MINT *c ); mult( MINT *a, MINT *b, MINT *c ); mdiv( MINT *a, MINT *b, MINT *q, MINT *r ); pow( MINT *a, MINT *b, MINT *m, MINT *c ); gcd( MINT *a, MINT *b, MINT *c ); invert( MINT *a, MINT *b, MINT *c ); rpow( MINT *a, int n, MINT *c ); msqrt( MINT *a, MINT *b, MINT *r ); mcmp( MINT *a, MINT *b ); move( MINT *a, MINT *b ); min( MINT *a ); omin( MINT *a ); fmin( MINT *a, FILE *f ); m_in( MINT *a, int n, FILE *f ); mout( MINT *a ); omout( MINT *a ); fmout( MINT *a, FILE *f ); m_out( MINT *a, int n, FILE *f ); sdiv( MINT *a, short n, MINT *q, short *r ); *itom( short n ); DESCRIPTION
These functions perform arithmetic on integers of arbitrary length. The integers are stored using the defined type MINT. Pointers to a MINT can be initialized using the itom() function, which sets the initial value to n. After that, space is managed automatically by the routines. The madd(), msub() , and mult() functions assign to c the sum, difference, and product, respectively, of a and b. The mdiv() function assigns to q and r the quotient and remainder obtained from dividing a by b. The sdiv() function is like the mdiv() function except that the divisor is a short integer n and the remainder is placed in a short integer whose address is given as r. The msqrt() function produces the integer square root of a in b and places the remainder in r. The rpow() function calculates in c the value of a raised to the (``regular'' integral) power n, while the pow() function calculates this with a full multiple precision exponent b and the result is reduced modulo m. The gcd() function returns the greatest common denominator of a and b in c, and the invert() function computes c such that a*c mod b = 1, for a and b relatively prime. The mcmp() function returns a negative, zero, or positive integer value when a is less than, equal to, or greater than b, respectively. The move() function copies a to b. The min() and mout() functions do decimal input and output while the omin() and omout() functions do octal input and output. More gener- ally, the fmin() and fmout() functions do decimal input and output using file f, and m_in() and m_out do input and output with arbitrary radix n. On input, records should have the form of strings of digits terminated by a newline; output records have a similar form. NOTES
Programs which use the multiple-precision arithmetic library must be compiled with -lmp. delim off mp(3)
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy