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

How write a program that display today temperatures and their average in c plus plus?

#include<iostream>

double celsius(double fahrenheit) { return((fahrenheit-32)*5/9); }

double fahrenheit(double celsius) { return(celsius*9/5+32); }

int main()

{

double f, c;

c = celsius( 32.0); // c 212.0

return(0);

}

Explain more about post and pre increment with examples?

  1. include

    main()

{

int b=5;

int c= (b++) + (++b) + (++b) + (++b);

printf("%d",c);

}

Ans: The answer will be 27.

The answer will be 32

How an unsigned int can be twice as large as the singed int?

If you have a 1 byte (8 bit) number, then you can use those bits in two different ways, signed and unsigned.

Unsigned means that all 8 bits represent a power of two, so you can go from 00000000 = 0 (2^0) to 11111111 = 255 (2^8 - 1).

SIgned means that you take the first bit and use it to represent positive or negative. In this case 00000001 = 1 and 10000001 = -1. So your range of values is 11111111 = -127 (-(2^7 - 1)) to 01111111 = 127.

There are a couple of problems with this simplified example, one being that you have two different representations for zero. Most computer systems use two's complement to get around this.

How do you call a function named my function?

In most languages, you can't have names with space, for functions, variables, etc. Assuming your function is called myFunction, the usual way to call it is:

myFunction()

This assumes the function requires no parameters. If the function does require parameters, the parameters will be included within parentheses.

What are the data types in C language and their meanings?

They are INT , FLOAT , CHAR. int carries integers only & occupies 2bytes of memory space each. float carries fractional numbers only & occupies 4bytes of memory space each.char carries characters only & occupies 1bytes of memory space each.

Hope this will help you.

C program for swap two numbers without using temporary variables?

Using a temporary variable:

#include<stdio.h>

#include<conio.h>

void main()

{

int a,b,temp;

clrscr():

printf("Enter the first number a\n");

scanf("%d",&a);

printf("Enter the second number b\n");

scanf("%d",&b);

printf("Before swapping a=%d b=%d",a,b);

temp=a;

a=b;

b=temp;

printf("The swapped values are: a=%d b=%d",a,b);

getch();

}

Without using a temporary variable:

#include<stdio.h>

#include<conio.h>

void main()

{

int a,b;

clrscr();

printf("Enter the first number a\n");

scanf("%d",&a);

printf("Enter the second number b\n");

scanf("%d",&b);

printf("Before swapping a=%d b=%d",a,b);

a=a+b;

b=a-b;

a=a-b;

printf("The swapped values are: a=%d b=%d\n");

getch();

}

How to merge two single linked list using c?

Here is the java version, C should be similar

// merges two Singly linked lists A and B, both sorted in increasing order of integers .

// Return a Singly linked list sorted in increasing order

// for ex if A = 1->2->3->6 and B = 2->4->7, returns 1->2->2->3->4->6->7

public LinkedList merge(LinkedList A, LinkedList B) {

Node 1A = A.head;

Node 1B = B.head;

Node P1A = NULL;

Node 2A = NULL;

Node 2B = NULL;

while ( 1A != NULL && 1B !=NULL){

2A = 1A.next;

2B = 1B.next;

if (1A.item >= 1B.item) {

if (P1A != NULL) {

P1A.next = 1B;

}

else if ( P1A == NULL){

P1A = 1B;

}

1B.next = 1A;

P1A = 1B;

1B = 2B;

}

else if ( 1A.item < 1B.item){

if ( 2A != NULL) {

P1A = 1A;

1A = 1A.next;

}

else{

1A.next = 1B;

break;

}

}

}

return A;

}

What is dangling else in c language?

Here is an example:

if (exp1) if (exp2) stmt1 else stmt2

It could mean different things, like:

if (exp1) { if (exp2) stmt1 else stmt2 }

if (exp1) { if (exp2) stmt1 } else stmt2;

if (exp1) { if (exp2) stmt1 else stmt2 } else stmt2

