#include "stdio.h"
int gcd(int a, int b);
void reduce(int* numerator, int* denominator);
int main(int argc, char* argv[]) {
int a, b;
fscanf(stdin, "%d/%d", &a, &b);
reduce(&a, &b);
fprintf(stdout, "%d/%d", a, b);
return 0;
}
int gcd(int a, int b) {
int c;
while (b) {
c = a % b;
a = b;
b = c;
}
return a;
}
void reduce(int* numerator, int* denominator) {
int g = gcd(*numerator, *denominator);
*numerator /= g;
*denominator /= g;
}
You get the greatest common divisor between the numerator and denominator and divide them by it.
Reduce uses integer pointers so that changes the numerator and denominator to their reduce form.
There are probably better or easier ways, but the following works.
#include <iostream>
using namespace std;
void Simplify( int * Num, int * Den )
{
int H = 0;
bool b = true;
while( b )
{
b = !b;
for( H = 10; H > 1; --H )
{
if( b = ((*Num) %H 0 ))
{
*Num /= H;
*Den /= H;
break;
}
}
}
}
int main()
{
int N = 0;
int D = 0;
printf( "Input the numerator: " );
scanf( "%u", &N );
printf( "Input the denominator: " );
scanf( "%u", &D );
int n = N;
int d = D;
Simplify( &n, &d );
printf( "%u/%u simplifies to %u/%u\n", N, D, n, d );
return( 0 );
}
create spiral in c programming?
In C programming, C compiler is user to translate C source into C object module.
C++ is the name of a programming language.
The C language (or more commonly C++) is the core of most programming done at the desktop level. Most programs written in Linux are in C or C++, as are most Windows programs. A number of languages in recent computer history have been designed to reduce the dependency on C and C++, but have still largely failed to replace C and C++ for high performance applications.
It is not necessary (nor possible) in C programming.
C and C++ are both high-level programming languages.
create spiral in c programming?
Robert Lafore has written: 'Object-oriented programming in Microsoft C++' -- subject(s): Object-oriented programming (Computer science), C++ (Computer program language), C. 'Microsoft C. Programming for the I.B.M.Personal Computer' 'Object-oriented programming in C++' 'Windows Programming Made Ridiculously Easy Book' 'The Waite Group's C Programming Using Turbo C++ (The Waite Group)' 'Microsoft C programming for the IBM' 'The Waite Group's Microsoft C programming for the PC' -- subject(s): C (Computer program language), IBM microcomputers, Microsoft C (Computer program), Microsoft C., Programming
C - programming language - was created in 1972.
In C programming, C compiler is user to translate C source into C object module.
C language is better for hardware programming .Most of the programming for hardware are written in C language so it is beneficial for hardware programming is not efficient for application programming due to drawback like in C data moves around the system.
C++ is the name of a programming language.
You can find C programming tutorials online at the C programming website. They provide both free and paid tutorials for many aspects of the C and C++ code.
The C language (or more commonly C++) is the core of most programming done at the desktop level. Most programs written in Linux are in C or C++, as are most Windows programs. A number of languages in recent computer history have been designed to reduce the dependency on C and C++, but have still largely failed to replace C and C++ for high performance applications.
Download 1000s of C C C++ Programming Language. http://www.guruengineers.com
Android is programmed in the C and C++ programming language.
It is not necessary (nor possible) in C programming.