What is algorithm and what are its characteristics?
An "algorithm" is simply a method to solve a certain problem. For example, when you use the standard method you learned in school to write down two numbers, one beneath the other, then add them, you are using an algorithm - a method that is known to give correct results in this particular case.
How do you get Pseudo code for largest element of an array?
Pseudocode: if x > y then return x else return y
Actual code (C++):
return( x>y ? x : y );
What is the purpose of including 'iostream.h' in each C program?
It is not anecessary to inlcude iostream in every C++ program, if you are using any Input stream (e.g. cin>>) ot Output stream (e.g. cout<<) functionality, then it's mandatory to include iostream
What is getchar function in c?
getc(FILE *stream), prototyped in stdio.h, reads the next character from stream and returns it, or returns EOF if an error occurs or end of file has been reached.
getch(), prototyped in both conio.h and curses.h, performs a blocking-style hardware-based read of the keyboard. If no key is available, by default getch()will wait until a key is available. Options or functions usually exist to check to see if a key is available in the system keyboard buffer.
getchar() is the same as getc(stdin).
More information is available at the related links below, which apply to both Win32 and Linux/Posix systems.
How is the stack and stack pointer work?
A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Stack pointer is the pointer that points to the top of the stack or that points the item at the top of the stack and help in adding or deleting the item from the top of stack.
What is the distance between a anti node and adjacent node?
A node (knot) is a point along a standing wave where the wave has minimal amplitude.
The opposite of a node is an anti-node, a point where the amplitude of the standing wave is a maximum.
These occur midway between the nodes.
There are a few different ways to do this but this one will work just fine for your problem. (note these numbers are not truly random, but they will probably be random enough for your purposes)
you will have to:
import java.util.Random;
then define a new random number generator called Generator:
Random generator = new Random(); Then, make a random integer between 0 and 40 and subtract 20 so it is between -20 and positive 20. int myNumber = generator.nextInt(40) - 20;
Can you please tell me the c program to print the following pattern... 1 123 12345 1234567?
This was checked for C++ using VS2008.
#include
using std::cin;
using std::cout;
using std::endl;
int main()
{
cout << endl << "Enter of digits in the last number of the patter "
<< endl << "(should be odd number, if you enter even number N," << endl << "the answer will have N - 1 digits in the last number): ";
int numElem = 0;
cin >> numElem;
cout << endl << "Pattern:" << endl;
for (int i = 1; i <= numElem; i += 2)
{
for (int j = 1; j <= i; j++)
{
cout << j;
}
cout << endl;
}
system("PAUSE");
return 0;
}
For just C you might want to use something like (not tested):
#include
int main()
{
cout << endl << "Enter of digits in the last number of the patter "
<< endl << "(should be odd number, if you enter even number N,"
<< endl << "the answer will have N - 1 digits in the last number): ";
int numElem = 0;
cin >> numElem;
cout << endl << "Pattern:" << endl;
for (int i = 1; i <= numElem; i += 2)
{
for (int j = 1; j <= i; j++)
{
cout << j;
}
cout << endl;
}
system("PAUSE");
return 0;
}
Explain in detail the basic organization of computer with neat diagram?
The basic organisation of computer includes, 1.Control Unit
2.Central Processing Unit
a)Control Unit
b)Arithmetic and Logical Unit
c)Memory Unit
*Primary Storage
*Secondary Storage
3.Output Unit
Calculate determinants of a nxn matrix in C programming?
from:
http://local.wasp.uwa.edu.au/~pbourke/other/determinant/
/*
Recursive definition of determinate using expansion by minors.
*/
double Determinant(double **a,int n)
{
int i,j,j1,j2;
double det = 0;
double **m = NULL;
if (n < 1) { /* Error */
} else if (n j1)
continue;
m[i-1][j2] = a[i][j];
j2++;
}
}
det += pow(-1.0,1.0+j1+1.0) * a[0][j1] * Determinant(m,n-1);
for (i=0;i<n-1;i++)
free(m[i]);
free(m);
}
}
return(det);
}
//New Answer By Shaikh SOHIAL Hussain form PAKISTAN
#include<stdio.h>
#include<conio.h>
void main ()
{ clrscr();
int a[10][10],row,i=0,j=0,result,w,x,y,z;
printf("This Program made 4 solve matrix determintae\n");
scanf("%d",&row);
while(i<row)
{printf("\n");
for(j=0;j<row;j++)
{ printf("Enter the value of %d%d\n",i,j);
scanf("%d",&a[i][j]);
}
i++;
}
i=0;
while(i<row)
{ printf("\n");
j=0; while( j<row)
{printf("%d",a[i][j]);
printf(" ");printf(" ");
j++;}
i++;
}
if(row==2)
{
result=(a[0][0]*a[1][1])-(a[0][1]*a[1][0]);
printf("The answer is\t %d",result);
}
else if(row==3)
{ result=(a[0][0]*((a[1][1]*a[2][2])-(a[1][2]*a[2][1]))) - (a[0][1]*((a[1][0]*a[2][2])-(a[1][2]*a[2][0]))) + (a[0][2]*((a[1][0]*a[2][1])-(a[1][1]*a[2][0])));
printf("\nThe answer is \t %d",result);
}
else if(row==4)
{
w=a[0][0]*(a[1][1]*(a[2][2]*a[3][3]-a[2][3]*a[3][2])-a[1][2]*(a[2][1]*a[3][3]-a[2][3]*a[3][1])+a[1][3]*(a[2][1]*a[3][2]-a[2][2]*a[3][1]));
x=a[0][1]*(a[1][0]*(a[2][2]*a[3][3]-a[2][3]*a[3][2])-a[1][2]*(a[2][0]*a[3][3]-a[2][3]*a[3][0])+a[1][3]*(a[2][0]*a[3][2]-a[2][2]*a[3][0]));
y=a[0][2]*(a[1][0]*(a[2][1]*a[3][3]-a[2][3]*a[3][1])-a[1][1]*(a[2][0]*a[3][3]-a[2][3]*a[3][0])+a[1][3]*(a[2][0]*a[3][1]-a[2][1]*a[3][0]));
z=a[0][3]*(a[1][0]*(a[2][1]*a[3][2]-a[2][2]*a[3][1])-a[1][1]*(a[2][0]*a[3][2]-a[2][2]*a[3][0])+a[1][2]*(a[2][0]*a[3][1]-a[2][1]*a[3][0]));
result=w-x+y-z;
printf("\n The answer is \t %d", result);
}
else{ printf("Determinate Limit is 4*4 max\n");
getch();
}
Program to find employee details using structure in c?
#include<stdio.h>
#include<conio.h>
struct employee
{
char name[100];
int age,salary;
};
void main()
{
struct employee details;
clrscr();
printf("\n the name of the employee is ... \n the age of the employee is... \n the salary acquired is...");
scanf("%c%d%d",&details.name,&details.age,&details.salary);
clrscr();
printf("\n the name is... \n the age is... \n the salary is...",details.name,details.age,details.salary);
getch();
}
How do you function help to reduce the size of program in C?
Functions reduce code size in one of three ways, depending on the complexity of the function.
Normally, a function call results in the compiler generating code to call and return from the function, but the code for the function itself is only generated once. This not only reduces duplication in your source code and thus makes your code much easier to read and maintain, it also reduces the overall size of the machine code if the code required to implement the call and return mechanism results in fewer operations than the function itself. However, the call and return mechanism has a runtime cost, reducing performance slightly.
Some functions can be inline expanded (by the compiler) to the extent that the expansion results in smaller code than the normal call and return mechanism would incur. By eliminating the function call mechanism, we not only improve runtime performance, we can also reduce code size.
Inline expansion does not guarantee smaller code size; in some cases we may increase the size of the code. Although increased code size can have an affect on overall performance, this has to be balanced against the performance that is gained by eliminating the function call mechanism.
Finally, some functions can take advantage of compile-time computation, which is similar to inline expansion but where complex expressions can be evaluated at compile time and thus reduced to much simpler expressions. This not only reduces code size but greatly improves performance by completely eliminating unnecessary runtime operations.
What is mean by scope in c language?
Scope is generally defined as variable or functions life... Generally the life is between the opening braces and close braces "{ }" ... If thee variable is defined as "static" and if is defined outside a function then its scope is in same file. if defined as global then its scope is across the files.
What is the difference between a readline statement and a writeline statement?
The readline statement method of programming will allow for the next statement in the sequence to be read. The writeline method of programming only allows for the current statement or sequence to be read after determining the end of the last line.
What is passes in sorting algorithm?
Assuming you're talking about comparison-based sorting algorithms, the number of passes is the number of comparisons that the algorithm makes internally while sorting. In a programming language, this would be the total number of times the loop executes. This number is defined by the computational complexity (Big-O notation), which defines an upper bound.
Difference between heap sort and quick sort?
Bucket sort is a sorting algorithm that works by partitioning an array into a finite number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm. A variation of this method called the single buffered count sort is faster than the quick sort and takes about the same time to run on any set of data.
How does a photovoltaic array work?
A photovoltaic array converts sunlight into electricity using solar cells made of semiconductor materials, typically silicon. When light photons strike the cells, they excite electrons, generating a flow of electric current through the material. This direct current (DC) electricity is then converted to alternating current (AC) by an inverter, making it usable for homes and businesses. The efficiency of the array depends on factors like the angle of sunlight, temperature, and the quality of the solar cells.
How do you print a string using putchar?
You would iterate over all characters within the string, printing each character with the putchar function. In C, strings are terminated with a null byte, so you'd stop when that null byte has been reached.
Example:
void printme(const char* me) {
while (*me) {
putchar(*me++);
}
}
Needless to say this method is inefficient compared to using API that outputs the entire string at once, but the general approach of iterating over all characters in a string is used frequently.
Convert the following binary and decimal number 396 into respective number system?
2 396 R
2 198 0
2 99 0
2 49 1
2 24 1
2 12 0
2 6 0
2 3 0
2 1 1
0 1
C program to read an array and print its reverse using pointers?
#include<stdio.h>
#include<conio.h>
// note: this code does not test for user-input errors!!
int main() {
int array[10],i,n;
printf("enter the number of elements in the array:");
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&array[i]);
printf("the reverse ordered array is :");
for(i=n-1;i>=0;i--) printf("%d",array[i]);
return 0;
}
Why java takes 4 byte of int while c has 2?
Java defined int as a 32-bit number because that is generally large enough to hold the information you need.
The size of an int in C may actually have either 16 or 32 bits, depending on the implementation. Basically, the specifications for any C implementation in UNIX must have 32-bit ints, while the ISO C standard only requires 16-bit ints. The stdint.h and limits.h files exist exactly because not all implementations are the same, and these files will define the min/max values of the integral types.
Do compiled programs usually run faster because they are already in machine code?
No it is because compiled programs are scared so they run like stink.
Plus, uncompiled programs, ie. source programs, do not run at all... neither slowly nor fast.
What are the different ways of constructing a multiway if-else structure?
If this is a one-off, use either SSI components from your junk-box, or one or more MUX chips, with some outputs wired back to inputs.
If you are making quantities, either use an eprom, burn it to ROM when it's debugged, or use a PLA.
Whichever you do, logical analysis first will probably save time and money in the long term.