answersLogoWhite

0

How do you print rectangle in c?

Updated: 8/10/2023
User Avatar

Wiki User

11y ago

Best Answer

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 #include #include #include #include void draw (int r[][2]) { int i; setlinestyle (DOTTED_LINE, 0, 1); line (320, 0, 320, 480); line (0, 240, 640, 240); setlinestyle (SOLID_LINE, 0, 1); line (320+r[0][0], 240-r[0][1], 320+r[1][0], 240-r[1][1]); line (320+r[0][0], 240-r[0][1], 320+r[3][0], 240-r[3][1]); line (320+r[1][0], 240-r[1][1], 320+r[2][0], 240-r[2][1]); line (320+r[2][0], 240-r[2][1], 320+r[3][0], 240-r[3][1]); } void reset (int r[][2]) { int i; int val[4][2] = { { 0, 0 },{ 100, 0 },{ 100, 50 },{ 0, 50 } }; for (i=0; i<4; i++) { r[i][0] = val[i][0]; r[i][1] = val[i][1]; } } void rotate (int r[][2], int angle) { int i; double ang_rad = (angle * M_PI) / 180; for (i=0; i<4; i++) { double xnew, ynew; xnew = r[i][0] * cos (ang_rad) - r[i][1] * sin (ang_rad); ynew = r[i][0] * sin (ang_rad) + r[i][1] * cos (ang_rad); r[i][0] = xnew; r[i][1] = ynew; } } void shear (int r[][2], int sx, int sy) { int i; for (i=0; i<4; i++) { int xnew, ynew; xnew = r[i][0] + r[i][1] * sx; ynew = r[i][1] + r[i][0] * sy; r[i][0] = xnew; r[i][1] = ynew; } } void translate (int r[][2], int dx, int dy) { int i; for (i=0; i<4; i++) { r[i][0] += dx; r[i][1] += dy; } } void ini() { int gd=DETECT,gm; initgraph(&gd,&gm,"..//bgi"); } void main() { int r[4][2],angle,dx,dy,x, y,choice; do { clrscr(); printf("1.Rotation about the origin followed by translation\n"); printf("2.Rotation about an arbitrary point\n"); printf("3.Shear about the origin\n"); printf("4.Exit\n\n"); printf("Enter your choice: "); scanf("%d",&choice); switch(choice) { case 1: printf("Enter the rotation angle: "); scanf("%d", &angle); printf("Enter the x- and y-coordinates for translation: "); scanf("%d%d",&dx,&dy); ini(); cleardevice(); reset(r); draw(r);getch(); rotate(r, angle); cleardevice(); draw(r);getch(); translate(r,dx,dy); cleardevice(); draw(r);getch(); closegraph(); break; case 2: printf("Enter the rotation angle: "); scanf("%d",&angle); printf("Enter the x- and y-coordinates of the point: "); scanf("%d%d",&x,&y); ini(); cleardevice(); reset(r); translate(r,x,y); draw(r); putpixel(320+x,240-y,WHITE); getch(); translate(r,-x,-y); draw(r);getch(); rotate(r,angle); draw(r);getch(); translate(r,x,y); cleardevice(); draw(r); putpixel(320+x,240-y,WHITE); getch(); closegraph(); break; case 3: printf("Enter the x- and y-shears: "); scanf("%d%d",&x,&y); ini(); reset(r); draw(r);getch(); shear(r, x, y); cleardevice(); draw (r);getch(); closegraph(); break; case 4: closegraph(); } }while(choice!=4); }

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

#include<graphics.h>

#include<conio.h>

main()

{

int gd=DETECT,gm;

setcolor(RED);

rectangle(X1,Y1,X1,Y1);

getch();

return 0;

}

Where X1, Y1, X2 , Y2 represent the width and length of the rectangle. You must also make this in a project, and download the graphics.h file.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you print rectangle in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a function which takes your text as an input and print it in a center of the box in c plus plus?

