0% found this document useful (0 votes)
29 views

Submit Screenshot of My Code and My Output For Q1

This C program reads a number from the user, passes it to a function f(x) that performs different calculations on the number depending on whether it is greater than, equal to, or less than 3, and returns and prints the result. The function adds 1 if the number is greater than 3, multiplies the number by 3 and subtracts 2 if it is equal to 3, or multiplies the number by 2 and subtracts 1 if it is less than 3.

Uploaded by

abdh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Submit Screenshot of My Code and My Output For Q1

This C program reads a number from the user, passes it to a function f(x) that performs different calculations on the number depending on whether it is greater than, equal to, or less than 3, and returns and prints the result. The function adds 1 if the number is greater than 3, multiplies the number by 3 and subtracts 2 if it is equal to 3, or multiplies the number by 2 and subtracts 1 if it is less than 3.

Uploaded by

abdh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like