answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

Implement Bresenham algorithm using c language?

#include<stdio.h> #include<conio.h> #include<math.h> #include<graphics.h> void draw_line(float,float,float,float); main() { int driver,mode; float x1,y1,x2,y2; clrscr(); printf("Enter the two endpoints of the line:"); printf("\nx1 ="); scanf("%f",&x1); printf("y1 ="); scanf("%f",&y1); printf("x2 ="); scanf("%f",&x2); printf("y2 ="); scanf("%f",&y2); clrscr(); driver = DETECT; initgraph(&driver,&mode,"\\tc\\bgi"); \\path of bgi can be different in your case draw_line(x1,y1,x2,y2); getch(); closegraph(); } void draw_line(float x1,float y1,float x2,float y2) { float dy,dx; float x,y; float p,p0,dp1,dp2; dy = y2-y1; dx = x2-x1; p0 = 2 * (dy - dx); dp1 = 2 * dy; dp2 = 2 * (dy - dx); putpixel(x1,y1,EGA_WHITE); p = p0; for(x=x1+1,y=y1;x<x2;x++) { if(p < 0) { p = p+dp1; putpixel(x,y,EGA_WHITE); } else { p = p+dp2; y++; putpixel(x,y,EGA_WHITE); } }

What is mail merge and where is it used?

Mail merge is a facility of Microsoft's Word program, and other wordf processing applications.

It allows the user to set up a form letter, with blank spaces in certain parts.

The user then sets up a mini-database, or uses an existing database, to send a personalised copy of the letter to people in the database, with the blank spaces being filled by their particulars... the process adjusts the text of the letter so that even if the entry is extremely long, or extremely short, the recipient thinks that the letter is unique to them.

It can also be used just to print address labels.

Would a 64Bit processor work with a 32Bit operating system?

It can do but it is really the other way around. A 32-bit operating system can work with a 64-bit processor. However, if the processor doesn't have a "soft" switching mode, you will have to manually switch the 64-bit processor to 32-bit mode via the CMOS setup.

Ideally you should install a 64-bit operating system and leave the processor in 64-bit mode. This will then allow you to run 32-bit programs and 64-bit programs side-by-side.

Write a program to accept two numbers and display their sum?

Assuming you're using the C programming language (as you did not specify any other), and that you're making some sort of arithmetic tester, a simple answer would be:

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int main()

{

time_t seconds;

time(&seconds);

srand((unsigned int)seconds);

int num1 = (rand()%100);

int num2 = (rand()%100);

int sum = num1 + num2;

int ans;

printf("What is %d + %d? ", num1, num2);

scanf("%d", &ans);

if(ans == sum) printf("Correct!");

else printf("Wrong, correct answer is %d", sum);

return 0;

}

Why do the time on my computer changes for no reason?

The reason is your cmos battery is about to die. All desktop PCs use a small lithium battery, similar to those used by hand-held calculators to keep time and date info. Once this battery runs low on voltage, your date and time will be shown incorrectly.

The solution: unplug your PC, open the case and carefully extract the battery (use a small flashlight). Buy a new one of the same number (cr2032, cr2025, etc.) and install it the right way. Don't worry, it will fit only one way. Now turn your PC on and set the time and date and that's it, no problem with that for a good few years. Hope this helps.

What does printf and scanf return?

Printf returned no. of character receive .

scanf return no of variable to be inputed according to format specifier . eg:

i=printf("thisisc") printf("%d",i); //i=7 j=scanf("dd",&a,&b,&c,&d); printf("%d",j);

IT IS MOST APPROPRIATE ANSWER FOR THIS Q .......... PLZ DO Practically............

How many pointers will have to be changed if a node is deleted from a linear linked list?

