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 convert hexadecimal to decimal numbers?

write an assembly language program to implement a stack. START: LXI SP,STACK ;initialize stack pointer

LXI H,BINBYT ;point HL index to where binary number is stored

MOV A,M ;transfer byte

LXI H,OUTBUF ;point HL index to output-buffer memory

CALL BINBCD

HLT BINBCD:

MVI B,100 ;load 100 into register B (power of ten holding register)

CALL BCD ;call conversion for BCD3

MVI B,10 ;load 10 into register B

CALL BCD ;call conversion for BCD2

MOV M,A ;store BCD1

RET

Algorithm in creating insert method in linked list?

You sort a doubly linked list the same way you sort any other kind of list or array.

You implement a procedure to sort the list or array, and that procedure calls the appropriate insert, delete, or move methods of the list or array.

How do you find the diameter of a length of string?

You use the diameter formular. You know, C=pi(d).

If you know the cicumference, then you use this equation, d=c/pi.

You subsitute the cimcumference and divide (pi=3.14), and that's how you calculate dimater. Oh yeah, and if your given the radius of the circle, just multiply it by two.Type your answer here...

What is a member of a primitive or uncivilised people?

They once were known as savages, but the term has been lately used to descibe anyone with barbaric tendencies.

What is pointer variable range?

The range of a pointer variable is the range of addressable memory. For a 32-bit system there are 2^32 addresses ranging from 0x0 to 0xffffffff. Address 0x0 is a reserved address and is used to indicate a pointer refers to no object in particular (points to null).

Depending on the word-alignment requirements of the architecture, certain addresses may be deemed invalid for a given type. For instance, a 4-byte integer is generally faster to access if it is aligned upon a 4-byte boundary.

What is significance attached to the main function in C programming?

The main function in C++ is no different to any other function, other than it is the only required function; it defines the entry point of the application. The minimal main function (and therefore the minimal C++ program) is:

#include <stdio.h>

int main()

{

return(0);

}

The main function must always return an integer to the caller (even if not required by the caller). A return value of zero is usually used to indicate the program terminated successfully, however it is up to the programmer to decide what the return value actually means to the caller. It is common to return (-1) upon an unrecoverable error.

C program to calculate area of circle?

/*to find the area of a circle*/

#include<stdio.h> #include<conio.h> main()

{

int r;

float a;

print f ("Enter r value \n");

scan f ("%d", &r);

a=3.14*r*r;

print f("area=%f",a);

}

How do you write a program in VB to compare three number and print larger number?

' Return the maximum of a,b,c

Function max(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) As Integer

Dim maxAB As Integer

maxAB = Math.Max(a, b)

Return Math.Max(maxAB, c)

End Function

2 Write an algorithm to print the factorial of a given number?

include<stdio.h>

main()

{

int n,fact=1;

clrscr();

printf("enter a no");

scanf("%d",&n);

while(n>0)

{

fact=fact*n;

n--;

}

printf("the factorial of given no is %d",fact);

getch();

}

What is meant by the storage class of a variable?

auto, extern, static, register, typedef (only formally)

C program asking to enter string?

its simple in c and c++: mainly it depends on what type of answer ur looking track fro the user .. if its a numeric u can define a integer or float variable else a string variable to store characters . ex : printf("\n whats ur age ?"); scanf("%d",&age); printf("\n hey ur %d years old :",age); cout

What is mean by robust language in c language?

Robust means strong enough to withstand or overcome intellectual challenges or adversity.

c is a robust language because its rich set of built-in functions and operators can be used to write any complex logic program.

How do you calculate the time complexity of selection sort?

Suppose (for simplicity) that n = 2k for some entire k. Let T(n) the time used to sort n elements. As we can perform separation and merging in linear time, it takes cn time to perform these two steps, for some constant c. So, T(n) = 2T(n/2) + cn.

In the same way:

T(n/2) = 2T(n/4) + cn/2, so

T(n) = 4T(n/4) + 2cn. Going in this way ... T(n) = 2mT(n/2m) + mcn, and

T(n) = 2kT(n/2k) + kcn = nT(1) + cnlog2n = O(n log n). Remember, as n=2k k = log2n! The general case requires a bit more work, but it takes O(n log n) time anyway.

Code for first fit algorithm in C?

#include <stdio.h>

#include <conio.h> //function to print the bins:

void printBins(float bins [500] [500],int items )

{

for (int j=1;j<=items;j++)

{

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

{

printf(" %1.3f",bins[i][j]);

}

printf("\n");

}

} int main()

