Program to draw a circle using Mid-point circle drawing algorithm in C++
- Get link
- X
- Other Apps
#include<iostream>
#include<graphics.h>
using namespace std;
void circleMidpoint(int,int,int);
int main()
{
int xc,yc,r;
cout<<"Enter center coordinate of circle:";
cin>>xc>>yc;
cout<<"Enter radius of circle:";
cin>>r;
int gd=DETECT,gm;
char path[] = "";
initgraph(&gd,&gm,path);
circleMidpoint(xc,yc,r);
getch();
closegraph();
return 0;
}
void circleMidpoint(int xc,int yc,int r)
{
int x=0,y=r,P;
P= 1-r;
while(x<y)
{
putpixel(xc+x, yc+y, WHITE);
putpixel(xc-x, yc+y, WHITE);
putpixel(xc+x, yc-y, WHITE);
putpixel(xc-x, yc-y, WHITE);
putpixel(xc+y, yc+x, WHITE);
putpixel(xc-y, yc+x, WHITE);
putpixel(xc+y, yc-x, WHITE);
putpixel(xc-y, yc-x, WHITE);
if(P<0)
{
P = P+(2*x)+1;
x++;
}
else
{
P=P+2*(x-y)+1;
x++;
y--;
}
}
}
OUTPUT:
- Get link
- X
- Other Apps
Popular posts from this blog
Download and install MATLAB R2017a in Ubuntu 18.04 | Linux Free | Cracked
Smile emoji using graphics in Java using Applet
import java.awt.*; import java.awt.event.*; import java.applet.*; public class Smile extends Applet { public void paint(Graphics g) { setBackground(Color.BLACK); g.setColor(Color.YELLOW); g.fillOval(30,50,100, 100); g.setColor(Color.BLACK); g.fillOval(55,75,10, 10); g.fillOval(95,75,10, 10); g.drawArc(60, 85, 40,40,-30,-120); } } /* <applet code="Smile.class" width="200" height="200"> </applet> */ OUTPUT:
Program to find the LCM & HCF of n numbers
class HcfLcm { public static void main(String[] args) { int n,x; System.out.println("Number of integers: "); n = Integer.parseInt(System.console().readLine()); if(n<1) { System.out.print("Invalid input!"); System.exit(0); } int[] arr = new int[n]; for(int i =0; i<n; i++) { System.out.print("Number "+(i+1)+":"); ...
Comments
Post a Comment