fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define SWIDTH 100
  6. #define SHEIGHT 50
  7. #define PLOTCHAR '*'
  8.  
  9. int f(x) {
  10. int p = (25 - x) / 3;
  11. int yd = 25;
  12. return p * p + yd;
  13. }
  14.  
  15. int f2(x) {
  16. float p = (x - SWIDTH / 2.0) / SWIDTH * 3.0 * 3.14159;
  17. int yd = 25;
  18. return (int) (floor(sin(p) * 20) + yd);
  19. }
  20.  
  21. void printscale_x() {
  22. int x;
  23.  
  24. printf(" ");
  25. for(x = 0; x < SWIDTH; ++x) {
  26. if (x % 10 == 0)
  27. printf("%d", x / 10);
  28. else
  29. printf(" ");
  30. }
  31. printf("\n");
  32.  
  33. printf(" ");
  34. for(x = 0; x < SWIDTH; ++x) {
  35. printf("%d", x%10);
  36. }
  37. printf("\n");
  38. }
  39.  
  40. main()
  41. {
  42. char scrn[SWIDTH][SHEIGHT];
  43. int x, y;
  44.  
  45. for(x = 0; x < SWIDTH; ++x) {
  46. for (y = 0; y < SHEIGHT; ++y) {
  47. scrn[x][y] = ' ';
  48. }
  49. }
  50.  
  51. for (x=0; x < SWIDTH; ++x) {
  52. /*printf("%d\n", f2(x));*/
  53. if (f2(x) < SHEIGHT) {
  54. scrn[x][f2(x)] = PLOTCHAR;
  55. }
  56. else {
  57. scrn[x][SHEIGHT - 1] = '+';
  58. }
  59. }
  60.  
  61. printscale_x();
  62.  
  63. for(y = SHEIGHT - 1; y >= 0; --y) {
  64.  
  65. printf("%02d ", y);
  66. for (x = 0; x < SWIDTH; ++x) {
  67. printf("%c", scrn[x][y]);
  68. }
  69. printf("\n");
  70. }
  71.  
  72. printscale_x();
  73.  
  74. return 0;
  75. }
  76.  
Success #stdin #stdout 0.01s 1676KB
stdin
Standard input is empty
stdout
   0         1         2         3         4         5         6         7         8         9         
   0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
49                                                                                                     
48                                                                                                     
47                                                                                                     
46                                                                                                     
45                                                                                                     
44 ****                                                            *******                             
43     *                                                         **       *                            
42      *                                                       *          *                           
41       *                                                     *            *                          
40        *                                                   *              *                         
39         *                                                                  *                        
38          *                                                *                                         
37                                                          *                  *                       
36           *                                                                  *                      
35            *                                            *                                           
34                                                        *                      *                     
33             *                                                                                       
32                                                       *                        *                    
31              *                                                                  *                   
30                                                      *                                              
29               *                                                                  *                  
28                *                                    *                                               
27                                                                                   *                 
26                 *                                  *                                                
25                                                   *                                *                
24                  *                                                                                  
23                                                  *                                  *               
22                   *                                                                                 
21                                                 *                                    *              
20                    *                                                                  *             
19                                                *                                                    
18                     *                                                                  *            
17                      *                        *                                                     
16                                                                                         *           
15                       *                      *                                                      
14                                             *                                            *          
13                        *                                                                  *         
12                         *                  *                                                        
11                                           *                                                *        
10                          *                                                                  *       
09                           *              *                                                   *      
08                            *            *                                                     *     
07                             *          *                                                       *    
06                              *       **                                                         *   
05                               *******                                                            ***
04                                                                                                     
03                                                                                                     
02                                                                                                     
01                                                                                                     
00                                                                                                     
   0         1         2         3         4         5         6         7         8         9         
   0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789