Follow Me

Generality exercises in C Programming in C

  • Pressure of a perfect gas at a constant temperature in a gravitational field: Write a program that calculates and displays the pressure of a perfect gas at a constant temperature in a gravitational field: \(P(z)=P_0 \times \exp{-\frac{Mgz}{RT}}\), with \(P_0=10^5 hP\), \(M=29 g.mol^{-1}\), \(g=9.8 m.s^{-1}\), \(R=8.32 J.K^{-1}.mol^{-1}\)...
  • Absolute value of an integer: Write a program that reads an integer from the keyboard and displays its absolute value....
  • Printing Hello: Write a program that prints the word "Hello" on the screen....
  • Sum of 6 and 8: Write a program that calculates and prints the sum of 6 and 8....
  • Sum of two numbers: Write a program that reads, calculates and prints the sum of 2 numbers....
  • Using math library: Try the following program (next slide) and modify it so that it displays: $$A^B$$, the hypotenuse of a right triangle of sides A and B, the tangent of A using only the sin and cos functions, the rounded value (in minus) of A / B, The rounded value (i...
  • Swapping the values of three integers: Write a program that swaps and displays the values of three integer variables A, B, C entered on the keyboard: A ==> B , B ==> C , C ==> A...
  • Integer division: Write a program that displays the quotient and the remainder of the integer division of two integers entered on the keyboard as well as the rational quotient of those numbers....
  • Equivalent resistance: Write a program that displays the resistance equivalent to three resistors R1, R2, R3 (double type), if the resistors are connected in series: $$R_{ser} = R1+R2+R3$$ if the resistors are connected in parallel: $$R_{par} =\frac{R1*R2*R3}{R1*R2+R1*R3+R...
  • Area of a triangle: Write a program that calculates and displays the area of a triangle whose lengths must be entered on all three sides. Use the formula: $$S^2 = P*(P-A)*(P-B)*(P-C)$$ where A, B, C are the lengths of the three sides (type int) and P the half-perimeter ...
  • Sum of five variables: Write a program that calculates the sum of four numbers of type int entered on the keyboard, using 5 variables (saving of the entered values) using 2 variables (loss of the entered values) ...
  • Inclusive price: Write a program that calculates the inclusive price (double type) of an item from the net price (type int) and the VAT percentage (type int) to be added. Use the following formula, paying attention to priorities and automatic type conversions: $$PTTC...
  • Distance between two points: Write a program that calculates and displays the distance DIST (double type) between two points A and B whose coordinates (XA, YA) and (XB, YB) are entered in as integers...
  • Swapping two integers: Write a program that declares two integer variables X and Y. The user must enter their values and then exchange their values (swap X and Y) X takes the value of Y, and Y takes the value of X....
  • Fahrenheit to Celsius: Write a program that converts the temperature from Fahrenheit to Celsius. \[C=\frac{5}{9}(F-32)\]...
  • Rounding real numbers: Write a program that rounds a real number entered on the keyboard to two digits after the decimal point....
  • Opposite of a real: Write a program that reads a real value and displays its opposite....
  • Display name and birth date: Write a program that reads and displays your first name and date of birth on two different lines....
  • Sum and multiplication of two integers: Write a program that declares two integer variables. The user must enter their values. The program then calculates their sum, their multiplication, and displays the results....
  • Absolute value: Write a program that reads two integer values x and y and displays the absolute value of (x-y). Execution example:Enter x: -5Enter y: 4 The absolute value obtained = 9...
  • Discounted price: During a promotion operation, a hardware component store applies a 10% discount on all components. Write a program that reads the price of a component on the keyboard and displays the calculated price taking into account the discount....
  • Program output: Give the output on the screen of the following program (indicate a space using this symbol _): #include<stdio.h>double mystery(int A[], int i){     i = A[i] * 2;     A[0] = 0;     return i+1;} int main(){     int i = 8, j = 5, k, A[...
  • Program output 1: Give the output on the screen of the following program #include <stdio.h>int main(){     int x;     x = -3 + 4 * 5 -6; printf("%d\n",x);     x = 3 + 4 % 5 -6; printf("%d\n",x);     x = -3 * 4 % -6 / 5 ; printf("%d\n",x);     x = ...
  • Program output 2: Give the output on the screen of the following program #include <stdio.h>int main(){    int x = 3, y , z;     x*= 2 + 1; printf("%d\n",x);     x *= y = z = 3; printf("%d\n",x);     x = y == z ; printf("%d\n",x);     x == ...
  • Program output 3: Give the output on the screen of the following program #include <stdio.h>int main(){    int x = 3, y = 1 , z = 0;     x = x && y || z; printf("%d\n",x);     printf("%d\n",x || ! y && z);     x = y = 2;     ...
  • Program output 5: Give the output on the screen of the following program #include <stdio.h>int main(){    int x , y ,z;      x = y = z = 1;      x += y += z;      printf("%d\n", x < y ? y : x);      printf("%d\n",x < y ? x++:y++)...
  • Program output 6: Give the output on the screen of the following program #include <stdio.h>void print(int x, int y, int z){     printf("x = %d \t y = %d \t z = %d\n", x ,y ,z);}int main(){     int x , y ,z;      x = y = z = 1;     ++x || ++y &...
  • Program output 12: Give the output on the screen of the following program (indicate a space using this symbol _): #include<stdio.h>int main(){     int a = 7, b = 4, c;     double x = 0.02, y = -0.05, z = 0.1 ;     printf("#1# %d ##\n", (a + b) % 1234); ...
  • Program output 13: Give the output on the screen of the following program (indicate a space using this symbol _): #include<stdio.h>double mystery(int T[], int i){     int k;      for(k=0 ; k<i ; k++)          T[k] -= T[i] - k;     return T[k] + ...
  • Program output 4: Give the output on the screen of the following program #include <stdio.h>#define PRINT(i) printf("value = %d\n", i)int main(){     int x = 03, y = 02 , z = 01;     PRINT(x | y & z);      PRINT(x | y & - z);      PRINT(x ^ y ...
  • Program output 7: Give the output on the screen of the following program #include <stdio.h> #define PRINT(format,x) printf(#x " = %"#format"\n",x) int main(){     int integer = 5;     char character = '5';     char *string = "5";     PRINT(d, string)...
  • Program output 8: Give the output on the screen of the following program #include <stdio.h> #define PR(x) printf(#x " = %.8g\t",(double)x)#define NL putchar('\n');#define PRINT4(a,b,c,d) PR(a);PR(b);PR(c);PR(d);NL int main(){     double d;     float f;  Â...
  • Program output 9: Give the output on the screen of the following program #include <stdio.h> #define PR(x) printf(#x " = %.8g\t",(double)x)#define NL putchar('\n');#define PRINT1(a) PR(a);NL#define PRINT2(a,b) PR(a);PR(b);NL int main(){     double d = 3.2 , x;...
  • Program output 10: Give the output on the screen of the following program #include <stdio.h> #define PRINT(format,x) printf(#x " = %"#format"\t",x)#define NL putchar('\n'); #define PRINT1(f,x) PRINT(f,x);NL#define PRINT2(f,x1,x2) PRINT(f,x1);PRINT1(f,x2)#define...
  • Program output 11: Give the output on the screen of the following program #include <stdio.h> #define PRINT(format,x) printf(#x " = %"#format"\t",x)#define NL putchar('\n'); #define PRINT1(f,x) PRINT(f,x);NL#define PRINT2(f,x1,x2) PRINT(f,x1);PRINT1(f,x2)#define...

Back to the list of exercises