C

Topic: C basics

How do I write a program which can generate all possible combinations of numbers from 1 to one less than the given number ?

main( ){long steps, fval, bstp, cnt1 ;int num, unit, box[2][13], cnt2, cnt3, cnt4 ;printf ( "Enter Number " ) ;scanf ( "%d", &num ) ;num = num < 1 ? 1 : num > 12 ? 12 : num ;for ( steps = 1, cnt1 = 2 ; cnt1 <= num ; steps *= cnt1++ ) ;for ( cnt1 = 1 ; cnt1 <= steps ; cnt1++ ){for ( cnt2 = 1 ; cnt2 <= num ; cnt2++ )box[0][cnt2] = cnt2 ;for ( fval = steps, bstp = cnt1, cnt2 = 1 ; cnt2 <= num ; cnt2++ ){if ( bstp == 0 ){cnt4=num ;while ( box[0][cnt4] == 0 )cnt4-- ;}else{fval /= num - cnt2 + 1 ;unit = ( bstp + fval - 1 ) / fval ;bstp %= fval ;for ( cnt4 = 0, cnt3 = 1 ; cnt3 <= unit ; cnt3++ )while ( box[0][++cnt4] == 0 ) ;}box[1][cnt2] = box[0][cnt4] ;box[0][cnt4] = 0 ;}printf ( "\nSeq.No.%ld:", cnt1 ) ;for ( cnt2 = 1 ; cnt2 <= num ; cnt2++ )printf ( " %d", box[1][cnt2] ) ;}}This program computes the total number of steps. But instead of entering into the loop of the first and last combination to be generated it uses a loop of 1 to number of combinations. For example, in case of input being 5 the number of possible combinations would be factorial 5, i.e. 120. The program suffersfrom the limitation that it cannot generate combinations for input beyond 12 since a long int cannot handle the resulting combinations.Data StructuresHashing...Hashing or hash addressing is a searching technique. Usually, search of an element is carried out via a sequence of comparisons. Hashing differs from this as it is independent of the number of elements n in the collection of data. Here, the address or location of an element is obtained by computing some arithmetic function. Hashing is usually used in file management. The general idea is of using the key to determine the address of a record. For this, a function fun( ) is applied to each key, called the hash function. Some of the popular hash functions are: 'Division' method, 'Midsquare' method, and 'Folding' method. Two records cannot occupy the same position. Such a situation is called a hash collision or a hash clash. There are two basic methods of dealing with a hash clash. The first technique, called rehashing, involves using secondary hash function on the hash key of the item. The rehash function is applied successively until an empty position is found where the item can be inserted. If the hash position of the item is found to be occupied during a search, the rehash function is again used to locate the item. The second technique, called chaining, builds a linked list of all items whose keys hash to the same values. During search, this short linked list is traversed sequentially for the desired key. This technique involves adding an extra link field to each table position.

Browse random answers:

