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

Write a program to find greatest of three number using conditional operator in c?

To find greatest of 3 digits in one line

#includ<stdio.h> #include<conio.h>

void main() { int a,b,c; printf("enter a,b,c:); scanf("d%d%d",&a,&b,&c);

printf("greatest no: %d"(a>b)?((a>c)?a:c):((c>b)?c:b));

printf("have a nice day");

getch();

}

What is the difference between C and HTML?

HTML is a widely accepted web-design language. With HTML, you surround a block of text with “tags” that indicate how the text should appear or what purpose it has in a document. Cascading Style Sheets (CSS) make it faster and easier to create and maintain websites. CSS works with HTML (or any markup language) to apply a uniform style and format to your website. CSS allows you to set your site’s fonts, colors, layouts and more without repeating the HTML formatting tags throughout. SSL

What are the advantages of a pointer variable?

Arrays takes consecutive memory space.

So, if you have 5 consecutive memory blocks free which is consecutive, an error will

occur while creating an array which takes more than 5 blocks of memory.

But if you use pointer, then it don't need consecutive memory blocks all the elements can be placed anywhere in memory.

Built-in functions in turbo c?

i want a coding of a program of a calculator using graphics in c language??

What high level programming languages are translated by a compiler?

Almost any language can be used to develop a compiler. The first compilers were written in assembly language or machine code but today they are typically written in C or (more commonly) C++. Other languages can be used, however the key aspects of any compiler are speed and efficiency, in which both C and C++ excel.

How does an inline function differ from a preprocessor macro in c?

"Differences between inline functions and non"Non-inline functions are your standard functions. When they're called, the compiler puts all the variables and its current position on the stack, jumps to the location in memory where the function resides, executes the instructions, and jumps back to where it was originally called. All that work takes a lot more time then if you had just not used functions. By writing the code directly into your procedure and not using functions you are inlining your code. If you have that same piece of code in multiple places, maintaining your code will become a problem because your code will be duplicated everywhere (because you're not using functions in order to achieve a speed increase).

In order to get the best of both worlds, C++ introduced the inline keyword. By specifying that a function is inline, the compiler will take the function you have written and basically replace the function call that would have been generated with the function itself. In other words, using an inline function is pretty much directly putting your code there, except it's prettier and more maintainable.

Overuse of inlining function will cause bloated code for a very marginal increase in speed, if any. Inline functions are best suited for small quick functions. Also note that the inline keyword is a request to inline a function and the compiler may not necessarily honor that request. One example would be attempting to inline a recursive function.

In other languages like Java and C#, you are not able to specify what is inlined and what is not. The compiler will automatically make that decision without any input from the programmer.

What is the use of break and exit statements in c?

A break is a jump statement that allows code to exit a statement block without processing the remaining instructions in that statement block. Execution continues with the statement following the statement block.

Jump statements (the break, return, continue and goto keywords) are typically used in conjunction with a conditional expression, to allow execution to branch to another section of code within the same function whenever the expression is true. Function calls do a similar type of thing, branching off to other sections of code, but execution always returns to the point the call was made. Jump statements do not.

However, jump statements are also used in conjunction with switch statements. If a case label does not have a jump statement before the next case label is encountered, execution will fall through to the next label (just as as if that label did not exist). Sometimes this may be the intention but, in most cases, once a specific case has been handled, execution is normally passed to the statement immediately following the switch block, in which case a break is required (return and goto can also be used to exit a case label, but not continue). The final case (or default case) does not require a break if execution is expected to fall through to the statement following the switch statement.

With regards to the other jump statements:

The continue statement is used in loops, to start a new loop without executing any remaining command in the loop. In do..while() loops, execution is passed to the while(condition) expression.

The goto statement jumps to a given label, which must be present somewhere within the same function. A label is a user-defined name followed by a colon, marking the point in the function the goto will jump to.

The return statement exits a function altogether, returning control back to the calling function.

Write a program to swap any number?

Do write, but before you start, please explain what does swapping a number mean.

When one dimensional character array of unspecified length is assigned an initial value?

string[] str= new string[2]{"ss","gg"}

for(int i=0;i<str.length;i++)

{

Response.wrirte(str[i]);

}

How do you write a c plus plus program to calculate the sum of squares using a function?

/**recursive function to find square root of a double to a precision of

maxDepth = 10 decimal places

returns -1.0 when given a negative number*/

#define maxDepth 10

/*firstly find the rational part*/

