Important notice? comments will be deducted 5 points in grade Exercise 1 (15 poi
ID: 674372 • Letter: I
Question
Important notice? comments will be deducted 5 points in grade Exercise 1 (15 points) You should put comments in your take-home assignments. Solutions without in. Let a and b be integers so that either a and b is nonzero. The greatest common divisor, written ged(a,b), of a and b is the largest positive integer that divides both a and b. Your program must contain a function that takes as input two integers and t either a and b 'is nonzero. The greatest common return the gcd of integers. Hints: ged(a,b) ged(b, a mod b) if a b. Grading scheme: a main function to call ged function and display the final outcome 5 points; a function to calculate ged 5 points; handling the condition when the number is zero correctly 5 points. Exercise 2 (15 points) Write a program that outputs infiation rates for two successive years and whether the inflation is increasing or decreasing. Ask the user to input the current price of an item and its price one year and two years ago. To calculate the inflation rate for a year, subtract the price of the item for that year from the price of the item year ago and then divide the result by the price a year ago. Your program must contain at least the following functions: a function to get the input, a function o calculate the results, and a function to output the results. Use appropriate parameters to pass the information in and out of the function. Do not use a global variables. ny Grading scheme: a function to get the input - 5 points; a function to calculate the results - 5 points; a function to display the output and a main function to call the three functions above correctly 5 points.Explanation / Answer
#include <stdio.h>
int GCD(int x, int y)
{
if (y == 0) {
return x;
}else if(x==0){
return y;
} else if (x >= y && y > 0) {
return GCD(y, (x % y));
}else{
return GCD(x,(y%x));
}
}
int main(){
int a,b,gcd;
printf("Enter the first number: ");
scanf("%d",&a);
printf("Enter the second number: ");
scanf("%d",&b);
printf("Gcd of %d and %d is: %d ",a,b,GCD(a,b));
return 0;
}
#include <stdio.h>
void output(double i,double j,int flag){
if(flag==0){
printf("Inflation is constant as inflation for the two years are %.2f and %.2f",i,j);
}else if(flag==1){
printf("Inflation is increasing as inflation for the two years are %.2f and %.2f",i,j);
}else{
printf("Inflation is decreasing as inflation for the two years are %.2f and %.2f",i,j);
}
}
void cal_inflation(int x,int y,int z){
double inf1=(double)(y-x)/y;
double inf2=(double)(z-y)/z;
int flag;
if(inf1>inf2){
flag=1;
}else if(inf1<inf2){
flag=-1;
}else{
flag=0;
}
output(inf1,inf2,flag);
}
void input_var(){
printf("Enter the price of item in current year: ");
int c;
scanf("%d",&c);
printf("Enter the price of item a year before: ");
int b;
scanf("%d",&b);
printf("Enter the price of item two years before: ");
int a;
scanf("%d",&a);
cal_inflation(c,b,a);
}
int main(){
input_var();
return 0;
}