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

Write a program to generate the Fibonacci series using non-recursive method?

In c:

int fibr(int n) { // Find nth Fibonacci number using recursion.

if (n<=2) return 1; // the first two Fibonacci numbers are 1 and 1

return (fibr(n-2)+fibr(n-1));

}

int fibi(int n) { // Find nth Fibonacci number using iteration.

int temp,last=1,f=1;

int i;

for (i=3;i<n;++i) { // the first two Fibonacci numbers are 1 and 1

temp=f;

f+=last;

last=temp;

}

return f;

}

Algorithm for infix to prefix conversion?

Algorithm to Convert Infix to Prefix Form

Suppose A is an arithmetic expression written in infix form. The algorithm finds equivalent prefix expression B.

Step 1. Push ")" onto STACK, and add "(" to end of the A

Step 2. Scan A from right to left and repeat step 3 to 6 for each element of A until the STACK is empty

Step 3. If an operand is encountered add it to B

Step 4. If a right parenthesis is encountered push it onto STACK

Step 5. If an operator is encountered then:

a. Repeatedly pop from STACK and add to B each operator (on the top of STACK) which has same or higher precedence than the operator.

b. Add operator to STACK

Step 6. If left parenthesis is encontered then

a. Repeatedly pop from the STACK and add to B (each operator on top of stack until a left parenthesis is encounterd)

b. Remove the left parenthesis

Step 7. Exit

Write a program to Print pyramid of numbers using loops in c?

#include <stdio.h>

#include <conio.h>

void main()

{

int height, line, i;

clrscr();

scanf("%d", &height);

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

printf(" ");

printf("1\n");

for (line = 1; line < height; ++line)

{

for (i = 0; i < height - line - 1; ++i)

printf(" ");

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

printf("%d", line + 1);

printf(" ");

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

printf("%d", line + 1);

printf("\n");

}

getch();

}

Why are the array and linked list used as stack queue and others?

Arrays are beneficial whenever you need constant-time, random-access to any element within a set of data and the number of elements doesn't change too much (enlarging an array may require the entire array be copied to a larger block of free memory, which is expensive in terms of performance). Linked lists are beneficial when the number of elements is highly variable and you also need constant time access to the head (as per a stack) or both the head and tail (as per a queue). Neither a queue nor a stack requires any traversal whatsoever, so the lack of random access is immaterial. If a set of data is variable and must remain in sorted order (such as a priority queue), then a heap or self-balancing binary tree is the most efficient structure to use.

What are the advantages and disadvantages of arrays in c sharp?

Advantages:

1. Can store "n" number of same data types in different indexes

2. Can be accesses using reference.

Disadvantage:

1. No boundary check, if the array boundary is crossed run time

2. No facility to increase the size of array in Run time

How do you determine the size of an array of int passed to a method?

It really depends on the language. In Java, you can use the .length property.

Can you return multiple values from a function in C?

There are many approaches to this 'problem'. Since a C function is only allowed to return one value as the name of the function you have to provide parameters to the routine if you want multiple values to be returned.

For example, traditionally you return a value thus:

int Today () ;

if (Today() == 2) ....

int Today ()
{
/* Some logic */
return value ;
}


So if you want multiple values, send parameters to the routine that can be changed:

int Today (int * val1, int * val2, char * charValue) ;


Then, call it:

int first ;
int second ;
char third ;

if (Today (&first, &second, &third) == 2)

In this case first, second, and third can be changed inside the Today routine and return multiple values.

int Today (int * val1, int * val2, char * charValue)
{
*val1 = 5 ;
*val2 = 10 ;
*charValue = 'Y' ;
return 2 ;
}

Why there is a need for converting high level language into machine level language............ why cant we use high level language directly in computers?

Machine code is the native language of the machine. The machine does not "understand" any language other than its own native language. As such, all other languages, including low level assembly languages, must be compiled or interpreted in order to produce the required machine code.

Program in C to find root using bisection method?

#include

#include

#include

#define fn(x) (x*x*x-3*x*x-x+9)

void main()

{

clrscr();

float x,a,b,y,y1,y2;

cout<<"enter the initial value a&b"<

cin>>a>>b;

y1=fn(a);

y2=fn(b);

if(y1*y2>0)

{

cout<<"invalid interval"<

}

do

{

x=(a+b)/2;

y=fn(x);

if(y1*y<0)

{

b=x;

y2=y;

}

else

{

a=x;

y1=y;

}

}

while(fabs(b-a)>.001);

cout<<"the root of the equation ="<

getch();

}

Which application developed by c?

