0% found this document useful (0 votes)
0 views5 pages

PW3: Computer Science 1 (Sections: A, F, G) /ST Department: Part I: (Operators Priority in Langage C)

The document outlines exercises related to C programming, covering operator priority, if-else statements, switch cases, and loops. It includes tasks such as evaluating expressions, writing programs for various scenarios, and calculating averages based on user input. Additionally, it requires the implementation of algorithms and modifications for user-defined inputs.

Uploaded by

julienmanceaux
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views5 pages

PW3: Computer Science 1 (Sections: A, F, G) /ST Department: Part I: (Operators Priority in Langage C)

The document outlines exercises related to C programming, covering operator priority, if-else statements, switch cases, and loops. It includes tasks such as evaluating expressions, writing programs for various scenarios, and calculating averages based on user input. Additionally, it requires the implementation of algorithms and modifications for user-defined inputs.

Uploaded by

julienmanceaux
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

PW3: Computer science 1(sections: A, F, G)/ST Department

Part I: (Operators priority in langage c)

1. Give the type of the following expressions writing in C language:


 (a < b) || !(c > = d) && (b < c)
 a + pow (b/c,2) +((d/3+4)/3+a)/b
 (a>4) && !(d % 3 * 2 < 1) || (a>=8) && (a==c)

2. Write the previous expressions in algorithmic.


3. Evaluate them respecting the order of priority of the operators knowing that: a= 1,
b=2, c=4, d=6.

Part II: (if else statement)

Exercise 1:

1. Write the following program in your IDE.

#include <stdio.h>
#include <math.h>
int main()
{
int nbr,x,y;
printf("Enter a number:\n");
scanf ("%d", &nbr);
printf("Enter value to x:\n");
scanf ("%d", &x);
if (nbr%2 == 0)
{
printf("%d is even:", nbr);
y=sqrt (fabs(x+1)) ;
}
else
{
printf("%d is odd:\n", nbr);
y= sqrt (fabs(pow(x,3) +1)) ;
}
printf("y= %d \n", y);
return 0;
}
2. Give the on-screen display of the following program for two cases :
Case 1: nbr =13, x =2
Case 2: nbr =20, x =-5
3. What this program do?

Exercise 2:

Write a program c that:

 Reads three marks from the keyboard


 Calculates and display the average of these marks
 Display the corresponding mention as follows:

Not admitted if the average is less than 10

Fair if it is between 10 and 12

Good if it is greater than 12

Exercise 3:

Write the program c corresponding to this organizational chart (flowchart):


yes no

yes
x1=-b/ (2*a)

no

Exercise 4:

Write a C program which reads a real x then calculates y with:

𝑥² + 2 if x < 2
Y= 8_𝑥) if 8 > 𝑥 ≥ 2
(𝑥 2 − 8)3 if x ≥ 8

Part III :(switch)

1. Write the following program in your IDE.


2. Give the on-screen display of the following program for two cases :
Case 1: p=2
Case 2: P=8
3. Remove the key word break from the program then commentate.
4. Write the corresponding program using the instructions if else?
#include <stdio.h>

int main()

int p,price;

printf("power = ");

scanf("%d",&p);

switch(p)

case 1:

case 2:

case 3: price = 500; break;

case 4:

case 5:

case 6: price= 1500; break;

case 7:

case 8:

case 9: price = 2500; break;

default: price = 3500;

printf("price = %d ",price);

return 0;

}
Part IV : Loops

 Write an algorithm that displays the ten first integers? Modify the algorithm to
display the N (given by the user) first integers?
 Write an algorithm that calculates the sum of ten first positive integers? Modify
the algorithm to calculate the sum of N (given by the user) first positive integers?
 Rewrite the previous algorithms in language c.

You might also like