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 do you draw a line using C graphics?

its very easy just include the graphics directory in your program...

out put a dot on the screen.... in loop like..

Horizontal line from point A(x1,y1) B(x2,y2) start to out put the point from x1,y1 and then evry next loop keep y1 the same and increment x1 by 1.

Thanks

There is one more function in graphic library of C++, that is line().

It has four arguments of int type.

line(starting x coordinate, starting y coordinate, end x coordinate, end y coordinate);

setlinestyle() and setlinecolor() can be used for different line colors and line styles.

Class data types in c?

The data types indicate the type of values that can be stored. The primary data types in c are:

1. int, short, long, long long - used for integer values

2. float, double - used for storing floating point numbers

3. char - used for storing ASCII characters

What is program in c to swap entered two numbers without using third variable?

The required c program is given below

/*Swapping(interchange) the two entered numbers*/

#include<stdio.h>

main()

{

/*Without using third variable*/

int a,b,t;

printf("Enter a:");

scanf("%d",&a);

printf("Enter b:");

scanf("%d",&b);

a=a+b;

b=a-b;

a=a-b;

printf("\n After swapping without using third variable");

printf("\na=%d\nb=%d",a,b);

}

What is the Program to find sum of natural number using recursion?

#include #define NUM 100 //since prog is to be written for adding 100 natural
int main(){
int i,sum=0;
for(i=1;i<=NUM;i++) //adding the numbers to sum, from 1 to NUM
sum+=i;
printf("SUM IS %d",sum); //printing the result
}

Program in c language to find sum of digits using recursion?

# include
void main()
{
int no,rem=0,sum=0,n; /*declaration*/
printf("Enter 2 digit number:");
scanf("%d",&no);
for(n=1;n<3;n++) /*conditions*/
{
rem=no%10; /*separation of digits using % and / */
sum=sum+rem;
no=no/10;
}
printf("sum=%d",sum);
}

What are the advantages of compiling a function separately?

So it can be run.

Answering from an alternative angle, compiling source code into an executable program creates a list of instructions that can be understood directly by the CPU of the computer without any extra tools.

The alternative being a script is a program which has to be read and interpreted by another program. This causes a major decrease in performance as the CPU had to run a program that will read the script character by character and perform a lot of lookup functions to perform the same tasks.

The in-between option is using a virtual machine language which produces a sort-of half compiled program. This is similar to LLVM, Java or the .NET CLR. All three options allow a program to be made smaller, can be run byte for byte or by an interpreter or can compile the code on the machine where it will be run. This is the ideal solution as the code can be compiled to run optimally on the end user's machine instead of trying to optimize code for all possible systems.

What is difference function prototype and function define in turbo c?

In C, a function prototype is a declaration to the compiler that a certain function exists, without a full definition. This allows other functions to call that function. The linker will later make sure that a function definition actually exists (perhaps somewhere else), and will turn the call to the function to a call to the correct function.

Why use the void display()?

void display is the function name in which we want to perform some task or it might be to display something. But it has got its residence in the main() function that means that function's inputs are being supplied from the main(). void doesn't return anything so function call is made in main() which doesn't return anything back to it.

Write a C function to sort two dimensional integer array in ascending order?

Here's an example using a bubble sort. Note that this is not a very efficient sort, but it works weel enough with small data sets.

#include

#include

int main(void)

