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

Which programming language uses a string of 1s and 0s?

You, as a programmer, can use a string with 1s and and 0s (or any other content) in each and every programming language.

Where are trees in data structures implemented in the real world?

First off, there are several types of trees in data structures. each with different uses and benefits. The two most common are binary trees and binomial trees.

Binary trees are used most commonly in search algorithms. The benefits of this is that a search can be performed in O(lg(n)) time, instead of the O(n) time that a sequential search takes. An example from the real world of a binary tree in action is in databases, where indexes are organized in a binary tree, thus enabling faster searching.

Binomial trees are usually used in communication, particularly when distributing or aggregating information. A real world example comes from supercomputers, where multiple processors are all working simultaneously. In order to aggregate or distribute data, a binomial tree structure is commonly employed.

Using conditional operator find a biggest number among two numbers?

Here is an example in Java: int a = 5; int b = 7; System.out.println(a > b ? a : b);

Here is an example in Java: int a = 5; int b = 7; System.out.println(a > b ? a : b);

Here is an example in Java: int a = 5; int b = 7; System.out.println(a > b ? a : b);

Here is an example in Java: int a = 5; int b = 7; System.out.println(a > b ? a : b);

What do mean by structural programming?

Structured programming is a programming paradigm. Prior to structured programming, code was typically written with intertwining jumps or gotos producing "spaghetti" code which is difficult to both read and maintain. Structured programming primarily added subroutines and loop control statements and was later extended by procedural programming which primarily added function calls (not to be confused with functional programming) and which also made exception handling that much easier to maintain. This then led to object-oriented programming.

Program in 'c' to find the LCM of any given five numbers?

Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.

Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.

Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.

Just write a method or function that calculates the LCM for two numbers at a time. Then calculate the LCM for the first two numbers, get the LCM of the result with the third number, etc.

What is the name of the C compiler used by Linux?

gcc is the most common C-compiler for GNU/Linux platform.

What is use of user defined data in c?

to create user defined functions the user defined data is needed nd its useful to the programmer to create its own data.

Why c language is powerful?

C++ is general-purpose and portable, which is common to many high-level languages, but it excels in terms of performance, comparable to that of assembly language. This is not surprising given the amount of work that goes into optimising the native machine code that the C++ compiler produces.

Java is arguably more popular today (especially with amateur programmers), but it doesn't perform well when compared to C++. This is largely due to the much higher level of abstraction which requires compiled programs to be executed and interpreted by the Java virtual machine. The main advantage of Java is that the abstraction allows Java programs to be run on any platform that supports the JVM without the need to modify the source code and recompile, which is the main disadvantage of C++. However, in terms of performance alone, few languages can compete with C++, hence its huge popularity in the community.

Who is the father is c language?

Sorry to disappoint you, but you cannot father a programming language. But you can invent one, like Dennis Ritchie did with C forty years ago.

Write a c plus plus program to find the largest and second largest number from an array?

#include <iostream.h>

#include <conio.h>

class largest

{

public:

int a[10],i,b,s;

void get();

};

void largest :: get()

{

cout<<"Enter the numbers"<<endl;

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

{

cin>>a[i];

}

b=0;

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

{

if(b>=a[i])

b=b;

else

b=a[i];

}

cout<<"Largest No-"<<b<<endl;

s=0;

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

{

if((s>=a[i])&&(s!=b))

s=s;

else

s=a[i];

}

cout<<"Second Largest No-"<<s<<endl;

}

void main()

{

clrscr();

largest l;

l.get();

getch();

}

Code in c to draw line?

// macros for simplicity

#define MAX(x,y) (x>y?x:y)

#define MIN(x,y) (x<y?x:y)

/*

** drawLine

**

** Draw a line from vertex (x0,y0) to vertex (x1,y1) using

** the midpoint line algorithm, implemented using OpenGL.

**

*/

void drawLine( GLint x0, GLint y0, GLint x1, GLint y1 ) {GLint dE, dNE, x, y, d, dx, dy;

// check if we need to switch the points

if( x0 > x1 ) {

x0 = x0 + x1;

x1 = x0 - x1;

x0 = x0 - x1;

y0 = y0 + y1;

y1 = y0 - y1;

y0 = y0 - y1;}

// calculate deltas

dy = y1 - y0; dx = x1 - x0;

// special cases

if( dx -1 - diag down-right

glBegin(GL_POINTS);

for( x = x0, y = y0; x <= x1; x++, y-- ) {

glVertex2i(x,y);}

glEnd();}else { // general cases

// midpoint algorithm

if( abs(dy) < dx ) { // small slope

dE = 2 * abs(dy);

dNE = 2 * (abs(dy) - dx);

d = dE - dx;

glBegin(GL_POINTS);

for( x = x0, y = y0; x <= x1; x++ ) {

glVertex2i(x,y);

if( d <= 0 ) {

d+= dE;}else {

y += (dy>0?1:-1);

d += dNE;}}// for x = x0 to x1

glEnd();}else { // large slope

dE = 2 * dx;

dNE = 2 * (dx - abs(dy));

d = dE - abs(dy);

glBegin(GL_POINTS);

for( x = x0, y = y0; (y0 < y1 && y <= y1)

(y0 > y1 && y >= y1); y+=(y0 < y1?1:-1) ) {

glVertex2i(x,y);

if( d <= 0) { x ++;

d+= dE; }else { d += dNE; }}// for y = y0 to y1

glEnd();}}

}// drawLine()

Where the local variables will be stored?

When you declare a variable and it's data type in a function, it is stored in the specific space for memory allocated by the variable type identifier known as the "stack."

C program for knapsack algorithm?

