answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

Can exact amount of bits specified for integer data type in c?

1. Yes, but only inside data-structures with the 'bit fields'.

2. There is header called inttypes.h which gives you the following types: int8_t, int16_t, int32_t, int64_t (and unsigned variants).

Who to Write a programme for addition of two 100 digit numbers in c language?

The native C language will not permit the addition of two 100 digit numbers with native data types. Therefore, you need to simulate the 100 digit numbers differently, and that can be done various ways, including using an arbitrary precision math package, or BCD arithmetic, etc.

What is called Dividing a program into function and modules?

Modularisation. It could also be called refactoring, where large and complex functions are split into several simpler functions, making code easier to read. Refactoring can also help to reduce code duplication.

What is a programmable timer?

A programmable timer usually just means a timer that can be programmed to go off at any time.

How type Punjabi?

If you want to type in punjabi, you have to download a font, i believe its Gurmikhi. But documents written using these fonts are not portable. Means you will require to carry the font along with your document if you want to use same document on some other system. Also you can not post content, written using these fonts, on websites (like your blog, community sites, etc).

You will rather require to write your content in UNICODE format. There are many Virtual Punjabi Keyboard (web based) which provides you such facility. You can try http://www.shriwaheguru.com/punjabi_keyboard.html

Algorithm to determine if a binary tree is complete binary?

There are many ways of checking for a complete binary tree. Here is one method:

1. Do a level order traversal of the tree and store the data in an array

2. If you encounter a nullnode, store a special flag value.

3. Keep track of the last non-null node data stored in the array - lastvalue

4. Now after the level order traversal, traverse this array up to the index lastvalue and check whether the flag value is encountered. If yes, then it is not a complete binary tree, otherwise it is a complete binary tree.

Which stage of building a fully executable program form C source code combine multiple files into an executable program?

It's actually 3 stages: preprocessing, compilation and linking.