Well, the first is the good answer, but it can be confusing, so when in doubt use {brackets}

Print the digits in a number in ascending or descending order c program?

#include


/* In case pow does not work from math.h */
int my_pow( int x, int y )
{
int i, result = 1;


for( i=1; i<=y; i++ )
{
result = result * x;
}


return result;
}


int main()
{
int n,i,j, temp1, temp2;


printf("\n Enter number of digits :");
scanf("%d",&n);


for( i= my_pow(10,n-1); i < (my_pow(10,n)-1); i++ )
{
j = n;


do
{
temp1 = ( i / (my_pow(10,(n-j))) ); /* Formula to fetch successive digit */
temp1 = temp1%10;


temp2 = ( i / (my_pow(10, (n-(j-1)))) ); /* Formula to fetch successive digit */
temp2 = temp2%10;


if ( temp1 > temp2 )
{
if ( 1 == j )
{
printf(" %d, ", i );
break;
}


j--;
}
else
{
break;
}


}while(1);
}


printf("\n");


return 1;


}


OUTPUT:


------------


[~/temp-satish]$ ./a.out


Enter number of digits :2
12, 13, 14, 15, 16, 17, 18, 19, 23, 24, 25, 26, 27, 28, 29, 34, 35, 36, 37, 38, 39, 45, 46, 47, 48, 49, 56, 57, 58, 59, 67, 68, 69, 78, 79, 89,
[~/temp-satish]$
[~/temp-satish]$ ./a.out


Enter number of digits :3
123, 124, 125, 126, 127, 128, 129, 134, 135, 136, 137, 138, 139, 145, 146, 147, 148, 149, 156, 157, 158, 159, 167, 168, 169, 178, 179, 189, 234, 235, 236, 237, 238, 239, 245, 246, 247, 248, 249, 256, 257, 258, 259, 267, 268, 269, 278, 279, 289, 345, 346, 347, 348, 349, 356, 357, 358, 359, 367, 368, 369, 378, 379, 389, 456, 457, 458, 459, 467, 468, 469, 478, 479, 489, 567, 568, 569, 578, 579, 589, 678, 679, 689, 789,
[~/temp-satish]$ ./a.out


Enter number of digits :4
1234, 1235, 1236, 1237, 1238, 1239, 1245, 1246, 1247, 1248, 1249, 1256, 1257, 1258, 1259, 1267, 1268, 1269, 1278, 1279, 1289, 1345, 1346, 1347, 1348, 1349, 1356, 1357, 1358, 1359, 1367, 1368, 1369, 1378, 1379, 1389, 1456, 1457, 1458, 1459, 1467, 1468, 1469, 1478, 1479, 1489, 1567, 1568, 1569, 1578, 1579, 1589, 1678, 1679, 1689, 1789, 2345, 2346, 2347, 2348, 2349, 2356, 2357, 2358, 2359, 2367, 2368, 2369, 2378, 2379, 2389, 2456, 2457, 2458, 2459, 2467, 2468, 2469, 2478, 2479, 2489, 2567, 2568, 2569, 2578, 2579, 2589, 2678, 2679, 2689, 2789, 3456, 3457, 3458, 3459, 3467, 3468, 3469, 3478, 3479, 3489, 3567, 3568, 3569, 3578, 3579, 3589, 3678, 3679, 3689, 3789, 4567, 4568, 4569, 4578, 4579, 4589, 4678, 4679, 4689, 4789, 5678, 5679, 5689, 5789, 6789,
[~/temp-satish]$

How can you write a c program using while loop that will print first ten odd numbers?

#include<stdio.h>