What is the output of printf(“%d”)?
What is the difference between const char *p, char const *p, and char* const p ?
What's the difference between a null pointer, a NULL macro, the ASCII NUL character and a null string?
Can we get the remainder of a floating point division ?
How to write a swap( ) function which swaps the values of the variables using bitwise operators.
Is there any difference between the two representations?
main(){             int c[ ]={2.8,3.4,4,6.7,5};             int j,*p=c,*q=c;             for(j=0;j<5;j++) {                        printf(" %d ",*c);                        ++q;     }             for(j=0;j<5;j++){printf(" %d ",*p);++p;     }}
Why doesn’t this code: a[i] = i++; work?
Write a pro gramme to show bubble sort on a set of 10 numbers?
How do I write code that executes certain function only at program termination?
Is NULL always defined as 0?
Find the output of followingmain(){float me = 1.1;double you = 1.1;if(me==you)printf("I love U");elseprintf("I hate U");}
What are storage memory, default value, scope and life of Automatic and Register storage class? 
Nesting of loops in C may continue upto how many levels?
What are storage memory, default value, scope and life of Static and External storage class? 
Write a function to swap any two numbers? 
Which expression always return true? Which always return false? 
Can we change the system date to some other date?
Give some explanation for "for" LOOP ON C LANGUAGE? 
How to print 1 to 100 without using any conditional loop?
Can we get the process identification number of the current program?
C Program to print the following series:11 21 2 31 2 3 41 2 3 4 5
Write a pro gramme to show bubble sort on a set of 10 numbers? 
How to set the system date through a C program ?
How can we find out prime numbers from 1 to 50? 
Can we use scanf( ) function to scan a multiple words string through keyboard?
How to decide even and odd values without decision making loops? 
Why the output of sizeof ( 'a' ) is 2 and not 1 ?
write c program fibbonaci series program?
Explain with an example the self-referential structure.  
Describe structures and Union in brief.  
How to extract the integer part and a fractional part of a floating point number?
How to build an expression trees ?
What's the difference between a null pointer, a NULL macro, the ASCII NUL character and a null string?
How do I get the time elapsed between two function calls ?
How do I write a program which can generate all possible combinations of numbers from 1 to one less than the given number ?
How can we read/write Structures from/to data files?
When should you use a type cast?
What are the advantages and disadvantages of external class?
Define recursion in C.  
Differentiate Source Codes from Object Codes
How can you increase the size of a dynamically allocated array?
What is the difference between i++ and i+1 ? 
How will you allocate memory to double a pointer?
What is the purpose of main( ) function ?
What is the simplest sorting method to use?
How to distinguish between a binary tree and a tree?
What is a stack ?
What are memory models?
How does C compiler store elements in a multi-dimensional array?
If the result of an _expression has to be stored to one of two variables, depending on a condition, can we use conditional operators as shown below?( ( i < 10 ) ? j : k ) = l * 2 + p ;
What are stdin, stdout, and stderr?
How do I use the function ldexp( ) in a program?
What value is yielded by a relational expression?
How do I print the contents of environment variables?
– Is the unary minus operator (-) the same as the subtraction operator (-)?
How do I convert a floating-point number to a string?
 What can the %lu format specifier do?
 What will be output when you will execute following c code?#include<stdio.h>void main(){     int check=2;     switch(check){        case 1: printf("D.W.Steyn");        case 2: printf(" M.G.Johnson");        case 3: printf(" Mohammad Asif");        default: printf(" M.Muralidaran");     }}
Which of the following correctly shows the hierarchy of arithmetic operations in C?
What is automatic type promotion in c?
Which of the following is the correct usage of conditional operators used in C?
Declare a pointer which can point printf function in c.
Which of the following is the correct order if calling functions in the below code?
What are merits and demerits of array in c?
Which of the following are unary operators in C?
 Is C a great language, or what? Where else could you write something like a+++++b ? 
What will be output when you will execute following c code?#include<stdio.h>void main(){    int a=5,b=10,c=1;    if(a&&b>c){         printf("cquestionbank");    }    else{         break;    }}a) cquestionbank b) It will print nothingc) Run time errord) Compilation errore) None of the above
How would you use the functions fseek(), freed(), fwrite() and ftell()?
What does static variable mean?
What is the simplest sorting method to use?
Difference between syntax vs logical error?
What will the preprocessor do for a program?
What is preincrement and post increment?
Way to minimize a last dimension regarding executable?
Write a program to interchange 2 variables without using the third one?
How much does static varied signify?
Way to minimize a last dimension regarding executable?
Difference between *p and **p?
Difference between pass by reference and pass by value?
What are enumerations?
Write a code for implementation of doubly linked list with use of single pointer in each node?
What is the use of typedef?
what are C tokens?
What are C identifiers?
What is preincrement and post increment?
What are bit fields? What is the use of bit fields in a Structure declaration?
 Is it possible to have more than one main() function in a C program ?
Why n++ executes faster than n+1 ?
What will the preprocessor do for a program ?
What is a data type?
What will happen if any string in c is converted to integer explicitly?
Write a program to find the greatest of three numbers.
Write a program to check whether a given number is a prime.
Write a program to find the greatest among ten numbers.
Write a program to generate the fibonacci series
Write a program to display the multiplication table of a given number.
What is the difference between ‘break’ and ‘continue’ statements?
What is the difference between getchar and scanf functions for reading strings?
What is the difference between declaring a variable and defining a variable?