This program will contain 5 user defined functions: 1. int Getint(void); 2. doub
ID: 3872939 • Letter: T
Question
This program will contain 5 user defined functions: 1. int Getint(void); 2. double GetDouble(void); 3. char Getlnitial(void); 4. int FunctionOnelint arg1, double arg2); 5. int FunctionTwo(char arg1): Description: // gets an integer from the user and returns it int Getint/void) // gets a double from the user and returns it double GetDoubletvoid); // gets a letter from the user and returns it char Getlnitial(void: // takes two arguments, an integer and a double // adds 10 to the integer //multiplies the double argument by .5 and prints the result onto the screen //returns the result of integer addition
Explanation / Answer
Code of the asked program is as follows :
#include <stdio.h>
#include <ctype.h>
//GetInt function
int GetInt()
{
int n;
scanf("%d",&n);
return n;
}
//GetDouble function
double GetDouble()
{
double d;
scanf("%lf",&d);
return d;
}
//GetInitial
char GetInitial()
{
char c;
scanf("%c",&c);
return c;
}
//FunctionOne function
int FunctionOne(int arg1, double arg2)
{
arg1 += 10 ; //adding 10 to the integer
arg2 *= 5 ; //multiplying 5 to the double
printf("%lf ",arg2);
return arg1;
}
//FunctionTwo function
int FunctionTwo(char c)
{
int upper_c = toupper(c);
if(upper_c<=77)
return 1;
else
return 2;
}
//main function
int main()
{
int n;
double d;
char c;
n = GetInt(); //calling GetInt function
d = GetDouble(); //calling GetDouble function
c = GetInitial(); //calling GetInitial function
printf("%d ",FunctionOne(n,d)); //calling FunctionOne and printing the integer
printf("%d ",FunctionTwo(c)); //calling FunctionTwo and printing 1 or 2
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.