Program Code to Copy
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int lcm(int, int);
int gcd(int, int);
int main(){
int num1, num2, num3, den1, den2, den3, minMultiple;
//Taking input fractions for sum
printf("Enter first fraction: ");
scanf("%d%d", &num1, &den1);
printf("Enter second fraction: ");
scanf("%d%d", &num2, &den2);
// Finding LCM of den1 and den2
den3 = lcm(den1,den2);
// Changing the fractions to have same denominator
// Numerator of the final fraction obtained
num3 = (num1)*(den3/den1) + (num2)*(den3/den2);
//Finding GCD of num3 and den3 to convert result into lowest
term
int cd = gcd(num3, den3);
//Converting to lowest term
num3 = num3 / cd;
den3 = den3 / cd;
//Printing result
printf("Sum of %d/%d and %d/%d is %d/%d.\n",num1, den1, num2, den2,
num3, den3);
return 0;
}
//Finding LCM to compute sum of fractions
int lcm(int n1, int n2){
int minMultiple = ( n1 > n2) ? n1 : n2;
//Always TRUE
while(1){
if (minMultiple % n1 == 0 && minMultiple % n2 == 0){
return minMultiple;
}
++minMultiple;
}
}
//Finding greatest common divisor to convert result in lowest
term
int gcd(int n1, int n2)
{
if (n2 != 0)
return gcd(n2, n1%n2);
else
return n1;
}
Program Screenshot


Program Output


make a code for the additions of fractions. use the attached code to find LCM. #define...
/* • The following code consists of 5 parts. • Find the errors for each part and fix them. • Explain the errors using comments on top of each part. */ #include <stdio.h> #include <string.h> int main( ) { ////////////////////////////////////////////////////////////////////////// ////////////// Part A. (5 points) ////////////////// int g(void) { printf("%s", Inside function g\ n " ); int h(void) { printf(" % s ", Inside function h\ n "); } } printf("Part A: \n "); g(); printf(" \n"); ////////////////////////////////////////////////////////////////////////// ////////////// ...
Solve using C programming
3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...
//C programing help #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #define SIZE 5 int main() { double gradesWithBonus[SIZE]; int i; for (i = 0; i < SIZE; i++) { printf("Please enter your grade: "); //getting grade scanf("%lf", &gradesWithBonus[i]); printf("\n"); } for (i = 0; i < SIZE; i++) { //adding 5 to entered grade double bonous; bonous = gradesWithBonus[i] + 5.0; printf("Grade entered at array element...
i need flowchart for the following c code #include <stdio.h> int main() { int n, i, sum = 0; printf("Enter an integer: "); scanf("%d",&n); i = 1; while ( i <=n ) { sum += i; ++i; } printf("Sum = %d",sum); return 0; }
#define minl (x, y) ( (x < y) ? x : y) #define min 10 #include <stdio.h> int min2(int x, int y) { if (x < y) return x; else return y; } main() { int a, b; scanf("%d %d", &a, &b); if (b < min) printf("input out of range\n"); else { a = minl(a, b++); printf("a = %d, b %d\n", a, b); a = min2(a, b++); printf("a = %d, b %d\n", a, b); } } ------------------------- 1 Give the...
Convert the below C code to basic MIPS. Please leave comments for explanation #include <stdio.h> int main(void) { printf("Insert two numbers\n"); int a,b; scanf("%d",&a); scanf("%d",&b); a=a<<2; b=b<<2; printf("%d&%d\n",a,b); return 0; }
Convert the below C code to basic MIPS. Leave comments for explanation please #include <stdio.h> int main(void) { printf("Insert two numbers\n"); int a,b,c; scanf("%d",&a); scanf("%d",&b); c=a|b; printf("%d|%d=%d\n",a,b,c); return 0; }
C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure you test your code. Supplied code #include <stdio.h> int main(void) { char ch; int countA = 0; int countE = 0; int countI = 0; printf("Enter in a letter A, E, or I.\n"); scanf(" %c", &ch); //Replace the following block with your switch if(ch == 'E' || ch == 'e') countE++; else if(ch == 'A' || ch == 'a') countA++; else if(ch == 'I'...
I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) { int i, j; int rowA, colA, rowB, colB; int A[10][10], B[10][10]; int sum[10][10]; char str1[10]; printf("This is a matrix calculator\n"); //read in size from user MATRIX A printf("Enter in matrix A....\n"); printf("\t#row = "); scanf("%d", &rowA); printf("\t#col = "); ...
Write a MATLAB program that implements the algorithm designed in the Topic 1 "Non-Linear Flowchart" and "Creating a Flowchart" assignments previously implemented in C. Compare and contrast the C and MATLAB versions of your codes. convert this to a matlab program #include <stdio.h> int main() { int a; printf("Enter first number: "); scanf("%d", &a); int b; printf("Enter second number: "); scanf("%d", &b); int limit; printf("Enter limit: "); scanf("%d", &limit); printf("\nFirst number: %d\n", a); printf("Second number: %d\n", b); int c; c...