int main () {

int odd=1;

int count=0;

while (count++<10) {

printf (%d\n", odd);

odd+=2;

}

return 0;

}

10 d in a t n including the a c?

10 digits in a telephone number including the area code

What are compiler directives?

Compiler directives instruct the preprocessor to perform certain tasks prior to compiling the source code. The language compiler can only compile C code, but macros (lines beginning with a # symbol) are not part of the C language, so these need to be processed before the compiler can do its job.

The most common compiler directive is the #include directive, which instructs the preprocessor to import the named file, effectively copy/pasting the content of that file in place of the directive. The content may itself contain directives and these must also be processed accordingly before the content is inserted.

Note that the insertion takes place in a temporary file; the source file is not changed by the preprocessor. The temporary file is usually deleted after compilation is complete, however you can configure the compiler to retain these files so you can see what code is produced by the preprocessor and thus what the compiler "sees".

The #define and #undefine compiler directives define or undefine macros; symbols which the preprocessor can refer to while processing other directives. Macros can also be defined via the command line.

The #ifdef, #ifndef, #elif, #else and #endif compiler directives are used in conditional compilation in conjunction with macro definitions. These tell the preprocessor which parts of the source code to include in or exclude from the temporary file. This is useful when writing debug code that we wish to include in a debug build but exclude from a retail build, or we wish to cater for different architectures and require different libraries and function calls in order to cater for them.

A macro symbol can also be given a value. Wherever that symbol appears in the code, the symbol is replaced with the value. This provides a convenient text-replacement system that can help make code easier to read. However, a macro can also be used to define a function (a macro function). These differ from ordinary functions in that they are always inline expanded, however they are not type-safe and the compiler cannot help you debug them (the compiler never sees the macro -- it only sees the inline expanded code produced by the macro). Macro functions are best avoided, however when used with care they can help to resolve complex problems that cannot easily be resolved within the language itself. It's best to think of macro functions as being code generators but, because they are not part of the language, its best to keep their usage as simple as possible.

As well as processing compiler directives, the preprocessor also strips out all the user-comments from the source file. Even if a compiler could read a comment it certainly wouldn't understand it, so to keep the compiler implementation as simple and as efficient as possible, all non-C code is completely stripped out. Even the redundant whitespace and newline characters are stripped out. The end result is a compact source file which can be easily compiled -- assuming no errors have been generated by your macros!

What is sequential programming language?

In the early days of computing, the dominant programming languages weresequential(such as basic or assembly language). A program consisted of a sequence of instructions, which were executed one after the other. It ran from start to finish on a single processor.

reference: http://code.google.com/edu/parallel/mapreduce-tutorial.html

Which are valid identifiers?

Identifiers can be composed of letters, numbers, _ and $. Identifiers can only begin with a letter, _ or $. The identifer can be of mixed case.

also. read page 51, paragraph titled"User- Defined Identifiers"

in the book ITT gave you. The answer to your homework is clearly stated there.

Does window 7 come with a c plus plus compiler already installed?

Not in its standard form, but there are modified versions available that will allegedly work under Windows 7. But if you really want to work with Windows 7 programs then you'd best avoid Turbo C++. Use a more generic and up to date version such as GCC.

What is stacks in data structure using c?

queue is an abstract data type that which entities in a collection are kept in order, this makes the sense of fifo(first in first out).

stack is a container of the object which works on the principle of lifo(last in first out)

Can you compile program without header file?

Yes,we can compile our program without header file without any error,but we can not use any predefine functions like printf,scanf.

What do you mean by compiler assembler and interpreter?

Computers can directly run only binary machine code. When people write programs, that program text must be processed into machine code before it can be run.

Compilers and assemblers convert the source code into machine code. Compilers take a high-level language such as C or C++ and convert it, while assemblers take a much lower level language called "assembly language" where there is one language statement per machine instruction. High-level languages can be recompiled for different kinds of processors (like Intel or ARM CPUs) but assembly language is closely tied to the kind of processor. Some compilers actually compile high-level code into assembly language and then run that through an assembler to get machine code.

Interpreters are a different animal. They take either source code or partially compiled code and run it in the interpreter itself, rather than creating machine code. In other words, they directly "interpret" the program. Languages such as Perl, Python, and Ruby are interpreted from the source code. For Java and C#, the source code is compiled into an intermediate code that is easy to interpret.