Question
Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2)
without making use of any floating point computations at all.
Question Submitted By :: =-PKG-=
I also faced this Question!!
Rank
Answer Posted By
Re: Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2)
without making use of any floating point computations at all.
Answer
# 1
#include<stdio.h>
#include<graphics.h>
main()
{
int x,y,r;
printf("Enter x,y,r\n");
scanf("%d %d %d",&x,&y,&r);
int g=DETECT,gmode;
initgraphics(&g,&gmode,"");
circle(x,y,r);
closegraphics();
}
Vignesh
Re: Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2)
without making use of any floating point computations at all.
Answer
# 2
just use Bresenham's algo
d=1-r;
y=r;
x=0;
while(y>x)
{
if(d<0)
d+=2*x+3;
else {
d+=2*(x-y)+5;
y--;
}
x++;
plotpoints(x,y);
}
Daru
Other C Code Interview Questions
Question Asked @ Answers main()
{
register int a=2;
printf("Address of a = %d",&a);
printf("Value of a = %d",a);
} 1 main()
{
clrscr();
}
clrscr(); 1 main()
{
extern i;
printf("%d\n",i);
{
int i=20;
printf("%d\n",i);
}
} 1 main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
} 1 main()
{
int i, n;
char *x = “girl”;
n = strlen(x);
*x = x[n];
for(i=0; i<n; ++i)
{
printf(“%s\n”,x);
x++;
}
} 1 main()
{
struct student
{
char name[30];
struct date dob;
}stud;
struct date
{
int day,month,year;
};
scanf("%s%d%d%d", stud.rollno, &student.dob.day,
&student.dob.month, &student.dob.year);
} 1 programming in c lanugaue programm will errror error with
two header file one as stdio.h and other one is conio.h 1 union u
{
struct st
{
int i : 4;
int j : 4;
int k : 4;
int l;
}st;
int i;
}u;
main()
{
u.i = 100;
printf("%d, %d, %d",u.i, u.st.i, u.st.l);
}
a. 4, 4, 0
b. 0, 0, 0
c. 100, 4, 0
d. 40, 4, 0 HCL 1 void pascal f(int i,int j,int k)
{
printf(“%d %d %d”,i, j, k);
}
void cdecl f(int i,int j,int k)
{
printf(“%d %d %d”,i, j, k);
}
main()
{
int i=10;
f(i++,i++,i++);
printf(" %d\n",i);
i=10;
f(i++,i++,i++);
printf(" %d",i);
} 1 write a program to Insert in a sorted list Microsoft 4 main()
{
signed int bit=512, mBit;
{
mBit = ~bit;
bit = bit & ~bit ;
printf("%d %d", bit, mBit);
}
}
a. 0, 0
b. 0, 513
c. 512, 0
d. 0, -513 HCL 1 How to access command-line arguments? 4 main()
{
int i, j;
scanf("%d %d"+scanf("%d %d", &i, &j));
printf("%d %d", i, j);
}
a. Runtime error.
b. 0, 0
c. Compile error
d. the first two values entered by the user HCL 1 main()
{
char c;
int i = 456;
clrscr();
c = i;
printf("%d", c);
}
a. 456
b. -456
c. random number
d. none of the above HCL 1 plz send me all data structure related programs 1 main()
{
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
} 1 Given an array of size N in which every number is between 1
and N, determine if there are any duplicates in it. You are
allowed to destroy the array if you like. Microsoft 15 int DIM(int array[])
{
return sizeof(array)/sizeof(int );
}
main()
{
int arr[10];
printf(“The dimension of the array is %d”, DIM(arr));
} 1 main()
{
int i;
float *pf;
pf = (float *)&i;
*pf = 100.00;
printf("\n %d", i);
}
a. Runtime error.
b. 100
c. Some Integer not 100
d. None of the above HCL 1 String reverse with time complexity of n/2 with out using
temporary variable. NetApp 8 For more C Code Interview Questions Click Here