What is the minimum number of nodes in a full binary tree with depth 3?
A full binary tree of depth 3 has at least 4 nodes. That is; 1 root, 2 children and at least 1 grandchild. The maximum is 7 nodes (4 grandchildren).
How do you write a program for division of 2 values?
#include<stdio.h>main()
{
float x,y,d; //x&y are numbers &d is division
printf("Enter 2 numbers separated by space");
scanf("%f%f",&x,&y);
d=x/y;
printf("Answer is %f",d);
return 0;
}
When was the programming language C Sharp initially developed or released?
It was developed by Microsoft during 2000-01. A beta version was released in October 2001 and a full version was out in April 2002.
During the development of the .NET Framework, the class libraries were originally written using a managed code compiler system called Simple Managed C (SMC). In January 1999, Anders Hejlsberg formed a team to build a new language at the time called Cool, which stood for "C-like Object Oriented Language". Microsoft had considered keeping the name "Cool" as the final name of the language, but chose not to do so for trademark reasons. By the time the .NET project was publicly announced at the July 2000 Professional Developers Conference, the language had been renamed C#, and the class libraries and ASP.NET runtime had been ported to C#.
C# First Language specification was given on December 2001
and its First Version was released on January 2002
Write a programme in C to find the union and intersection of two sets?
#include<stdio.h>
#include<conio.h>
void Union(int set1[10],int set2[10],int m,int n);
void Intersection(int set1[10],int set2[10],int m,int n);
void main()
{
{
int a[10],b[10],m,n,i,j;
int ch;
clrscr();
printf("\nEnter the no of elements in first set:");
scanf("%d",&m);
printf("\nEnter the elements:");
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
printf("\nElement of First set:\n");
for(i=0;i<m;i++)
{
printf("\t%d",a[i]);
}
printf("\nEnter the no of elements in second set:");
scanf("%d",&n);
printf("\nEnter the elements:");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
}
printf("\nElement of second set\n");
for(i=0;i<n;i++)
{
printf("\t%d",b[i]);
}
while(1)
{
printf("\n\tMenu\n\n1.Union\n2.Intersection");
printf("\n3.exit");
printf("\nenter your choice:-");
scanf("%d",&ch);
switch(ch)
case 1:
union(a,b,m,n);
break;
case 2:
intersection(a,b,m,n);
break;
case 3:
exit(0);
}
getch();
}
}
void union(int a[10],int b[10],int m,int n)
{
int c[20],i,j,k=0,flag=0;
for(i=0;i<m;i++)
{
c[k]=a[i];
k++;
}
for(i=0;i<n;i++)
{
flag=0;
for(j=0;j<m;j++)
{
if(b[i]==c[j])
{
flag=1;
break;
}
}
if(flag==0)
{
c[k]=b[i];
k++;
}
}
printf("\nElement of resultant set\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
void intersection(int a[10],int b[10],int m,int n)
{
int c[20],i,j,k=0,flag=0;
for(i=0;i<m;i++)
{
flag=0;
for(j=0;j<n;j++)
{
if(a[i]==b[j])
{
flag=1;
break;
}
}
if(flag==1)
{
c[k]=a[i];
k++;
}
}
printf("\nElement of resultant set\n");
for(i=0;i<k;i++)
{
printf("\t%d",c[i]);
}
}
What are the first 20 numbers in Fibonacci's number sequence?
1 1 2 3 5
8 13 21 34 55
89 144 233 377 610
987 1597 2584 4181 6765
What is machine dependent assembler features?
1) Instruction format and addressing modes. 2) Relocation. For details refer "System Software By L.L.Beck" BY:: SUNIL SHARMA (sunil13982@gmail.com)
What is the algorithm to delete a child node in binary tree?
as far as i know u have 4 cases for the node u wanna delete
1.It's a leaf (has no children)
2.It has only left child
3.it has only right child
4.it has both children ,left and right
now, let's work on it :>
set a pointer node to the root
while the element to be deleted doesnt equal the pointer
if it's smaller, move the pointer to the left subtree
if it's large , move the pointer to the right subtree
if pointer reached the end of the tree , null, break the loop (unluckly that means u didnt find the element that should be removed)
end while //(now u must have found the target, the while condition is breaked normally)
// this is case 4
if both children don't equal null
get the most left node in the subtree of the pointer node
assign its value to the pointer node.
remove it (set that most left thing to equal null)
//...case 2
if pointer node.right only equals null
pointer node = pointer node.left
//...case3
if pointer node.left only equals null
pointer node = pointer node.right
//... case 1
if pointer node.left and .right equals null
pointer node.data = null
maybe it doesnt look like any algorithm style ,sorry for that, that's as far as i knw, i doubt case 4 anyways..
Why do you need to use comments in a C program?
Preferably as little as possible, however it depends on the language. Low-level languages require a vast amount of user-comments because it can be extremely difficult to read the logic from the code alone. High-level languages require very few comments because the code should be largely self-documenting. Languages like C++ allow you to express concepts and ideas directly in code, so there's very little you need to document with a comment. Choosing good names for functions, classes and variables is a vital aspect of creating readable code.
What are IF statement functions?
A statement and a function are two separate things. An if statement is a selection statement and has the following forms in C:
if (expression) {
statement;
}
if (expression) {
statement;
} else {
statement;
}
In the first form, the statement executes only when the expression evaluates true. In the second form, the first statement executes when the expression evaluates true, otherwise the second statement executes. The second statement may be another if statement (a nested if):
if (expression) { statement;
} else if (expression) {
statement;
} else {
statement;
}
Here, the second expression is only evaluated when the first expression evaluates false. If both expressions evaluate false, the final statement executes. Note that the final else clause is optional within nested if statements.
Nested ifs can often be thinly-disguised switch statements:
if (x==0) {
f(x);
} else if (x==1) {
g(x);
} else if (x==2) {
h(x);
} else {
i(x);
}
If statements of this type are best implemented using a switch statement:
switch (x) {
case 0: f(x); break;
case 1: g(x); break;
case 2: h(x); break;
default: i(x);
}
As well as being easier to read (and maintain), execution is more efficient as the control expression (x) need only be evaluated once and execution will immediately pass to the appropriate case label (much like a goto statement). With a nested if statement, each expression has to be evaluated in turn until one of them evaluates true, or execution passes to the else clause.
Switch statements are also more flexible in that the default clause need not be the final clause and execution automatically "falls through" to the next case label until a break or return statement is encountered.
How do you include a system header file called sysheader.h in a c source file?
There is no system header called share.h, but if there were, it would be:
#include <share.h>
What is a pointer variable in C?
Pointer variables point to data variables. They are mostly used to point to dynamically allocated data variables, but can actually point to anything (e.g. statically allocated variables, array elements, anywhere inside a variable, program machine code, I/O device descriptors, nonexistent memory). Misuse of pointer variables, either unintentionally or intentionally, is a major cause of nearly impossible to debug software problems in programs written in C (and C++).
How to write Program to swap two variables using function call by value?
//This program swaps the values in the variable using function containing reference arguments
#include<iostream.h>
void swap(int &iNum1, int &iNum2);
void main()
{
int iVar1, iVar2;
cout<<"Enter two numbers "<<endl;
cin>>iVar1;
cin>>iVar2;
swap(iVar1, iVar2);
cout<<"In main "<<iVar1<<" "<<iVar2<<endl;
}
void swap(int &iNum1, int &iNum2)
{
int iTemp;
iTemp = iNum1;
iNum1 = iNum2;
iNum2 = iTemp;
cout<<"In swap "<<iNum1<<" "<<iNum2<<endl;
}
Reference arguments are indicated by an ampersand (&) preceding the argument:
int &iNUm1;
the ampersand (&) indicates that iNum1 is an alias for iVar1 which is passed as an argument.
The function declaration must have an ampersand following the data type of the argument:
void swap(int &iNum1, int &iNum2)
The ampersand sign is not used during the function call:
swap(iVar1, iVar2);
The sample output is
Enter two numbers
12
24
In swap 24 12
In main 24 12
------------------------------------------------------------------
By Satish from here
/ * Program to Swap Two Numbers by Using Call By Reference Method * /
#include
main()
{
int i, j;
clrscr();
printf("Please Enter the First Number in A : ");
scanf("%d",&i);
printf("\nPlease Enter the Second Number in B : ");
scanf("%d",&j);
swapr(&i,&j); /* call by reference*/
printf("A is now in B : %d",i);
printf("B is now in A : %d",j);
}
/* call by reference function*/
swapr(int *x, int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}
Why you use class keyword in c?
You may use it as an identifier, because it is not a reserved word in C.
What is statement terminator in c language?
The compiler demands it: your programs wouldn't compile without them.
Explain pointer with the help of an example?
Pointers are data types that hold integer values, those "integer" values are simply addresses of another variables.
Example:
int x = 15; // this is an integer variable with value 15
int* ptr; // this is a pointer to an integer
ptr = &x; // now we assigned the address of x to the pointer ptr
// if you want to access the value of x (15 in this example),
// you should use the deterrence *
// so you can say:
printf("%d", *ptr); // this will print 15
// you can print the value of ptr (which is the address of x) using:
printf("%p", ptr); // this will print an integer, which is the address of x.
==========================================================
More explanation, let's imagine that this is a memory:
-00--01-02-03-04 =====> these are the address of the memory
|--- |--- |---|---|---| =====> values inside the memory
For the example I gave before, let's imagine the following:
-00-01-02--03--04
|---|15|--- | 01 |---|
------x------- ptr
As you can see, x hold the value 15, ptr holds the value 01 which is actually the address of x. Now ptr have a distinct address too, which is 03.
In reality, the address of a memory is longer, and usually represented as hexadecimal values. example 0x002154
You can find more information here:
http://en.wikipedia.org/wiki/Pointers
Structure declaration syntax:
struct tag_name
{
data_type member1;
data_type member2;
_______________________
_______________________
data_type membern;
};
A public class is a base class declared with public inheritance:
class base {
// ...
};
class derived : public base {
// ...
};
In the above example, base is a public class of derived, thus derived is regarded as being a type of base. The derived class inherits all the public and protected methods of its base. Protected methods are accessible to the derived class, its derivatives and their friends.
If base were declared protected, its public methods become protected methods of derived. The base class is then an implementation detail of derived; only members of derived, its derivatives and their friends can treat derived as being a type of base.
If declared private, the public and protected methods of base become private methods of derived. The base class is then an implementation detail of derived; only members of derived and its friends can treat derived as a type of base.
How do you do the summation of two matrix in c language?
#include
void f1(int a[]);
int a1[2][2],a2[2][2];
int i,j;
void main()
{
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("enter a1[%d] [%d]\t",i,j);
scanf("%d",&a1[i][j]);
}
printf("\n");
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("enter a2[%d] [%d]\t",i,j);
scanf("%d",&a2[i][j]);
}
printf("\n");
}
f1(a);
}
void f1(int a[])
{
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("therefor the result is: %d%d\t",a1[i][j]+a2[i][j]);
}
printf("\n");
}
}
In c plus plus what is the purpose of the keyword public and private in the definition of a class?
Public members/functions can be accessed from outside the class, private members/functions can only be accessed from functions of that class.
Ex.
class sampleClass{
private int value;
public void setValue(int a){value = a;} /* legal, value can be accessed since this is a method within the same class */
public int getValue(){return value;}
};
int main()
{
sampleClass sc; // class is instantiated
sc.setValue(5); // legal, setValue() is public
sc.value = 7; // ERROR, value is private, will not compile
printf("%d\n", sc.getValue()); // Will print 5
return 0;
}
Write a C programme for arithmetic operations using menu driven?
#include<stdio.h>
void main()
{
int num1, num2,res;
char ch;
printf("\n Enter the 1st operand");
scanf("%d",&num1);
printf("\n Enter the operator");
scanf("%c",&ch);
printf("\n Enter the 2nd operand");
scanf("%d",&num2);
switch(ch)
{
case '+' :res=num1+num2; break;
case '-' :res=num1-num2; break;
case '*' :res=num1*num2; break;
case '/' :res=num1/num2; break;
}
printf("\n The result of %d %d %d is =%d",num1,ch,num2,res);
}
Write a C programme to find out sum of the array elements?
main()
{
int n,a[i],s;
s=0;
printf("enter no of elements in array");
scanf("%d",&n);
printf("Enter elements in array");
for(i=;i
scanf("%d",&a[i]);
s+=a[i];
}
printf("sum of elements=%d",s);
return;
}
What is Volatile in c language?
'int' is the type, 'volatile' warns the compiler, that the value might be changed asynchronousy, so it mustn't be optimized (e.g. cached in register.)
Can you give a C plus plus program about FCFS algorithm?
#include<iostream.h>
#include<conio.h>
#include<alloc.h>
#include<stdio.h>
struct node
{
char name[10];
int bt;
int wt;
int tat;
struct node*next;
};
typedef struct node n;
n *start=NULL;
void main()
{
int i,m;
n *p,*temp,*t;
clrscr();
cout<<"\nEnter the number of Process:";
cin>>m;
for(i=0;i<m;i++)
{
p=(n*)malloc(sizeof (n));
cout<<"\n\tEnter the Process Name:";
cin>>p->name;
cout<<"\n\tEnter the Burst Time:";
cin>>p->bt;
if(start==NULL)
{
start=p;
start->next=NULL;
start->wt=0;
start->tat=start->bt;
}
else
{
temp=start;
while(temp!=NULL)
{
t=temp;
temp=temp->next;
}
t->next=p;
temp=p;
temp->wt=t->tat;
temp->tat=t->tat+temp->bt;
temp->next=NULL;
}
}
temp=start;
cout<<"\nProcesses\t\tBT\t\tWT\t\tTAT";
while(temp!=NULL)
{
cout<<"\n\t"<<temp->name;
cout<<"\t\t"<<temp->bt;
cout<<"\t\t"<<temp->wt;
cout<<"\t\t"<<temp->tat;
temp=temp->next;
}
cout<<"\n\n Created By:\n\tSanjog";
getch();
}
What is the latest compiler of C plus plus compiler?
C++ compilers are many and varied. There is no single "latest compiler" because every IDE implements their own version according to the current C++ standard. However some (Microsoft in particular) do not fully adhere to the C++ standard.
The "latest compiler" for your IDE is either provided as an interim update to the IDE, or by upgrading the IDE to the latest version.
What is static extern variables in C?
Basically storage class defines the accessibity of a variable. If you specify a variable with auto storage class, then that variable can be accessed only in that function or block where it is declared. if you specify a variable with static storage class, it has the same visibily like an auto variable but it can retains it's value between function calls where as an auto variable cannot. look at this example: void main() { int i,j ;
for(j = 0; j< =2; j++) { i = fun1(); printf("%d",i); } } int fun1() { static int k =0; k = k+1; return k; } it prints 1 2 3