double getSqrt(double numIn){

/*cant take the square root of a negitive,

and a square root should not be negative

so return -1*/

int candidate = 0;

if (numIn <0)

return -1.0;

/*try every integer until you get one whose square is higher than

the number required, and this clearly one more than the

integer part of your square root*/

do{

if (candidate *candidate *1.0 numIn)

return testVal;

if (testVal * testVal >numIn)

/*most square roots are irrational, and theirfore a maximum number of recursions

must be set, otherwise infinite recursion will occur*/

if (myDepth <maxDepth)

return getIrrational(numIn, testVal-1/10^myDepth, myDepth +1);

else

return testVal-1/10^myDepth;

}

//this can probably be improved on in terms of conciseness, but the logic is the only //way to find a sqrt without going into calculous

How can insert a data into file in c?

You insert data into a file by copying the file to a temporary file up to the point of insertion, then copying the data to be inserted, then copying the balance of the original file. After closing the temporary file you delete the original file and rename the temporary file back to the original file's name.

What is the Structure of Program in Assembly language?

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..

What is overflow and underflow in queue?

In C Programming arrays are given a size, which is the number of elements in the array. Space is allocated for an array in memory. The is the only memory that the array is supposed to use. C is a programming language that has very little restrictions regarding what it will allow you to do. If you try to write to a memory location that is not supposed to be written over, C will let you, however sometimes the operating system will prevent this. When an array writes past where it is supposed to this is called array overflow. For example. If is an array is designed to hold 50 integers and the program adds 51 integers then the extra integer is written at the end of the array and had to be written in memory not designated for the array.

Write a C program to print Armstrong numbers in a given range?

Sorry. I had to delete the older version, for it was written in C++, while the questioner had asked one in C. So here it is. In fact, I will give the questioner a bonus, it will print not only Armstrong numbers but all Narcissistic numbers (here the power to which the individual digits should be raised before being added to each other can be any integer. Clearly Armstrong numbers form a subset of these numbers, with the power equal to three), and that too not only upto 10000, but upto the maximum number a C compiler can process. Enjoy!

#include

#include

main()

{

int m=1,b;

int a[200],i,j,k,l;

while (m<=2147483647)

{

b=m;

i=0;

while (b>=1)

{

a[i]=(b%10);

b=floor(b/10);

++i;

}

for (j=1;j<=9;++j)

{

k=0;

for (l=(i-1);l>=0;--l)

k+= pow(a[l],j);

if (k==m)

goto sexy;

}

goto label;

sexy: printf("%d (raise every digit to power of %d)\n",m,j);

label: ++m;

}

}

Develop a program that reads a floating point number and then replace the right most digit of the integral part of the number?

/* program without if statement */

#include<stdio.h>

#include<conio.h>

void main()

{

int a,c;

float b;

clrscr();

printf("Enter the value \n");

scanf("%f",&b);

a=c;

c=a%10;

printf("the right most digit is %d",c);

getch();

}

Who developed c language n when?

C was developed between 1969 and 1973 by Dennis Ritchie at Bell Labs.

Write a 'c' program using command line arguments to search for a word in a file and replace it with the specified word?

#include<stdio.h>

#include<string.h>

void main()

{

char m_str[100],m_word[100],rep[100];

char str1[100];

int i,j,f,k;

int len1,len2,len3;

printf("\n enter the main string:=\n");

gets(m_str);

len1=strlen(m_str);

printf("\n enter the word that you want to replace:=\n");

gets(m_word);

len2=strlen(m_word);

printf("\n enter the word of same length you want to replace with:=\n");

gets(rep);

len3=strlen(rep);

for(i=0;i<len1;)

{

f=0;

for(j=0;j<len2;)

{

if(m_str[i]!=m_word[j])

{

while(m_str[i]!=m_word[j])

i++;

while(j<len2)

j++;

}

if(m_str[i]==m_word[j])

{

f=1;

j++;

i++;

}

}

if(f==1)

{

for(k=0,j=i-len2;k<len3;k++)

m_str[j+k]=rep[k];

}

}

printf("\nthe replaced string is :-");

puts(m_str);

}

What is meant by linked list in c programming?

Yes, a linked list can be implemented in an array. Instead of pointers (or references in JAVA) you can use element indexes in the "next" and "last" items.

This does not stop you from using pointers or references. They still work. You can take the address of an element of an array, such as &a[217], and place that in the .next or .last pointers, and manage the relationships in the normal way. Using an array is simply one way to manage memory.

What types of anthropometric data are there?

Haha Raymond 2 from I-NEWTON wlang sagot sa MAPEH

MANGHIRAM NA LNG KAU KAY RAUELL

Pare-pareho kau ng sagot..

What are the Circular singly linked list applications in real life?

best example is trains...where each coach is connected to next coach except the engine and the last coach..when we need to add a coach we need to move to the right position and adjust the connecting point suitably!!

What does N.C. switch?

The terminology, in regards to switches and relay contacts, stands for N.C. = normally closed and N.O. = normally open. When ever these designations are used in schematics or electrical prints the position is to be taken in the de-energized state. No power on the circuit.

What is an array of pointers to pointers?

A pointer is a variable that stores value of address of a variable. Since a pointer itself is a variable, it is allocated a memory location.

Pointer to pointer means a pointer which points to the address of a pointer. In other words a pointer to a pointer has the address of the address of a variable.


We can have pointers to int, and pointers to char, and pointers to any structures we've defined, and in fact pointers to any type in C, it shouldn't come as too much of a surprise that we can have pointers to other pointers. If we're used to thinking about simple pointers, and to keeping clear in our minds the distinction between the pointer itself and what it points to, we should be able to think about pointers to pointers, too, although we'll now have to distinguish between the pointer, what it points to, and what the pointer that it points to points.

What is the FORTRAN program for pascal's triangle?

the logic i have used is nCr => n!/(r!*(n-r)!) for example the outer loop counter is 'n' and the inner loop counter is 'r' , then the corresponding element of the pascal's triangle will be nCr. keep in mind that both the loops will have to start from zero. #include<stdio.h> main()

{

int num,i,j,k,space;

int difffact=1,diff,n,r,x,y,comb=0,nfact=1,rfact=1;

printf("please enter the number of lines\n");

scanf("%d",&num); k=num-1;

space=num-1;

for(i=0;i<num;i++)

{

k=space--;

for(;k>0;k--)

{

printf(" ");

}

for(j=0;j<=i;j++)

{

comb=0;

nfact=1;

rfact=1;

difffact=1; for(n=i;n>=1;n--)

nfact=nfact*n; for(r=j;r>=1;r--)

rfact=rfact*r; diff=i-j;

for(;diff>=1;diff--)

difffact=difffact*diff; comb=(nfact/(rfact*difffact));

printf("%d ",comb);

}

printf("\n");

}

}