Professional Documents
Culture Documents
REPORT
Laboratory work nr. 1
At Computer Programming
Performed by:
St.gr. FAF-233 Postoronca Dumitru
Checked by:
Dr., univ. conf. Mikhail Kulev
Chisinau – 2023
Laboratory work 1
Topic: Use of control and loop instructions in C language
Purpose of the laboratory work: Studying techniques and methods of use a condition control
instructions and cyclic instructions in the C language for tabulating the function.
Problem condition [1] : To calculate and display on the screen the values of the argument x and the
values of the function F, defined by 3 given expressions, for the interval х1 ≤ x ≤ х2 and the step px of
incrementing the argument x. The values x1, x2, px and the parameters a, b, c are input data of type real.
Variant 7:
#include<stdio.h>
#include<math.h>
float a, b, c, x1, x2;
float F, px;
int n;
float func(int x){
if (x-2 > 0 && a==0){
return (a + log(x))/sin(c)-b*b;
}else if(x-2 < 0 || a!=0 ){
return (x-sin(x+1))/b;
}else return (a*x+c)/cos(x*2);
}
char display(float x){
return printf("%i) x = %.2f\tF = %.2f\n", n, x, func(x));
}
int implem_for(float x){
n=1;
printf("Solving the function using for loop:\n");
for (x=x1; x < x2; x+=px){
display(x);n++;
}return printf("\n");
}
int implem_while(float x){
n=1;
printf("Solving the function using while loop:\n");
while (x < x2){
display(x);n++;
x+=px;
}return printf("\n");
}
int implem_doWhile(float x){
n=1;
printf("Solving the function using do-while loop:\n");
do{
display(x);n++;
x+=px;
}while(x < x2);
return printf("\n");
}
int implem_goto(float x){
n=1;
printf("Solving the function using goto+if loop:\n");
begin:
display(x);n++;x+=px;
if (x < x2) goto begin;
else return printf("\n");
}
int main(){
printf("input the boundaries: ");scanf("%f %f", &x1, &x2);
printf("input the step: ");scanf("%f", &px);
printf("input the a, b and c: ");scanf("%f %f %f", &a, &b, &c);
implem_for(x1);
implem_while(x1);
implem_doWhile(x1);
implem_goto(x1);
return 0;
}
#include<stdio.h>
#include<inttypes.h>
int main(const int64_t *value){
int64_t n, m, a, aForN, aForM, result;
scanf("%"SCNd64, &n);
scanf("%"SCNd64, &m);
scanf("%"SCNd64, &a);
if (n % a != 0) aForN = n/a + 1;
else aForN = n/a;
if (m % a != 0) aForM = m/a + 1;
else aForM = m/a;
result=aForM*aForN;
printf ("%"PRId64, result);
return 0;
}
2A winner
Sincerely I don’t understand source of the troubles at test 10 because the code
follows all requirements in the task as they are written