{

int item[100];

int a, b, t;

int count;

/* read in numbers */

printf("How many numbers? ");

scanf("%d", &count);

for(a = 0; a < count; a++)

scanf("%d", &item[a]);

/* now, sort them using a bubble sort */

for(a = 1; a < count; ++a)

for(b = count-1; b >= a; --b) {

/* compare adjacent elements */

if(item[ b - 1] > item[ b ]) {

/* exchange elements */

t = item[ b - 1];

item[ b - 1] = item[ b ];

item[ b ] = t;

}

}

/* display sorted list */

for(t=0; t

return 0;

}

How to print ASCII values using c?

Well in C++:

#include <iostream>

int main()

{

char x;

for(int i = 0; i < 255; i++)

{

x = i;

std::cout << i << "\t" << x << std::endl;

}

char wait;

std::cin >> wait;

return 0;

}

Define basic structure of c program?

Documentation section

link section

definition section

Global declaration section

main() function section

{

Declaration part

Executable part

}

subprogram section

(user defined function)

By jancy

Answer: Doesn't really have a structure, but there are some rules you have to follow:

- function-definitions cannot be nested;

- in a code-block, data declaration/definitions must come before the executable statements

What are tokens in c language?

in c program the smallest individual unit is called c-token

Examples of automatic variables in c?

Automatic variables are variables that are declared within the scope of a block, usually a function. They exist only within that scope, i.e. that block, and they cease to exist after the block is exited. These variables are usually allocated from the stack frame.

Example a program using two dimensional array multiplication table?

#include <stdio.h>

int main() {

int TimesTable[12][12] = { {1,2,3,4,5,6,7,8,9,10,11,12}, {1,2,3,4,5,6,7,8,9,10,11,12} };

int a, b;

for (a = 1; a <= 12; ++a) {

for (b = 1; b <= 12; ++b) {

TimesTable[a][b] = a*b;

printf("%5d", a*b);

}

printf("\n\n");

}

return 0;

}

How is object oriented programming language easier to use than procerdural programming language?

object oriented programing helps better modeling the world as we humans see it, while functional and procedural programming is for the mathematicians P.O.V. harder to maintain the code, and for me , harder to understand imperative(functional) code over side effect code(OOP) OOP is more intuitive by the grasp of the model to the mind, as it stands to help better model the mind, though most developers i have see so far, can really make a good simulation for the world in order for the code to be more coherent. OOP is Object Oriented Programming P.O.V is Point Of View

Which data structure is Best for library management system wheater Tree or Linked list?

It depends on what you intend to do with the data. The assumption is the data is dynamic, the number of elements are not known in advance. Binary trees are best if you want to sort the data as it is entered. Linked lists are best if you simply want a list of sequential data, or need to implement a stack or a queue.

What is the header file for gotoxy in c?

There is no such function as gotoxy(). It was originally a standard function in conio.h, used to set the console cursor position, but it was deprecated because it was non-portable. While it may still exist in older C compilers, its usage would be frowned upon today and no known C or C++ compiler should support such a function these days.

You are free to "roll your own" version of the function, of course. The following version works on Windows only. But given how little it actually adds to what already exists, and its non-portable nature it hardly seems worthwhile.

#include <stdio.h>

#include <conio.h>

#include <windows.h>

// Standard version:

void gotoxy( COORD c )

{

SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), c );

}

// Overloaded version emulating original gotoxy function:

void gotoxy( int x, int y )

{COORD c;c.X = x;c.Y = y;

gotoxy( c ); // call standard version

}

Write programme for sum of number given?

// this v'll work to obtain sum of 1st and last number of any number

#include

int main()

{

int num,sum=0,i,fd,ld;

printf("enter the number);

scanf("%d",&num);

ld=n%10; //will get the last digit

while(num!=0)

{

fd=n;

n/10; //to get the 1st digit

}

sum=fd+ld; //add 1st n last digit

printf("\n sum of 1st n last digit is %d",sum)

}

The depth of a complete binary tree with n nodes is-?

The number of elements in a complete, balanced, binary tree is N = 2D - 1, where D is the depth. Simply solve for D...

N = 2D - 1

N + 1 = 2D

log2 (N + 1) = D

Why null values in database?

The 'null'-content of any given field is just that. It's a 'nothing'. Example, if you create a database to hold chemical values for instance. If the values are, for example, real nubers. That would imply that any value that has 0 in it, is just that; zero. It was beeing measured, and found to contain zero. On the other hand if a value was not tested, the value of that compound should be set to 'null'. If a 'null' value isn't supported by the database a workaround is to set 'null' values to -1 (as per the example above). --

C program to calculate average using while loop?

//to calculate using while

#include<stdio.h>

#include<conio.h>

void main()

{ int count

float average,sum;

sum=0;

count=0;

while(count<N)

scanf("%f",n)

sum=sum+count

count=count+1

}

average=sum/n