How would you write the number 37 in binary?
100101 1 times 2^0 = 1 PLUS 0 times 2^1 = 0 PLUS 1 times 2^2 = 4 PLUS 0 times 2^3 = 0 PLUS 0 times 2^4 = 0 PLUS 1 times 2^5 = 32 EQUALS 37
You don't declare library functions. Simply include conio.h. For details use the built-in help.
How do you write a c program for hashing?
- Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string. Hashing is used to index and retrieve items in a database because it is faster to find the item using the shorter hashed key than to find it using the original value. It is also used in many encryption algorithms. As a simple example of the using of hashing in databases, a group of people could be arranged in a database like this: Abernathy, Sara Epperdingle, Roscoe Moore, Wilfred Smith, David (and many more sorted into alphabetical order) Each of these names would be the key in the database for that person's data. A database search mechanism would first have to start looking character-by-character across the name for matches until it found the match (or ruled the other entries out). But if each of the names were hashed, it might be possible (depending on the number of names in the database) to generate a unique four-digit key for each name. For example: 7864 Abernathy, Sara 9802 Epperdingle, Roscoe 1990 Moore, Wilfred 8822 Smith, David (and so forth) A search for any name would first consist of computing the hash value (using the same hash function used to store the item) and then comparing for a match using that value. It would, in general, be much faster to find a match across four digits, each having only 10 possibilities, than across an unpredictable value length where each character had 26 possibilities. The hashing algorithm is called the hash function (and probably the term is derived from the idea that the resulting hash value can be thought of as a "mixed up" version of the represented value). In addition to faster data retrieval, hashing is also used to encrypt and decrypt digital signatures (used to authenticate message senders and receivers). The digital signature is transformed with the hash function and then both the hashed value (known as a message-digest) and the signature are sent in separate transmissions to the receiver. Using the same hash function as the sender, the receiver derives a message-digest from the signature and compares it with the message-digest it also received. They should be the same. The hash function is used to index the original value or key and then used later each time the data associated with the value or key is to be retrieved. Thus, hashing is always a one-way operation. There's no need to "reverse engineer" the hash function by analyzing the hashed values. In fact, the ideal hash function can't be derived by such analysis. A good hash function also should not produce the same hash value from two different inputs. If it does, this is known as a collision. A hash function that offers an extremely low risk of collision may be considered acceptable. Here are some relatively simple hash functions that have been used: * The division-remainder method: The size of the number of items in the table is estimated. That number is then used as a divisor into each original value or key to extract a quotient and a remainder. The remainder is the hashed value. (Since this method is liable to produce a number of collisions, any search mechanism would have to be able to recognize a collision and offer an alternate search mechanism.) * Folding: This method divides the original value (digits in this case) into several parts, adds the parts together, and then uses the last four digits (or some other arbitrary number of digits that will work ) as the hashed value or key. * Radix transformation: Where the value or key is digital, the number base (or radix) can be changed resulting in a different sequence of digits. (For example, a decimal numbered key could be transformed into a hexadecimal numbered key.) High-order digits could be discarded to fit a hash value of uniform length. * Digit rearrangement: This is simply taking part of the original value or key such as digits in positions 3 through 6, reversing their order, and then using that sequence of digits as the hash value or key. A hash function that works well for database storage and retrieval might not work as for cryptographic or error-checking purposes. There are several well-known hash functions used in cryptography. These include the message-digest hash functions MD2, MD4, and MD5, used for hashing digital signatures into a shorter value called a message-digest, and the Secure Hash Algorithm (SHA), a standard algorithm, that makes a larger (60-bit) message digest and is similar to MD4.
Why the clrscr is used after declaration?
Use the help: this function clears the screen.
Note: non-standard Borland-specific function, don't use.
What is the difference between C programming and CPP programming?
C has no object oriented support. C++ is a superset of C that adds object-oriented support, but retains the concept of primitive variables. C# is a superset of C++, developed by Microsoft, that removes the concept of primitives, making it fully object-oriented but, unlike C and C++, is non-generic and is only useful for .NET programming. C# is not unlike Java, but Java is fully cross-platform and therefore has much wider support.
C program to find the given number is Adam number?
Is the instructions programmers have written in a higher level language?
"BASIC" is not a program, it is a programming language. A particular BASIC-interpreter or IDE may have been written in a high level language, maybe even in BASIC (C is more plausible though).
Examples of custom written program?
a custom written program that acts as our "intranet".This tool has a range of templates, letters and forms that we use in our everyday work both for our clients and for day-to-day tasks.
I can't give you the entire code since I don't know what programming language you are using. Here is a hint:
In the C language, you can simply use a loop statement that repeats the scanf() function
What the data structure is used behind FACEBOOK?
The GRAPH data structure used behind Facebook.
for more detail see
How do you write a c program to convert binary to decimal by using while statement?
write a c++ program to convert binary number to decimal number by using while statement
How does the assembly language can be executed by CPU?
Assembly language programs are the Low level programs. We write Assembly Language program in basically 8085 and 8086 microprocessors.
We can have several registers to do opreations with. Accumulator is one most important Register in a assembly program.
We use several instructions like..
Arithmetic:
INR - Increment Accumulator
ADD B - Add Content of Reg. B with Accumulator
SUB, etc.
Logical:
AND - Bitwise AND
Jump Instriction:
JZ label - Jump to label if ZERO flagged
JC Label - Jump on Carry
Etc..
Example:
MVI B, 06 //Load Register B with the Hex value 06
MOV A, B //Move the value in B to the Accumulator or register A
MVI C, 07 //Load the Register C with the second number 07
ADD C //Add the content of the Accumulator to the Register C
STA 8200 //Store the output at a memory location e.g. 8200
HLT //Stop the program execution
What is the c program to sort the n elements in the array in ascending order?
The following example repeatedly asks for a number. As each number is entered, the array (arr) is dynamically resized to accommodate the new number. To finish entering numbers, enter any non-number (such as the letter X). If any numbers were entered, the array is then sorted using a simple bubble sort and the result is then displayed.
Note that resizing an array like this is highly inefficient because the array must be copied each time it is resized. If you can determine how many numbers will be entered in advance (at runtime), then the array can be allocated just once, before reading the numbers into each array element.
#include <iostream>
int main()
{
float t, num = 0, *arr = NULL;
int max = 0, i, j;
while( 1 )
{
printf( "\nEnter a number:\n(Any letter to quit)\n>" );
int iResult = scanf( "%f", &num );
if( !iResult )
break;
arr = ( float * ) realloc( arr, ++max * sizeof( float ));
arr[ max-1 ] = num;
}
printf( "%d numbers entered.\n", max );
if( max )
{
for( i=1; i<max; i++ )
{
for( j=0; j<max-i; j++ )
{
if( arr[j] > arr[j+1] )
{
t = arr[j];
arr[j] = arr[j+1];
arr[j+1] = t;
}
}
}
printf( "Sorted:\n");
for( i=0; i<max; i++ )
printf( "%f\n", arr[i] );
printf( "\n" );
free( arr );
arr = NULL;
}
return( 0 );
}
How many characters can be taken as command line arguments?
Platform dependent. Many in unix, few in WinDos.
Write a c program to find positive and negative count?
Advantage and disadvantage of for loop over while looop?
Any for loop is equivalent to some while loop, so the language doesn't get any additional power by having the for statement. For certain type of problem, a for loop can be easier to construct and easier to read than the corresponding while loop. The for statement makes a common type of while loop easier to write. It is a very good (perhaps the best) choice for counting loops.
What is the difference between Built in Function and User Defined Function?
Built-in functions are functions that are provided for you by the standard includes. User-defined functions are those that you write yourself. Third-party functions are those that are written for you, but that are not provided by the standard includes.
What are the drawbacks of assembly level language?
The assembly language does not support object oriented program
so they change to c and c++ the c++ will support object oriented program
this are the demerits of assembly language.
How can you increase the size of a statically allocated array?
/* Allocate space for an array with ten elements of type int. */
int *ptr = malloc(10 * sizeof (int));
if (ptr == NULL) { /* Memory could not be allocated, the program should handle the error here as appropriate. */ realloc It is often useful to be able to grow or shrink a block of memory. This can be done using realloc which returns a pointer to a memory region of the specified size, which contains the same data as the old region pointed to by ptr (truncated to the minimum of the old and new sizes). If realloc is unable to resize the memory region in-place, it allocates new storage, copies the required data, and frees the old pointer. If this allocation fails, realloc maintains the original pointer unaltered, and returns the null pointer value. The newly allocated region of memory is uninitialized (its contents are not predictable). The function prototype is void *realloc(void *pointer, size_t size);
Write a program to add two integers using c plus plus?
#include<iostream>
int main()
{
int a=40;
int b=2;
std::cout<<a<<'+'<<b<<'='<<a+b<<std::endl;
}
Output:
40+2=42
What is the most basic loop in c?
the answer to this question would vary from programmer to programmer... Basically for the embedded system programmer the while loop is more important and would be considered as basic. However for the application programmer the for loop is always a better option.
AnswerThese are: LABEL-goto, while, for, do-while, and recursion, of course.
How do you write a C program to add 2 matrices using functions?
We'll assume the matrix elements are doubles, but we can easily adapt the code to cater for any numeric data type.
First we need a (primitive) function that emulates the += operator for two arrays of doubles:
double* add_assign_array (double* a, double* b, size_t sz) {
for (size_t i=0; i<sz; ++i) a[i] += b[i];
return a;
}
Note that we are wholly reliant upon the caller to ensure all arguments are valid. We could test for null pointer arguments, however there's no advantage in doing so when we cannot even guarantee that a and b actually refer to at least sz elements. For efficiency it's better if the caller handles any and all necessary runtime tests and thus keep those tests to a minimum.
With this function in place we can now add two matrices, row by row:
double* add_assign_matrix (double* a, double* b, size_t rows, size_t cols) {
size_t i;
for (size_t row=0; row<rows; ++row) {
i = row * cols;
add_assign_array (a[i], b[i], cols);
}
return a;
}
Example usage:
// Utility functions: void print_array (double*, size_t);
void print_matrix (double*, size_t, size_t);
int main (void) {
const size_t rows = 3;
const size_t cols = 4;
double a[rows][cols] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
double b[rows][cols] = {{13, 14, 15, 16}, {17, 18, 19, 20}, {21, 22, 23, 24}};
printf ("Matrix a:\n");
print_matrix (a, rows, cols);
printf ("Matrix b:\n");
print_matrix (b, rows, cols);
printf ("Matrix a+=b:\n");
add_assign_matrix (a, b, rows, cols);
print_matrix (a, rows, cols);
return 0;
}
void print_array (double* a, size_t sz) {
for (size_t i=0; i<sz; ++i) printf ("%f\t") a[i];
printf ("\n");
}
void print_matrix (double* a, size_t rows, size_t cols) {
for (size_t row=0; row<rows; ++row) print_array (a[row * cols], cols);
}
Note that the add_assign function emulates a += b rather than c = a + b. However, we can easily emulate this by copying one of the matrices and then calling add_assign upon the copy:
// e.g., c = a + b;
double c[rows][cols]; // uninitialised matrix
memcpy (c, a, rows * cols * sizeof (double)); // c is a copy of a
add_assign_matrix (c, b, rows, cols); // c += b
It's far from intuitive but arrays and matrices are anything but intuitive in C programming.
Which loop does not have an entry condition in C plus plus?
The only loop that does not require an entry condition is the procedural goto loop:
again:
/*...*/
goto again;
Although a do-while loop has no entry condition per-se, it still requires a mandatory entry condition into the second and all subsequent iterations.
do { /*...*/} while (true); // mandatory entry condition into all but the 1st iteration
And although a for loop's condition is optional, it is implicit:
for (;;) {/*..*/} // implicit for ever loop
for (;true;) {/*...*/} // explicit for ever loop
Write a program to find the square root of the quadratic equation using flow chart?
You don't need a flow chart for that; just use the quadratic formula directly; most programming languages have a square root function or method. You would only need to do this in many small steps if you use Assembly programming. The formulae would be something like this:
x1 = (-b + sqrt(b^2 - 4*a*c)) / (2 * a)
and
x2 = (-b - sqrt(b^2 - 4*a*c)) / (2 * a)
where a, b, and c are the coefficients of the quadratic equation in standard form, and x1 and x2 are the solutions you want.
A string literal is a sequence of characters, including backslash-escaped codes, between two double-quote characters. These are of type const char*, such that the character values are immutable (cannot be changed after creation). "Hello my little minions" is a string constant, for instance.
Note that under C you can pass const char* types as char* in function parameters, or assign values between constant and non-constant types, but C++ will issue warnings if you attempt to do as such (unless those warnings have been disabled, which may not be recommended).