Question 1:
a- Write C program that read number x from the user. b- Then write function that calculate the
results as in f(x)
Answer:
#include <stdio.h>
int f(int);
int main() {
int x;
printf("Please enter the number:");
scanf("%d", &x);
x=f(x);
printf("The result is :%d \n",x);
return 0;
}
int f(int x){
if ( x > 3 )
x=x+1;
else if(x == 3 )
x=3*x - 2;
else if(x < 3 )
x=2*x - 1;
return x;
}
Submit screenshot of my code and my output for Q1
Answer Question 2:
a- What does this C code do?
Answer :
This code let the user read three numbers, then compare them to find the largest number and
print it.
b- Find the output of the code by giving 3 examples of the output:
Answer:
Example one:
Inputs num1=1, num2=4, num3=0
The output will be
the larger number is: 4
Example two:
Inputs num1=26, num2=10, num3=5
The output will be
the larger number is: 26
Example three:
Inputs num1=130, num2=178, num3=290
The output will be
the larger number is: 290