How do you use qsort function to sort an array of structures?
It depends what language you are using and how the function is implemented. However, generally, you need to pass 4 arguments to the function:
1. A reference to the array.
2. The lower bound of the sub-array to be sorted (usually 0).
3. The upper bound of the sub-array to be sorted (usually n-1 for an array of n elements).
4. A binary predicate to perform comparisons between the elements (usually a less-than predicate).
How do you you delete a node in singly linked list only pointer to that node is given in C?
Firstly, thanks for trying solve this algorithm.
I will rewrite the wrong way and debug it in the next line, and the causes in th last line , O right?
wrong:void delete(int n).
debug:void delete_node(node* list, int n).
causes:
-You have to include the name of the list from which you want to delete a node. -you used delete as a name of the function, and that is impossible because delete is a predefined function, use delete_node for example.
wrong:you didn't affect the address of the list to the temporary pointer named here P.
debug:p=list.
causes:
-one of the disadvantages of the chained list -unlike contiguous list-is: to arrive to the the required node, we have to traverse all previous nodes to get the required one, therefor we use that temporary pointer, and this latter mast have to start from the first node names here list.
the rest is right, try this code, I think it works::
void delete_node(node *list, int n)
{
node *p;
p=list;
int i=1;
while(i
{
p=p->next;
++i;
}
node *q;
q=p->next;
p->next=q->next;
free(q);
}
Best regards of InfoMan.
C program to swap three variables?
#include<stdio.h>
#include<conio.h>
void main()
{
int a=2,b=3;
swap(a,b);
printf("%d%d",a,b);
getch()
}
swap(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
printf("%d%d",x,y);
}
How do you print 1 121 1331 14641 in c?
#include
#include
void main()
{
clrscr();
for (int i=1;i<=5;i++) // this for loop controls the line
{
for(int
j=1;j<=i;j++) // this for loop controls the values(1,12,123..)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
What are the 2 high level programming language?
BASIC , FORTRAN ,COBOL , PASCAL are high level lanhuages which are simply understood by us used in the computers.
What is the function of variable frequency drive?
The function of a frequency drive is to control the speed of an electric motor.
In general, a frequency drive converts the ac supply voltage into a dc voltage and then converts this dc voltage into a ac voltage of which the amplitude (voltage) and the frequency can be varied. Giving you the possibility to fully control the speed of the motor.
Applications: (big) ventilators, pumps, cranes, elevators and virtually all other applications where electric motors are used.
What is a simplex data communication mode?
One way data communication.
http://en.wikipedia.org/wiki/Simplex_communication
Parts of the program C plus plus?
parts of a program
Structure of C++ program
Documentation Section
Preprocessor Section
Definition Section
Global Declaration Section
main()
{
Declaration part;
Executable part;
}
sub program section
{
Sub program execution part
}
How do you draw a line using C graphics?
its very easy just include the graphics directory in your program...
out put a dot on the screen.... in loop like..
Horizontal line from point A(x1,y1) B(x2,y2) start to out put the point from x1,y1 and then evry next loop keep y1 the same and increment x1 by 1.
Thanks
There is one more function in graphic library of C++, that is line().
It has four arguments of int type.
line(starting x coordinate, starting y coordinate, end x coordinate, end y coordinate);
setlinestyle() and setlinecolor() can be used for different line colors and line styles.
The data types indicate the type of values that can be stored. The primary data types in c are:
1. int, short, long, long long - used for integer values
2. float, double - used for storing floating point numbers
3. char - used for storing ASCII characters
What is program in c to swap entered two numbers without using third variable?
The required c program is given below
/*Swapping(interchange) the two entered numbers*/
#include<stdio.h>
main()
{
/*Without using third variable*/
int a,b,t;
printf("Enter a:");
scanf("%d",&a);
printf("Enter b:");
scanf("%d",&b);
a=a+b;
b=a-b;
a=a-b;
printf("\n After swapping without using third variable");
printf("\na=%d\nb=%d",a,b);
}
What is the Program to find sum of natural number using recursion?
#include
int main(){
int i,sum=0;
for(i=1;i<=NUM;i++) //adding the numbers to sum, from 1 to NUM
sum+=i;
printf("SUM IS %d",sum); //printing the result
}
Program in c language to find sum of digits using recursion?
# include
void main()
{
int no,rem=0,sum=0,n; /*declaration*/
printf("Enter 2 digit number:");
scanf("%d",&no);
for(n=1;n<3;n++) /*conditions*/
{
rem=no%10; /*separation of digits using % and / */
sum=sum+rem;
no=no/10;
}
printf("sum=%d",sum);
}
What are the advantages of compiling a function separately?
So it can be run.
Answering from an alternative angle, compiling source code into an executable program creates a list of instructions that can be understood directly by the CPU of the computer without any extra tools.
The alternative being a script is a program which has to be read and interpreted by another program. This causes a major decrease in performance as the CPU had to run a program that will read the script character by character and perform a lot of lookup functions to perform the same tasks.
The in-between option is using a virtual machine language which produces a sort-of half compiled program. This is similar to LLVM, Java or the .NET CLR. All three options allow a program to be made smaller, can be run byte for byte or by an interpreter or can compile the code on the machine where it will be run. This is the ideal solution as the code can be compiled to run optimally on the end user's machine instead of trying to optimize code for all possible systems.
What is difference function prototype and function define in turbo c?
In C, a function prototype is a declaration to the compiler that a certain function exists, without a full definition. This allows other functions to call that function. The linker will later make sure that a function definition actually exists (perhaps somewhere else), and will turn the call to the function to a call to the correct function.
void display is the function name in which we want to perform some task or it might be to display something. But it has got its residence in the main() function that means that function's inputs are being supplied from the main(). void doesn't return anything so function call is made in main() which doesn't return anything back to it.
Write a C function to sort two dimensional integer array in ascending order?
Here's an example using a bubble sort. Note that this is not a very efficient sort, but it works weel enough with small data sets.
#include
#include
int main(void)
{
int item[100];
int a, b, t;
int count;
/* read in numbers */
printf("How many numbers? ");
scanf("%d", &count);
for(a = 0; a < count; a++)
scanf("%d", &item[a]);
/* now, sort them using a bubble sort */
for(a = 1; a < count; ++a)
for(b = count-1; b >= a; --b) {
/* compare adjacent elements */
if(item[ b - 1] > item[ b ]) {
/* exchange elements */
t = item[ b - 1];
item[ b - 1] = item[ b ];
item[ b ] = t;
}
}
/* display sorted list */
for(t=0; t
return 0;
}
How to print ASCII values using c?
Well in C++:
#include <iostream>
int main()
{
char x;
for(int i = 0; i < 255; i++)
{
x = i;
std::cout << i << "\t" << x << std::endl;
}
char wait;
std::cin >> wait;
return 0;
}
Define basic structure of c program?
Documentation section
link section
definition section
Global declaration section
main() function section
{
Declaration part
Executable part
}
subprogram section
(user defined function)
By jancy
Answer: Doesn't really have a structure, but there are some rules you have to follow:
- function-definitions cannot be nested;
- in a code-block, data declaration/definitions must come before the executable statements
There a program that uses both interpreted and compiled code?
Yes.EasyTreve Plus has both an interpreted and a compiled version available.
Examples of automatic variables in c?
Automatic variables are variables that are declared within the scope of a block, usually a function. They exist only within that scope, i.e. that block, and they cease to exist after the block is exited. These variables are usually allocated from the stack frame.
Example a program using two dimensional array multiplication table?
#include <stdio.h>
int main() {
int TimesTable[12][12] = { {1,2,3,4,5,6,7,8,9,10,11,12}, {1,2,3,4,5,6,7,8,9,10,11,12} };
int a, b;
for (a = 1; a <= 12; ++a) {
for (b = 1; b <= 12; ++b) {
TimesTable[a][b] = a*b;
printf("%5d", a*b);
}
printf("\n\n");
}
return 0;
}
How is object oriented programming language easier to use than procerdural programming language?
object oriented programing helps better modeling the world as we humans see it, while functional and procedural programming is for the mathematicians P.O.V. harder to maintain the code, and for me , harder to understand imperative(functional) code over side effect code(OOP) OOP is more intuitive by the grasp of the model to the mind, as it stands to help better model the mind, though most developers i have see so far, can really make a good simulation for the world in order for the code to be more coherent. OOP is Object Oriented Programming P.O.V is Point Of View