answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

What are the real time applications of linked lists?

For understanding basic concept train would be the best example for linked lists for example adding and deleting nodes is how we add and remove compartments in a train

Real time application where linked list is really used is maintaining relational databases.

in database tables may be associated with each other so for linking it to each other linked list data structure is the best choice

Where the printf statements are stored in memory?

Try this:

#include <stdio.h>

int main (void)

{

printf ("printf is at location %p\n", (void *)printf);

printf ("main is at location %p\n", (void *)main);

return 0;

}

What are the two parts of class specification in c plus plus programming?

There are more than two, but the class name and interface would be the minimum specification for any class. The interface can be further divided into public, protected and private access, each of which may contain member methods and/or member variables, which may themselves be static and/or non-static. The last part of the specification are the friend declarations, if required.

What are the signs in flow charts?

System flowcharts are the ideal diagrams for visually representing processes. System flow chart symbols include, terminator (it is oval in shape and indicates either start or end of a process, and normally contain the word 'start ' or 'End '), process (represented by rectangle), arrow (used to show the flow of control in a process), connector (circular in shape), data (input/output) (represented by a parallelogram), Decision (Diamond shaped), Junction (represented by a black bob), Concurrency (used whenever two or more control flows must run simultaneously),and subroutine(represented as a rectangle with a double-struck vertical edge).

How composite structures fittnig in airplane?

Assemblies made of composites are typically installed by fasteners. Composite structures are made of glass fibers or carbon fibers that have glue that bonds it together in an oven. During manufacture of the composite structure, a metal strip or a rib or a bushing will be attached to it that will allow it to be mated to the airplane or other structure. For example: take a complex helicopter rotor blade. These are usually made by winding long fibers along the length of the blade to form the main spar. Then more fibers are wound around this in a spiral trace from one end to the other. Over this a skin is added and a leading edge shield is attached. At the root of the blade, the first fibers that are laid down are usually wrapped around a bushing that becomes the bolt hole for attaching it to the main rotor hub. The tip of the blade is trimmed off and sometimes a tip cap is added.

What is heathcare PA-C or NP?

A PA is a Physician Assistant, the C means that a national certification exam was taken and passed. An NP is a Nurse Practitioner.

What ways can object oriented systems be considered cure to the software crisis?

It isn't clear what you mean by the "software crisis". The benefits of object oriented systems are usually in the re-use of code (not having to write the same type of code over and over again), which leads to a better ROI (return on investment).

This means you can leverage what you already have done to get a product to market faster.

How do you create Write a program that takes 10 integers as input The program will place these integers into an array and display the following 1. List in ascending order 2. mean 3. median 4.max val?

import java.util.Arrays;

import java.util.Scanner;

public class Answers {

public static void main(String[] args) {

//Creates a scanner object named console.

Scanner console = new Scanner(System.in);

//Variabels

int [] numbers = new int [10];

double avg = 0.0;

double median = 0.0;

int max = numbers[0];

double count = 0.0;

//User input.

for (int i = 0; i < numbers.length; i++){

System.out.print("Number: ");

numbers[i] = console.nextInt();

}

//break

System.out.println("===============");

//finds the average and max value.

for (int i = 0; i < numbers.length; i++){

count += numbers[i];

avg = count / numbers.length; //average

if (numbers[i] > max){ //finds the max value.

max = numbers[i];

}

}

median = (numbers[4] + numbers[5])/2; //Median value

//Display to user.

System.out.println("Highest value found: " + max); //Show maximum value found in array

System.out.printf("Median is: %.3f \n",median); //Show median

System.out.printf("Average is: %.3f \n",avg); //Show average

sortAsc(numbers); //Print out whole array ascending

}

//Method for sorting an Array ascending.

public static void sortAsc(int [] array){

for (int i = 0; i < array.length; i++){

Arrays.sort(array);

System.out.println(array[i]);

}

}

}

This should do everything you asked for, hope this helps!

1.difference between stack using arrays and queue using arrays and 2.difference between stack using linked list and queue using linked list?

Both questions really boil down to the difference between a stack and a queue, so let's deal with that first. A stack is used when you want a last-in, first-out collection (LIFO), like a stack of plates; the last plate you place on the stack is the first to come off the stack. A queue is a first-in, first out collection (FIFO); the first person in a queue is the first to be served.

Secondly, we would never use an array for a stack or a queue. Arrays must be resized dynamically, both to cater for new elements and to remove redundant elements. When catering for a new element, it may be necessary to reallocate the entire array because arrays must reside in contiguous memory. We can alleviate some of this burden by allocating more elements than we actually need, but this wastes precious memory unnecessarily. Alternatively, we can use a two-dimensional array to allocate non-contiguous blocks of memory (which is important when the array is large), but it still wastes memory unnecessarily.

Linked lists are the optimum model for both stacks and queues as the nodes need not reside in contiguous memory and memory can be allocated and deallocated on a per-node basis with minimum impact on performance and memory consumption. While it is true some additional memory is required per-node to cater for each node pointing to the next, there is no redundant memory. And while arrays do allow constant-time random access to any element, stacks and queues do not require random access.

The main feature of a stack is that we require constant time access to the head of the stack. Insertions and extractions are made only to the head of the stack, therefore we need only maintain one pointer to the head of the stack. When a new node is inserted, its next node points to the existing head of the stack (which may be NULL if the stack is empty), and then the head pointer points to the new node. When the head node is extracted, its next node (which may be NULL) becomes the new head pointer.

The main feature of a queue is that we require constant time access to both the head and the tail. Insertions occur at the tail and extractions at the head, therefore we need two pointers, one at the head node, the other at the tail node. Initially both point to NULL. When a new node is inserted and the tail is NULL, both the head and tail point to the new node, otherwise the tail node points to the new node and the new node becomes the tail. The tail node always points to NULL. Extracting the head node is the same as in a stack, except the tail node is set to NULL whenever the head is set to NULL.