#include<stdio.h>

#include<conio.h>

int w[10],p[10],v[10][10],n,i,j,cap,x[10]={0};

int max(int i,int j)

{

return ((i>j)?i:j);

}

int knap(int i,int j)

{

int value;

if(v[i][j]<0)

{

if(j<w[i])

value=knap(i-1,j);

else

value=max(knap(i-1,j),p[i]+knap(i-1,j-w[i]));

v[i][j]=value;

}

return(v[i][j]);

}

void main()

{

int profit,count=0;

clrscr();

printf("\nEnter the number of elements\n");

scanf("%d",&n);

printf("Enter the profit and weights of the elements\n");

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

{

printf("For item no %d\n",i);

scanf("%d%d",&p[i],&w[i]);

}

printf("\nEnter the capacity \n");

scanf("%d",&cap);

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

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

if((i==0)(j==0))

v[i][j]=0;

else

v[i][j]=-1;

profit=knap(n,cap);

i=n;

j=cap;

while(j!=0&&i!=0)

{

if(v[i][j]!=v[i-1][j])

{

x[i]=1;

j=j-w[i];

i--;

}

else

i--;

}

printf("Items included are\n");

printf("Sl.no\tweight\tprofit\n");

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

if(x[i])

printf("%d\t%d\t%d\n",++count,w[i],p[i]);

printf("Total profit = %d\n",profit);

getch();

}

What is the C program for byte stuffing with the output?

//Sender

#include<string.h>

#include<stdio.h>

#include<unistd.h>

#include<fcntl.h>

#define SIZE 40

struct frame

{

char str[SIZE+1];

char tmp[2*SIZE];

char flag;

char e;

char final[2*SIZE];

}s;

main()

{int fd,len1;

int i,j,len;

fd=open("b1",O_WRONLY);

printf("\nEnter flag character and escape character for byte-stuffing:");

scanf("%c %c",& s.flag,&s.e);

printf("\nEnter string:");

scanf("%s",s.str);

len=strlen(s.str);

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

{

if(s.str[i]==s.flag)

{

s.tmp[j]=s.e;

s.tmp[j+1]=s.flag;

j++;

continue;

}

else if(s.str[i]==s.e)

{

s.tmp[j]=s.e;

s.tmp[j+1]=s.e;

j++;

continue;

}

else

{

s.tmp[j]=s.str[i];

}

}

printf("\nAppended string is==>%s \n",s.tmp);

len1=strlen(s.tmp);

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

{

if((i==0)(i==len1))

{

s.final[j]=s.flag;

s.final[j+1]=s.tmp[i];

j++;

continue;

}

else

{

s.final[j]=s.tmp[i];

}

}

printf("\nFianal string is==>%s\n",s.final);

write(fd,&s,sizeof(s));

}

//Reciver

#include<string.h>

#include<stdio.h>

#include<unistd.h>

#include<fcntl.h>

#define SIZE 40

struct frame

{

char str[SIZE+1];

char tmp[2*SIZE];

char flag;

char e;

char final[2*SIZE];

}r;

main()

{

int fd,len1;

int i,j,len;

mknod("b1",010666,0);

fd=open("b1",O_RDONLY);

read(fd,&r,sizeof(r));

printf("\nFlag character is==>%c\n",r.flag);

printf("\nEscape character is ==>%c\n",r.e);

printf("\nAnd actual message was ==>%s\n",r.str);

printf("\nReceived message is %s\n\n",r.final);

}

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

[mca222@rcclinux mca222]$ cc -os byte_s.c

[mca222@rcclinux mca222]$ cc -or byte_r.c

[mca222@rcclinux mca222]$ ./r&

[1] 1570

[mca222@rcclinux mca222]$ ./s

Enter flag character and escape character for byte-stuffing:#

@

Enter string:sim#andh@ar

Sending message is==>#sim@#andh@@ar#

Flag character is==>#

Escape character is ==>@

And actual message was ==>sim#andh@ar

Received message is #sim@#andh@@ar#

What is a complier in computer language?

A compiler is a program that translates a programming language (like c++, java, pascal, php etc...) to a language that computers can "understand" (i.e. "1001010110101010...")

How do you write a c program that reads a six digit integer and prints the sum of its six digits?

int sum_digits (int num) {

int sum;

sum =0;

while (num) {

sum += num % 10;

num /= 10;

}

return sum;

}

Example usage:

int main (void) {

int i;

printf ("Input a 6-digit number: ");

scanf ("%6d", &i);

printf ("The sum of the digits in %d is: %d\n", i, sum_digits (i));

return 0;

}

Why can't we perform binary search in linked lists?

The binary search algorithm depends on equal (or direct) access time for any selected element of a list. A linked list, however, does not provide that, so a binary search is inappropriate for a linked list.

Write an algorithm find out the sum of first n odd numbers?

Algorithm: sum_even

Input: an integer, n, such that n>0

Output: the sum of all even integers within the open range (1:n)

sum := 0

val := 2

while (val < n) do

{

sum := sum + val

val := val + 2

}

return sum

Note that you explicitly specified between 1 and n, which literally means both 1 and n should be excluded from the sum. 1 would be excluded anyway since it is not an even number, however if we wish to include n, then use the following algorithm instead:

Algorithm: sum_even

Input: an integer, n, such that n>0

Output: the sum of all even integers within the half-open range (1:n]

sum := 0

val := 2

while (val <= n) do

{

sum := sum + val

val := val + 2

}

return sum

Write a program in C language to implement the apriori algorithm?

JavaScript is one program that has been written in C to implement the Apriori algorithm. There are also several other known programs available on the Internet that implement it as well.