Wednesday, 15 July 2015

c - Print ellipse using characters -


Form A (x - h) ^ 2 + 2 of the normal equation for rotated oval centered on (H, K).

I am trying to print a filled oval by using this formula, but it only prints' s on the first line and for the next 39 lines of \ n where the loop Breaks. Why I am not doing this.

These are the codes of my line, I am using input A = 0.04, B = 0.001, C = 0.01, h and k = 6, I would call 5x10 oval with a center 6, 6 Should print.

  int x = 0, y = 0, h, k; Float A, B, C; Printf ("Input A"); Scan ("% F", & amp; A); Printf ("Input B"); Scanf ("% F", and B); Printf ("Input C"); Scanf ("% f", & amp; c); Printf ("Input"); Scan ("% F", & amp; nbsp;); Printf ("Input"); Scanf ("% f", & amp; amp; k); While (1) {if (y> = 40) {break; } If ((a * (xh) * (xh)) + (b * (xH) * (vk)) + (c * (yk) * (yk))))  = 80) {printf ("\ n"); Y ++; to continue; } Other {printf (""); X ++; to continue; }} Return 0;    

This trivial fix of your code, which changes to a MCVE () When I run it shows more or less oval output:

  #include & lt; Stdio.h & gt; Int main (zero) {float A = 0.04; Float b = 0.001; Float C = 0.01; Int H = 6; Int k = 6; Int x = 0; Int y = 0; While (y <40) {if ((* (x * h) * (x - h)) + (b * (x - h) * (y - k)) + (c * (y - k) * (Y - K)) <= 1.0) {printf ("*"); X ++; } And if (x> = 80) {printf ("\ n"); Y ++; X = 0; } Other {printf (""); X ++; }} Return 0; }  

Sample Output:

 $ ./ellipse ******** ********* **** ***** ******** ********* ******** *********** ******* * * *************** *************** *** *** ***** *  

(A number of more blank rows).

Since the bulk was done in comments and not by me, I made this reply community wiki.


No comments:

Post a Comment