To fully address the question, let's consider stacks and queues using arrays. We'll ignore the resizing issues simply by assuming that there are initially 10 unused elements, and whenever there are fewer than 5 unused elements the array will be resized by an extra 10 elements, and reduced by 10 elements whenever there are more than 15 unused elements. Thus there will always be at least 10 elements. There are better methods than this, but it will suffice for the purpose of this answer.

Since insertions at the start of the array would require us to copy all elements into the next element to make room for the insertion, all insertions will occur at the end of the array in the first unused element. Therefore we must maintain a zero-based index of the first unused element (the tail). When we insert an element at that index, the tail is simply incremented.

For the stack, extractions also occur at the tail. Therefore, if the tail is non-zero, we simply decrement the tail and extract the element at that index. If the tail is zero, the stack is empty. Otherwise the tail tells us how many elements have been used for resizing purposes. Resizing should be done after an insertion or extraction.

For the queue, extractions occur at the head, therefore we initially point at element zero. If the head and tail are different, an item exists at the head element so we extract it and increment the head. If the head and tail are the same, then there are no elements in use so both can be reset to zero. The only real complication is in working out how many unused elements there are for resizing purposes. For this we simply subtract the head from the tail to determine how many elements are in use. This should be done prior to any insertion. If a resize is required it would be prudent to shunt all used elements to the start of the array and adjust the head and tail accordingly, then perform the insertion.

As you can appreciate, a queue is more complex than a stack when using an array, but ultimately an array is more complex than a linked list for both stacks and queues.

What is the advantage of using functions and write a c program to explain about built-in functions with examples?

C does not have any built-in functions as such. The language allows the programmer to create functions or to include functions contained in external function libraries, but the language itself has no functions whatsoever. The C standard library is not considered built-in since programmers are free to ignore the standard library completely. However, the library contains highly efficient, optimised functions that are considered "general purpose" and therefore useful to the majority of programmers. The programmer can use these functions as the basis for more complex, more specialised functions.

The main advantage of functions is that they allow programmers to break programs down into a series of simple subroutines, each of which is handled by a function. Functions can call other functions, including themselves, and can be called as often as required. Although some code duplication is inevitable in any program, by placing duplicate code in a function, the programmer ensures that the code remains consistent. Since the function code is in one place, it is much easier to maintain that code, there is no need to make multiple changes across all duplicates, which is error prone and could introduce inconsistencies. Also, with well-named functions, code becomes self-documenting, making it easier to express ideas in code without the need for verbose comments within the code itself, which tends to be distracting rather than helpful.

Why you need a for loop when you have already while loop or do while loop?

We need a for loop because the while and do-while loops do not make use of a control variable. Although you can implement a counter inside a while or do-while loop, the use of a control variable is not as self-evident as it is in a for loop. Aside from the use of a control variable, a for loop is largely the same as a while loop. However, it is quite different to a do-while loop, which always executes at least one iteration of the loop before evaluating the conditional expression. In a for and while loop, the conditional expression is always evaluated before entering the loop, which may result in the loop not executing at all.

How do you draw a line using c garphics best site?

I presume you need a graphics package that you can use with C. Do some google searches (and remember to specify your OS) and pick the one you like the best.

What is the Visual C plus plus 2008 Express Serial Code?

The Express edition of C++ does not require a serial code. It is free.

Program for How do you find the missing number in sequential array?

#include<stdio.h> #include<conio.h> void main() { int a[5],i; int ele,temp=0,pos=0; clrscr(); printf("enter the array elements\n"); for (i=0; i<5; i++) scanf("%d",&a[i]); printf("Enter the element to be search\n"); scanf("%d",&ele); // searching for the element for (i=0; i<5; i++) { if (a[i]==ele) { temp=1; pos=i; } } if (temp==1) printf("Element found %d , position==%d",ele,pos); else printf("Element not found\n"); } // end of main()

Any Doubts Dharma....(dharma548@gmail.com)

What is the Algorithm to convert to RS to?

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

int r,d,t,code;

printf("enter your code 1 for rupees to dollar\n 2 for dollar to rupee");

scanf("%d",&code);

if(code==1)

{

printf("enter your amount");

scanf("%d",&r); d=r/(45);

printf("you have dollar %d",d);

}

elseif (code==2) { printf("enter your amount");

scanf("%d",&d); r=d*(45);

printf("you have rupees %d",r);

}

else printf("invalid code");

getch();

}

What pointer points to the next free element?

Presumably you are referring to the next unused element of an array. If your array contains unused elements then it is up to you, the programmer, to keep track of them. Typically you will do this by placing all unused elements at the end of the array. Knowing the array's overall capacity (in elements) and the number of elements that are currently in use, it is trivial to compute the address of the next free element; there is no need to maintain a separate pointer.

Perhaps you are referring to the (call) stack pointer. Call stacks are defined by the system. In 8086 architecture, the call stack is a fixed-length region of contiguous memory addresses allocated to a thread (every thread has its own call stack). The call stack extends downwards into lower memory addresses. The stack pointer (SP) register refers to the last element pushed onto the stack (the lowest used address). Note that it cannot possibly refer to the next unused element given that the length of an unused element cannot be determined until an element is actually pushed onto the stack. That is, if the element being pushed were 2 addresses (or bytes) in length, the SP will be decremented by 2 addresses and the new element will be placed at the new address. When we subsequently pop that element, the SP is simply incremented by 2 addresses.

What you create a file in c?

A file. Of course it wouldn't hurt if you asked questions that make sense.

Perhaps see if fopen() from stdio.h is what you're looking for.

Is C language readable?

No, but source-programs written in C language are.