For a singly-linked list, only one pointer must be changed. If the node about to be deleted (let's call it node for the sake of argument) is the head of the list, then the head node pointer must be changed to node->next. Otherwise, the node that comes before the deleted node must change its next pointer to node->next.
Note that given a singly-linked node has no knowledge of its previous node, we must traverse the list from the head in order to locate that particular node, unless the node is the head of the list:

void remove (List* list, Node* node) {
if (!list !node) return; // sanity check!
if (list->head == node) {
list->head = node->next;
} else {
Node* prev = list->head;
while (prev->next != node) prev = prev->next; // locate the node's previous node
prev->next = node->next;
}
}

Note that the remove function only removes the node from the list, it does not delete it. This allows us to restore the node to its original position, because the node itself was never modified (and thus still refers to its next node in the list). So long as we restore all removed nodes in the reverse order they were removed, we can easily restore the list. In order to delete a node completely, we simply remove it and then free it:

void delete (List* list, Node* node) {
if (!list !node) return; // sanity check!
remove (list, node);
free (node);
}

For a doubly-linked list, either two or four pointers must be changed. If the node about to be deleted is the head node, then the head node pointer must be changed to n->next and n->next->prev must be changed to NULL, otherwise, n->prev->next becomes n->next. In addition, if the node about to be deleted is the tail node, then the tail node pointer must be changed to n->prev and n->prev->next must be changed to NULL, otherwise, n->next->prev becomes n->prev.


Deletion from a doubly-linked list is generally quicker than deletion from a singly linked list because a node in a doubly-linked list knows both its previous node and its next node, so there's no need to traverse the list to locate the previous node to the one being deleted.

void remove (List* list, Node* node) {
if (!list !node) return; // sanity check!
if (list->head == node) {
list->head = node->next;
node->next->prev = NULL;
} else {
node->prev->next = node->next;
}
if (list->tail == node) {
list->tail = node->prev;
node->prev->next = NULL;
} else {
node->next->prev = node->prev;
}
}


Again, to physically delete the node we simply remove and then free the node:


void delete (List* list, Node* node) {

if (!list !node) return; // sanity check!

remove (list, node);
free (node);
}

Can you have a final abstract class?

No. The abstract keyword means that you cannot instantiate the class unless you extend it with a subclass. The final keyword means that you cannot create subclasses of that class.

Combining them would lead to an unusable class, so the compiler will not let this happen.

What are advantages and disadvantages of priority queue?

In CQ we utilize memory efficiently. because in queue when we delete any

element only front increment by 1, but that position is not used later. so when

we perform more add and delete operation, memory wastage increase. But in CQ

memory is utilized, if we delete any element that position is used later,

because it is circular.

What is the difference between a queue and a stack?

Queue is better than stack because jobs in a queue are processed on a first in first out order thereby reducing traffic and delay.

But jobs in a stack are processed in a last in first out order causing traffic and delay of jobs that arrived earlier

What are 3 different data types?

According to Wikipedia,

"In computer science and computer programming, a data type or simply type is a classification identifying one of various types of data, such as real-valued, integer or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of that type can be stored."

"Almost all programming languages explicitly include the notion of data type, though different languages may use different terminology. Common data types may include:

  • integers,
  • booleans,
  • characters,
  • floating-point numbers,
  • alphanumeric strings."

How do you write algorithm to find the area of a rectangle?

You will need to define the input and times length by width.

For example: L - Length & W - Width


start

sum = 0

input L, W

sum = L * W

print "The area of the rectangle is: SUM"

end

What commands to draw pentagon in logo?

to draw-pentagon :length

pd

seth 126

repeat 5 [ fd :length rt 72 ]

end

Draws a pentagon "length" pixels on each side, with the turtle originating and terminating at the apex.

What is a computer interpreter?

An interpreter, or a translator, is a person who translates different languages. For an example, if a Chinese person and an American person can't understand each other, an intepreter can translate for both of them.

What is a high level progrmming language?

It is a programming language with strong abstraction from the details of the computer.

Advantages and disadvantages of using employee referral campaign recruitment?

· Employee referrals:

o Advantages: choosing a person that you know well (character, qualifications etc), save cost & time vs advertisement.

o Disadvantages: if person is not suitable (qualifications, experience, character etc) but is merely a friend/relative (nepotism) of the current employee. Favoritisms, potential request for unreasonable favor in return.

C program for newton's backward interpolation?

#include<stdio.h>

#include<conio.h>

#include<process.h>

#include<math.h>

void main()

{

int n;

int i,j;

float ax[10];

float ay[10];

float x;

float y=0;

float h;

float p;

float diff[20][20];

float y1,y2,y3,y4;

clrscr();

printf("\t\t!! NEWTON GRAGORY FORWARD INTERPOLATION FORMULA!!\n");

printf("\t\t By KRISHAN \t\t\n");

printf("\t\t enter the no of terms ->");

scanf("%d",&n);

printf("\n\t\t enter the value in form of x->");

for(i=0;i<n;i++)

{

printf("\n\t\t enter the value of x%d->",i+1);

scanf("%f",&ax[i]);

}

printf("\n\t\tenter the value in the form of y->");

for(i=0;i<n;i++)

{

printf("\n\t\tenter the value of y %d->",i+1);

scanf("%f",&ay[i]);

}

printf("\n\t\tenter the value of x for");

printf("\n\t\t which u want the value of y->");

scanf("%f",&x);

h=ax[1]-ax[0];

for(i=0;i<n-1;i++)

diff[i][1]=ay[i+1]-ay[i];

for(j=2;j<=4;j++)

for(i=0;i<n-j;i++)

diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

do

{

i++;

}

while(ax[i]<x);

i--;

p=(x-ax[i])/h;

y1=p*diff[i-1][1];

y2=p*(p+1)*diff[i-1][2]/2;

y3=p*(p+1)*(p-1)*diff[i-2][3]/6;

y4=(p+2)*(p+1)*p*(p-1)*diff[i-3][4]/24;

y=ay[i]+y1+y2+y3+y4;

printf("\n\t\t when x=%6.4f,y=%6.8f",x,y);

printf("\n\n\n\t\t\t!! PRESS ENTER TO EXIT!!");

getch();

}

Write a simple program algorithms flow charts to find out how many of the numbers from 1 to 10 is greater than 4?

/* c program for how many of the numbers from 1 to 10 is greater than 4? */

#include

void main()

{

int i ,j=0; /* j is used for counting the nos greater than 4 from 1 to 10*/

for(i=1;i<=10;i++)

if(i>4)

j++;

printf("\n The numbers greater than 4 , from 1 to 10 is %d",j);

}

Algorithm

step 1:start

step 2 :initialize j=0

step 3 :Initialize i=1,check whether i < 10 ,if true increment i else go to step 6

step 4: check whether i >4 If true go to step5 ,else go to step 3

step 5 :Increment j and then go to step 3

step 6:print the value of j

step 7 :Stop

Why do we avoid loops in programming?

We don't avoid loops in programming. Loops are a fundamental feature of many algorithms. If we need to iterate over a data sequence in order to perform the same set of operations upon each data element, we would use an iterative loop. If we need to repeatedly reduce a larger problem into one or more smaller instances of the same problem until the problem is small enough to be solved we'd use a recursive loop.

Write a c program to Calculate the average of five entered number from keyboard?

Sample code is as follows:

#include <stdio.h>

void main()

{

int i = 0;

int final_number = 0;

int array[] = {1,2,3,4,5};

for(i = 0; i < (sizeof(array)/sizeof(array[0])); i++)

{

final_number += array[i];

}

printf("Sum = %d and average = %d", final_number, (final_number / i));

}

A c comma c plus plus program that can accept first name surname and display it?

int main()

{

std::string first, last;

std::cout << "Enter your first name: ";

std::cin >> first;

std::cout << "Enter your last name: ";

std::cin >> last;

}

Enqueue and dequeue in data structures?

The queue insert operation is known is enqueue.

A queue has two ends namely REAR & FRONT. After the data has been inserted in a queue ,the new element becomes REAR.The queue deletion operation is known as dequeue.

The data at the front of the queue is removed .

How can you define a structure with bit field members?

We can define structure bit field members with Dot operators.

EXAMPLE:

#include <stdio.h>

int main()

{

Struct bit_field

{

Int x.4; // it allocates only 4 bits to x

Char C.6; // it allocates only 6 bits to C;

};

return 0;

}

What type of triangle has all different sides?

Scalene sides are different lengthed

isosceles two of the 3 sides are the same

equilateral, the three sides are the same lenght and are all at 90degrees