C++ has no generic graphics capability whatsoever. Graphics are platform-specific, and every C++ implementation provides its own API and libraries specific to the intended platform. For instance, the following user-defined Visual C++ MFC function will centre any text (t) within a given rectangle (r) relative to the given device context (dc): void centre_text(CString&amp; t, CRect&amp; r, CDC&amp; dc) { CRect b; // bounding rectangle. // Calculate the bounding rectangle of the text: dc.DrawText( t, b, DT_CALCRECT ); // Position the bounding rectangle in the centre of the given rectangle: b.MoveToXY( r.left + (( r.Width() - b.Width() ) / 2 ), r.top + (( r.Height() - b.Height() ) / 2 )); // Draw the text in the bounding rectangle: dc.DrawText( t, b, DT_NOCLIP ); } Note that the above code is non-generic and therefore cannot be ported to other platforms. It will only work in Visual C++ MFC applications. However, the principal will be largely the same on other platforms: calculate the bounding rectangle, move it to the centre of the intended rectangle and then print the text in the bounding rectangle.


How do you print two slashes - right after another - in c?

You will have to use "printf" when you want to print two slashes one after another in c.


What does a c in a circle mean on a print?

Copyright


What is a C program to print initials?

printf ("initials");


Write various ways to implement stack data structure?

2. Write a program using switch statement that reads a character representing a geometrical figure, then asks the user to enter the required data (ex. Radius for a circle, length and height for a rectangle, etc. ...) . The program should then print the area and circumference.Figures are: circle(c), square(s), rectangle(r), triangle (t).

Related questions

Write a program that prompts the user to input the length and width of a rectangle and then prints the rectangle's area and perimeter?

PRINT "Give me the rectangle's length.": Input L PRINT "Give me the rectangle's width.": Input W PRINT "The rectangle's area is "; L x W PRINT "The rectangle's perimeter is "; 2 x (L + W) PRINT "You've been a great audience. I'm here til Thursday. Don't forget to tip your waiter. Have a nice day."


Write a function which takes your text as an input and print it in a center of the box in c plus plus?

C++ has no generic graphics capability whatsoever. Graphics are platform-specific, and every C++ implementation provides its own API and libraries specific to the intended platform. For instance, the following user-defined Visual C++ MFC function will centre any text (t) within a given rectangle (r) relative to the given device context (dc): void centre_text(CString&amp; t, CRect&amp; r, CDC&amp; dc) { CRect b; // bounding rectangle. // Calculate the bounding rectangle of the text: dc.DrawText( t, b, DT_CALCRECT ); // Position the bounding rectangle in the centre of the given rectangle: b.MoveToXY( r.left + (( r.Width() - b.Width() ) / 2 ), r.top + (( r.Height() - b.Height() ) / 2 )); // Draw the text in the bounding rectangle: dc.DrawText( t, b, DT_NOCLIP ); } Note that the above code is non-generic and therefore cannot be ported to other platforms. It will only work in Visual C++ MFC applications. However, the principal will be largely the same on other platforms: calculate the bounding rectangle, move it to the centre of the intended rectangle and then print the text in the bounding rectangle.


What is the shape of a rectangle print?

a rectangle. it has four parallel sides each side is the same length as the one on the other side.


What is the use of print option in c plus plus?

C++ has no print option. The print option in your IDE allows you to print your C++ source code, thus giving you a "hard" copy of your code.


Blue print for a house if the bedroom is a parallelogram with at least one right angle the bedroom is a rectangle square or rhombus?

A rectangle (or square).


What is a Type c photograph?

A C-print or Type C-print is a color print from a color negative. The term "Type C" is generally used to distinguish from R or Reversal prints or direct positive prints from transparencies (color positives). Type C prints can also be made digitally. Type C is probably the most common form of color print.


What always has a line of symmetry a. trapezoid b. parallelogram c. triangle d. rectangle?

d. rectangle


How do you print a triangle of stars?

write a c++ programe to print a triangle without (for)


How do you print in c?

printf(format_string, ...);


C program to find greatest of three numbers?

# include&lt;stdio.h&gt; main() { int a,b,c; print f("enter the values of a,b,c"); scan f("%d%d%d",&amp;a,&amp;b,&amp;c); if((a&gt;b)&amp;&amp;(a&gt;c)) print f("Greatest value is a =%d",a); else if((b&gt;a)&amp;&amp;(b&gt;c)) print f("Greatest value is b=%d",b); else print f("Greatest value is c=%d",c); }


How do you print two slashes - right after another - in c?

You will have to use "printf" when you want to print two slashes one after another in c.


Find the dimensions of the rectangle of largest area that can be inscribed in a circle of radius a in C programming?

Find the dimensions of the rectangle of largest area that can be inscribed in a circle of radius a in C programming