Preprocessing deals with all the preprocessor directives (all lines beginning with #). So a line such as #include<stdio.h> will effectively copy/paste the contents of the stdio.h header in place of the directive. The header itself may also contain preprocessor directives and these must be processed prior to insertion. Macros are also processed at this stage and all comments are stripped out. The end result is a translation unit that contains pure C code with absolutely no macros, no directives and no comments whatsoever. The translation unit is usually stored in working memory, however your IDE may include a switch that allows you to examine the contents of the translation unit.

The compiler processes each translation unit in isolation. Since the compiler cannot see any other translation units, only names with internal linkage can be resolved at compile time. The compiler produces an object file from the translation unit. The object file contains machine code along with a table of any names that couldn't be resolved by the compiler (those with external linkage).

Once all translation units have been compiled, the linker can examine the object files and resolve the outstanding external linkage problems, essentially linking all the object files into a single executable.

Problems can occur at any stage. For instance, preprocessing could result in a macro expansion that generates code that cannot be compiled. The compiler cannot resolve these problems because the compiler never saw the macro, it only saw the code that was generated by the preprocessor. So although it can identify the problem in the translation unit, it cannot identify where that problem originated. This is why macros are so difficult to debug: the compiler cannot help you.

Aside from macro problems, the compiler can identify and help you resolve a wide range of problems in your code thus it pays to make use of it as much as possible. The compiler can also statically assert your assumptions, perform compile-time computations and optimise your code through inline expansion, thus ensuring your code is error free and operates at peak performance.

Link-time errors are more difficult to deal with, but usually mean you've violated the one-definition rule (ODR) in some way, either by providing two different definitions for the same name or by not providing any definition of a name.

Even if no errors occur and linking is successful, it does not mean your executable is error free. The computer will only do exactly what you've told it to do, but it cannot account for logic errors at runtime. Many of these can be caught at compile time by making prudent use of static assertions, however this isn't always possible so you should also provide "sanity" checks wherever necessary and include appropriate error handling wherever runtime logic cannot be guaranteed to hold.

Write an Algorithm for towers of hanoi?

#include
#include
void hanoi(int x, char from,char to,char aux)
{
if(x==1)
{
printf("Move Disk From %c to %c\n",from,to);
}
else
{
hanoi(x-1,from,aux,to);
printf("Move Disk From %c to %c\n",from,to);
hanoi(x-1,aux,to,from);
}
}
int main(void)
{
int disk;
clrscr();
printf("Enter the number of disks you want to play with:");
scanf("%d",&disk);
double moves=pow(2,disk)-1;
printf("\nThe No of moves required is=%g \n",moves);
hanoi(disk,'A','C','B');
getch();
}

When you're running a component within aspnet what account is it running under on windows xp ---windows 2000 windows 2003?

It runs on ASPNET (IIS Default Account) found under AD or Users and Computers. The password is autogenerated and DO NOT change the password. If done, there is a document by MS to resolve the issue. Kind regards, Imtiaz Hasham

SME IT Networks

Write a program that accept a sentence and print all the words starting with vowels?

import java.io.*;

class test

{

public static void main()throws IOException

{

String s,p="";

char ch;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int i,c=0;

//input statement

System.out.println("Enter any string");

s=br.readLine();

s=s+" ";

for(i=0;i<s.length();i++)

{

ch=s.charAt(i);

if(ch!=' ')

{

p=p+ch;

}

else

{

if(p.startsWith("a")p.startsWith("e")p.startsWith("i")p.startsWith("o")p.startsWith("u"))

{

c++;

System.out.println(p.toUpperCase());

}

p="";

}

}

System.out.print("Total Words Starting with Vowels="+c);

}

}

by :

Pradeep Sir

Infonet Global Solutions

E-Block new Tempo Stand, Rajaji puram,

Lucknow-17

mob:- +91-9450821737

What is the difference between subscript and subscripted variable in c plus plus?

Subscripts are used to identify the elements in an array, where the first element has subscript 0. Thus an array of n elements has subscripts in the range 0 to n-1. Each element may itself be an array, thus allowing multi-dimensional arrays.

The subscript may be a constant or a variable. However, when declaring a static array, the subscript must be a constant. Constants include literal constants as well as named constants.

A subscripted variable is simply an array or a datatype that can be divided into an array. For instance, a 32-bit int can be treated just as if it were an array of two 16-bit shorts or four 1-byte chars.

Thus in the 32-bit int array, int i[10], i is a subscripted variable where i[0] is the first integer and i[9] is the last. If we then say char*c=&i, c would allow us to treat i as if it were a subscripted variable with 40 char elements (c[0] to c[39]).

What is the difference between interpreted and parsed?

Interpreted means - normally - the code is interpreted at run-time, while parsed (actually, it's "compiled") means the code is translated to a native object file at compile-time, and then executed. Compiled code is usually faster, also.

Is it better to write in cursive or in print?

It depends on what you're personally comfortable with AND whether or not you think others will be able to read it (if it is meant for others to do so). I personally write with a combination of boths cursive and print. It seems weird, but it is still clearly written and readable. With technology on the rise, it seems that the art of cursive (or handwriting, or just writing period) seems to going out the door.

How to solve Josephus problem using c?

Previous answer was in C++, please learn the difference.

/**********************************************************

*josephus.c: Solve the josephus problem for an arbitrary number of players *and an arbtitrary number of players missed each time.

*

*Author: XXX

*

*Input1:Number of players

*Input2:Number of players to miss each time

*Output:The lucky survivor

**********************************************************

#include <stdlib.h> /*For calloc, free and sizeof*/

#include <stdio.h> /*For printf, scanf*/

/*---Global structure to hold player details and a pointer to the next player---*/

struct player{

int player_num;

struct player *next;

};

int main (void) {

int i, j; /*Loop counters*/

int n; /*Number of players*/

int k; /*Number to skip each time*/

struct player *firstplayer; /*Hold firstplayer, so list can be circular linked*/

struct player *current_player; /*Hold current player*/

struct player *victim; /*Hold victim, for freeing*/

/*---Welcome statement---*/

printf("\njosephus.c: Program to solve the Josephus problem for an arbitrary number of "

"\n players and an arbitrary choice of count. The output will be the "

"\n number of the surviving player.\n\n");

/*---Request the number of players and assign to n---*/

printf("Please input the number of players.\n>>");

scanf("%d", &n) ;

/*---Request how many players to miss and assign to k---*/

printf("Please input the number of players you want to miss before execution.\n>>");

scanf("%d", &k);

/*---Alert the user, and exit the program, if they entered the wrong type of input---*/

if (n<=0 k<=0) {

printf("\a\n\nPlease enter positive integers only for the player and count!! "

"\nExiting...\n\n");

return 0;

}

/*---Set initial current player and firstplayer to be the same and assign space dynamically to hold them---*/

firstplayer=current_player=(struct player *)calloc(1, sizeof(struct player));

/*---Detect allocation failure---*/

if (current_player==NULL) {

printf("\a\nAllocation failure. Program terminates...\n\n");

exit(1);

}

current_player->player_num=1; /*Set the first/initial current players number to one*/

/*---Loop over n, assigning space for all the players and linking each successive one to

* the previous. Note: we do not count from 1, since already done above---*/

for (i=2; i<=n; ++i) {

current_player->next=(struct player *)calloc(1, sizeof(struct player));

/*---Detect allocation failure---*/

if (current_player->next==NULL) {

printf("\a\nAllocation failure. Program terminates...\n\n");

exit(1);

}

current_player=current_player->next; /*Current player now points to the next player*/

current_player->player_num=i; /*Define each player number*/

}

/*Finally link the final current player to the firstplayer, to make the list circular*/

current_player->next=firstplayer;

/*---Loop over n, counting up one every time a player dies---*/

for (i=1; i<n; ++i) {

/*Cycle through players until the one just before the unlucky one is reached*/

for (j=1; j<k; ++j) {

current_player=current_player->next;

}

/*Victim is the player just after the current player*/

victim=current_player->next;

/*Set the current player to point at the space just after where the victim was*/

current_player->next=current_player->next->next;

/*Set space now pointed to by victim free*/

free(victim);

}

/*Notify user of the game survivor*/

printf("\nThe lucky survivor is = %d\n\n", current_player->player_num);

/*---Set the final players space free---*/

free(current_player);

return 0;

}

C program for 2D convolution?

You can use ImageMagick library and use 'convolve' function.

Can we seal a 3 foot crack in a vent stack instead of replacing the entire stack and if so what materials would you use?

if it is above any water carrying capacity (area that has drain water flowing through it) and is truly just a vent stack it should be sealable using a clear silicone caulking.

Write c program to find median?

If you are using an array : sort using qsort() then take middle element.

Program to find n th fabonacci number?

#include
#include

using std::cin;
using std::cout;
using std::endl;
using std::tolower;

long factorial(const int& N);

int main()
{
int N = 0; //factorial of N
char command = 'n';
do
{
cout << "Enter a number to calculate factorial: ";
cin >> N;

cout << endl << "Factorial of " << N << " is: " << factorial(N) << endl;

cout << "Do you want to continue (y/n)?";
cin >> command;
cout << endl;
} while ('y' == tolower(command));

system("PAUSE");
return 0;
}

long factorial(const int& N)
{
if (N == 0)
{
return 1;
}
else
{
return (N * factorial(N - 1));
}
}

How many 8 bit characters does the ASCII standard define?

128 (0-127), 95 printable, 33 control (for 7 bit ascii that is a through back to teletypes.)

ISO 8859-1 has 256 characters.

From 128 up to 255 we find extra symbols for other languages and regions. Ascci 128 = € for instance and 255 = ÿ.

Of course there are many 8-bit standars, windows-1250, for an example.

How are the strings passed to a function?

By reference. The name of the string is converted to a pointer (in C/C++) and given to the function as the address of the first element. (In Java, all objects are passed by reference, and there are no pointers.)