fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. // Define the range of x values
  6. float x_start = 0.0;
  7. float x_end = 1.0;
  8. float step = 0.1;
  9.  
  10. // Print the header of the table
  11. printf("x\tcos(x)\n");
  12. printf("----\t----\n");
  13.  
  14. // Calculate and print the values for each x
  15. for (float x = x_start; x <= x_end; x += step) {
  16. // Calculate the cosine of x
  17. float cosx = cos(x);
  18.  
  19. // Print the x and cos(x) values
  20. printf("%.2f\t%.4f\n", x, cosx);
  21. }
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
x	cos(x)
----	----
0.00	1.0000
0.10	0.9950
0.20	0.9801
0.30	0.9553
0.40	0.9211
0.50	0.8776
0.60	0.8253
0.70	0.7648
0.80	0.6967
0.90	0.6216