{

int items, x=1,c=1, i=0, j=1, countOfBins=1;

float z,sum=0 ,inputitems[500], bin[500][500]; printf("Enter the number of items:");

scanf("%d", &items); //scanning how many elements the user wants to enter

if (items<=0)

{

printf("Can't bin-pack on zero elements");

getch();

}

else

{

do{

printf("\nEnter item number %d: ",x);

scanf ("%f",&z); //scanning the elements the user inputs if ((z<0)(z>1)) //assuming my bins range from 0 to 1 only

{

printf ("\nitem number %d is not in range of 0 to 1",x);

goto stop;

}

else //if all the inputs were in the correct range

{

inputitems[x]=z; //save my elements in an array called inputitems

x++;

}

}while (x<=items); //end of do-while statement

//technique number 1:

printf ("\nIn Next Fit online technique:");

loop:

while (c<=items)

{

if (sum+inputitems[c]<=1) //to check if you have any more room to fit in the bin

{

i++; //assuming that each row represents a bin

bin[i][j]=inputitems[c]; //place element from inputitems array into a 2D array called bin

sum += inputitems[c];

c++;

goto loop; //go back to the while statement to check condition

}

else

{

j++;

countOfBins++; //to count the number of bins we used

i=1;

sum=0;

bin[i][j]=inputitems[c];

sum += inputitems[c];

c++;

goto loop;

} } //end of while loop printf("\nNumber of bins used: %d \n", countOfBins);

printf("\nstructure of bin\n(FYI any empty rows shown, are equal to the number of items that you have entered)\n");

printBins(bin,items);//to print the bins used with their elements //end of first technique, can;t stop: getch();

}//end of very first else }//end of main //I could not figure out any of the other 4 techniques of Bin Packing... any help please?

Write a c program to print fibonacci series using do while loop?

#include<iostream>

using namespace std;

#define MIN 1

#define MAX 1000000

int main()

{

int num;

char c;

do

{

cout << "Enter a number from " << MIN << "-" << MAX << " (0 to quit): ";

cin >> num;

while(cin.fail() num < 0 num > MAX)

{

if( cin.fail() )

{

cin.clear();

cin >> c;

}

cout << "Invalid number, try again: ";

cin >> num;

}

if(num)

{

cout << "\nFibbonacci series for n, where 1 <= n <= " << num << ":\n\n";

int n = 1, x = 0, y = 0;

do

{

cout << n;

x = y;

y = n;

n = x + y;

if( n < num )

cout << ", ";

}while( n < num );

cout << endl << endl;

}

}while( num );

return( 0 );

}

What is return a void data type?

#include<stdio.h>

int main(){

int num,i,f,r,sum=0,temp;

printf("Enter a number: ");

scanf("%d",&num);

temp=num;

while(num){

i=1,f=1;

r=num%10;

while(i<=r){

f=f*i;

i++;

}

sum=sum+f;

num=num/10;

}

if(sum==temp)

printf("%d is a strong number",temp);

else

printf("%d is not a strong number",temp);

return 0;

}

Why getch function has semicolen?

Without the semi-colon, getch is just an expression, not a statement.

What are the applications of merge sort?

Applications of heap sort

  • One of the biggest application of heap sort is constructing a priority queue basic idea is that, we want to know the tasks that carry the highest priority, given a large number of things to do. and this is exactly how heap sort works.
  • Another application is interval scheduling. we may have a list of tasks with certain start and finish times and we want to do as many of these tasks as possible in a given period of time. in order to sort the finish time efficient algorithm to use is heap sort .
  • In essence application or algorithm that involves sorting a list of elements will rely heavily on an efficient sorting algorithm and heap sort can provide such a function.

Is C a pure Object Oriented Programming Language?

High. Only machine code and Assembly are low level languages.

The distinction most usually used to determine if a language is 'high' or 'low' is the use of a compiler. If a language requires some form of compilation or translation process to convert each written instruction into multiple machine executable instructions then it is a high-level language. If each written instruction can be directly converted to a single machine executable instruction (and usually back again) then it is low-level.

Comment statement of BASIC programming language?

In original Standard BASIC comments were indicated by a "REM" (short for "REMARK") statement.

So, if "REM" was the first characters on a line, the rest of the line was treated as a comment and ignored by the interpreter or compiler.

Later dialects of "Structured" Basic use exclamation points (!) or single quotes (') to indicate the start of a comment

Some dialects require the exclamation point or single quote to be the first character on the line, others allow them to appear later in the line after executable code.

Most dialects still support the REM notation as well.

Write a program to fill the enter screen with a smiling face the smiling face has an ASCII value 1?

#include<stdio.h>

#include<conio.h>

void main()

{

int a=1;

clrscr();

for(a=1;a<=47*(80);a++)

{

printf("%c",1);

}

getch();

}

What is a double ended queue?

A double ended queue, or deque, is a queue in which you can access or modify both the head and the tail. The front pointer can be used for insertion (apart from its usual operation i.e. deletion) and rear pointer can be used for deletion (apart from its usual operation i.e. insertion)

What is the difference between auto storage class and register storage class?

register behaves like auto class but auto variables are actually local variables.They are created when the functions are created but they are destroyed when the fns is exited.But register-variables are used to speed up the operations

Differences between scope and visibility of a variable?

Scope of a variable is the lines of code from which it can be seen and/or manipulated. Scope can be thought of as visibility, because a variable's scope is where it is visible from.

A variable declared within a function (or any block, for that matter) has scope only within that block. It is visible within that block, and from within any contained block, but not from within any containing (outer) blocks. However, it should be noted that if a variable's name is reused in a nested declaration, then the outer variable loses scope within that block. As a result, you can reuse, for instance, the variable "i" within a new block without compromising any use outside that block.

What are advantages and disadvantages of linear search?

1)in linear search it needs more space and time complexity.

2) in linear search if the key element is the last element and the search is from first element that is a worst case, or if the key element is the first element and the search is from last element then also is the worst case.