All kinds of machine-based programs can be developed in C, including: operating system kernels; low-level drivers; embedded systems software; client-server applications; general purpose applications; utilities; and games. There is no real limit to what you can develop in C. The question is really about whether C is the best choice for the type of software you wish to develop. For purely low-level development it is ideal, but for mid-level to high-level developments you'd be better off with C++. Where performance and memory are not a major issue, Java is better for application development.

What type of loop uses a boolean expression?

A "while" loop is appropriate in this case - one in which the condition is evaluated at the beginning of the loop.

What are arrays?

  • Array data structure, an arrangement of items at equally spaced addresses in computer memory
  • Array data type, used in a programming language to specify a variable that can be indexed
  • Associative array, an abstract data structure model that generalizes arrays to arbitrary indices

or various kinds of the above, such as

  • Bit array or bit vector
  • Dynamic array, allocated at run time
  • Parallel array of records, with each field stored as a separate array
  • Sparse array, with most elements omitted, to store a sparse matrix
  • Variable-length array
  • Ragged (jagged) array, where the rows have different lengths individually

or various related concepts:

  • Array processor, a computer to process arrays of data (not to be confused with a processor array)
  • Array programming, using matrix algebra notation in programs (not the same as array processing)
  • Array slicing, the extraction of sub-arrays of an array
  • APL (programming language)

or also:

  • Video Graphics Array (VGA), a display adapter and video format, and many variants thereof (EVGA, FWVGA, QVGA, QXGA, SVGA, SXGA, SXGA+, TXGA, UVGA, XGA, XGA+, ...)

What is the difference between a constant and a variable in java programming language?

A constant in Java is defined using the "final" modifier. For instance:

final double Density_Of_Water = 1.000;

would set Density_Of_Water to 1.000. This value can not be modified throughout the program because "final" told the compiler that this value would not change. A variable however, can be changed by the user throughout the program.

Write a program for scrolling a text in status bar using JScript?

Wrote this a few years ago, just paste it in the head or import it from a js file.

pretty self explanatory

<script language="JavaScript">

//Author: fjhdehoog

//Scriptname: Slide in status

var MyStatus='This is an example of how to use javascript to make a scrolling status text';

var start_status=1000; //start in 1 sec

var TBD=100; //Time Btween Digits 1000 = 1 Sec

var LoopIt=1; // 0= dont loop -- 1= loop

var DFSF=10000; //Display full status for 10 Sec /*------------------------------------------*/

setTimeout('ScrollStatus()',start_status); //comment this line out if u want to use body onload or window.onload

CurNum=MyStatus.length;

function ScrollStatus(){

window.status=MyStatus.substring(CurNum);

if (CurNum!=0) {

CurNum--;

setTimeout('ScrollStatus()',TBD); }

else

{

if (LoopIt) {CurNum=MyStatus.length;

setTimeout('ScrollStatus()',DFSF);} else { /*do Nothing*/ } } }

</script>

How do you make computer virus using c language?

Computer viruses can be written in any programming language, not just C. C would be a common language for a virus to be written in because C is fast, and allows viruses to directly access lower level functions like computer memory. C has also been a very popular language for many programs in the past, so those who decide to write a computer virus would be familiar with that language already.

How do you find the greatest of two numbers without using the if-else comparison operators?

By subtracting any two of the numbers A-B , if the output number is negative , B IS GREAT and if its positive A is great

What is the expansion of conio.h?

EXPANSION OF CONIO.H

Conio.h library in C implies a console version which encapsulates the common I/O functions.

Console input/output header

How do pointer work in c program?

Pointer can be defined as variable that is used to store memory address , usually the location another variable in memory. Pointers provide a means through which memory location of a variable can be directly accessed.

Why isn't main a keyword in c?

Neither is printf, stderr or NULL. Certainly, they are important words, but not keywords.

C plus plus program for 1223334444..?

int n, i;

for(n = 1; n <= 5; ++n) {

for(i = 1; i <= n; ++i) { printf("%d", n);

}

}

When using a For loop what happens when the loop variable is equal to the final value?

That would depend on how exactly you define the three parts of the for loop. A typical for loop, equivalent to "for i = 1 to 10" in other languages, would look like this:

for (int i = 1; i <= 10; i++)
{
...
}

If you change this to:

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

then the code would still execute once.

What is program documentation?

Program documentation is an essential part of any computer program or application. The documentation specifies what each part of the code does, what events will be triggered during the course of the program, and makes sure that no part of the program is accidentally left off the interface or code.

What is the real world example for linked list?

If you are referring to the Linked Lists used in programming:

You can use the Linked lists you learn in c++ (for example) to define actual shapes in OpenGL (a graphics library), then just 'call' the shapes and apply transformations to them (moving them around, rotating, etc).

This method saves a lot of bandwidth between your CPU and video card as the shapes are defined already.

Hopes this answers your question