fork download
  1. #include<graphics.h>
  2. #include<stdio.h>
  3. #include<math.h>
  4.  
  5. //Function to plot the ellipse
  6. void pixel (int xc, int yc, int x,int y)
  7. {
  8. putpixel(320+(xc+x),240-(yc+y),14);
  9. putpixel(320+(xc+x),240-(yc-y),14);
  10. putpixel(320+(xc-x),240-(yc-y),14);
  11. putpixel(320+(xc-x),240-(yc+y),14);
  12. }
  13.  
  14. int main()
  15. {
  16. int xc, yc, x, y, p, rx, ry;
  17.  
  18. int gdriver=DETECT, gmode; //Detects the graphics drivers automatically
  19. initgraph(&gdriver, &gmode,""); //Initialize to graphics mode
  20.  
  21. printf("Enter the co-ordinates of the center of the ellipse : ");
  22. scanf("%d %d",&xc,&yc);
  23. printf("Enter the value of rx and ry of the ellipse : ");
  24. scanf("%d %d",&rx,&ry);
  25.  
  26. //Take start position as(0,ry)
  27. x=0;
  28. y=ry;
  29.  
  30. p=(ry*ry)-(rx*rx*ry)+((rx*rx)/4); //Finding decision parameter p in region 1
  31.  
  32. //To plot the quadrants
  33. line(0,240,639,240);
  34. line(320,0,320,479);
  35. outtextxy(295,243,"0,0");
  36. setcolor(WHITE);
  37.  
  38. pixel (xc, yc, x, y);
  39.  
  40. while((2*x*ry*ry)<(2*y*rx*rx)) //At each x position in region 1
  41. {
  42. if(p<0) //If decision parameter is less than 0
  43. {
  44. x++; //Increment x
  45. p=p+(2*ry*ry*x)+(ry*ry); //Calculate the new decision parameter
  46. }
  47. else //If decision parameter is greater than 0
  48. {
  49. x++; //Increment x
  50. y--; //Decrement y
  51. p=p+(2*ry*ry*x)+(ry*ry)-(2*rx*rx*y); //Calculate the new decision parameter
  52. }
  53. pixel (xc, yc, x, y);
  54. }
  55.  
  56. p=ry*ry*pow((float)x+0.5,2) + rx*rx*pow(y-1,2)-rx*rx*ry*ry; //Finding decision parameter p in region 2
  57. pixel (xc, yc, x, y);
  58.  
  59. while(y>=0) //At each y position in region 2
  60. {
  61. if(p>0) //If decision parameter is greater than 0
  62. {
  63. y--; //Decrement y
  64. p=p-(2*y*rx*rx)+(rx*rx); //Calculate the new decision parameter
  65. }
  66. else //If decision parameter is less than 0
  67. {
  68. y--; //Decrement y
  69. x++; //Increment x
  70. p=p+(2*ry*ry*x)-(2*y*rx*rx)+(rx+rx); //Calculate the new decision parameter
  71. }
  72. pixel (xc, yc, x, y);
  73. }
  74.  
  75. getch(); //Pauses the Output Console until a key is pressed
  76. closegraph(); //Closes the graphics mode
  77. return 0;
  78. }
  79.  
Success #stdin #stdout #stderr 0.13s 45012KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
parse error near line 5 of file /home/D22bo7/prog.octave

  syntax error

>>> //Function to plot the ellipse
    ^

error: source: error sourcing file '/home/D22bo7/prog.octave'