PW3: Computer Science 1 (Sections: A, F, G) /ST Department: Part I: (Operators Priority in Langage C)
PW3: Computer Science 1 (Sections: A, F, G) /ST Department: Part I: (Operators Priority in Langage C)
Exercise 1:
#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:
Exercise 3:
yes
x1=-b/ (2*a)
no
Exercise 4:
𝑥² + 2 if x < 2
Y= 8_𝑥) if 8 > 𝑥 ≥ 2
(𝑥 2 − 8)3 if x ≥ 8
int main()
int p,price;
printf("power = ");
scanf("%d",&p);
switch(p)
case 1:
case 2:
case 4:
case 5:
case 7:
case 8:
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.