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 create a Pascal triangle using only one 'for' loop using C?

int factorial (int n)

{

if (n==0) return 1;

else return (n*factorial(n-1));

}

int combo (int n, int r)

{

return (factorial (n))/(factorial (r) * (factorial (n-r)));

}

int width(int n, int i, int j)

{

return(j==0?(((n+1)*2)-((i==0)?i:(i-j))):(j<=3)?j+1:j-1);

}

void print (int n)

{

int i, j;

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

{

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

{

printf ("%*d", width(n,i,j) ,combo (i, j));

if (i==j)

{

printf("\n");

}

}

}

}

int main ()

{

int row,col;

int maxrow;

printf("\nPlease enter the num of rows for pascal triangle : ");

scanf("%d",&maxrow);

printf("The Pascal Triangle for %d rows is :\n",maxrow);

print(maxrow);

printf("To get the value at any row, col please enter \nRow:");

scanf("%d",&row);

printf("Col:");

scanf("%d",&col);

printf("\nThe value at row %d & col %d is : %d\n",row,col,combo(row,col));

}

Should an optimizing compiler for C or C plus plus be allowed to change the order of sub-expressions in a Boolean expression?

This is definitely a homework question (I'm working on it right now) so I think it's best that you answer this yourself. :)

How do you loop with Yamaha djx?

You cannot loop a sequence you have to play it out for as long as you want the beat to be. Or you can record 4-8 bars and record each track to a computer software program then manually loop them by copy & pasting. From there you can track, & mix a whole song with break downs and everything.

Back in the late 90s a friend of mine had this keyboard and he could remake any beat he heard on the radio but the downside was the keyboard didnt loop.

How do I write a program that inputs the length of two pieces of fabric in feet and inches as whole numbers and prints the total?

#include <stdio.h>

int main (void) {

unsigned f1, i1, f2, i2;

scanf ("Enter the 1st length in feet and inches: %u%u", f1, i1);

scanf ("Enter the 2nd length in feet and inches: %u%u", f2, i2);

unsigned inches = i1 + i2 + (12 * (f1 + f2)); // sum the inches (convert feet to inches)

unsigned feet = inches / 12; // convert inches to feet

inches %= 12; // determine the remaining inches

printf ("The total length is %u feet %u inches.\n", feet, inches);

return 0;

}

What is Multiprogramming in C language?

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

{

printf("\nEnter an integer value:");

scanf("%d",&x);

if(x == 0)

y(j) = 0;

if(x != 0)

y(j) = 10;

}

What does implicit in c language means?

Implicit in c means compiler understands what and how to do without any reference of any keyword or token.

How does open source products relate in a programming language?

We have two kinds of programming languages, Open Source and Close Source :)

Open Source like javascript and Close Source ":)" like .exe files (Compiled Files)

Open Source files like javascript wont be compiled and will be used as it wrote. if you think php is open source or not, i should tell you it's a different thing, the first thing you should be worry about is the security, javascript is open source and open source files are less or even unsecured files, it means everyone can see your source code, they can break down your security easily..

So what you should do? USE SOME ENCIPHER PROGRAM TO MAKE IT HARDER TO BREAK DOWN (it will just make it harder.. not impossible)

Close Source (Complied Files) are those that you write an code then it will be complied to something else to be understand by computers, like you write c# codes in Visual Studio and when you want to run it, your codes will be compiled to an exe application, then your computer will be able to run it.

Compiled Files is more secure but keep it in mind it don't mean it's unbreakable.. nowdays there are reverse programs out there.. :)

Wish i got your question right.. :)

Are loop colostomies permanent?

A loop colostomy is most often performed for creation of a temporary stoma to divert stool away from an area of intestine that has been blocked or ruptured.

What is the statements written by the programmer are called?

They are called statements. They have no other special name. A group of statements are called "Block statements".

Models of distributed computer system?

•Minicomputer model (e.g., early networks)

-Each user has local machine

-Local processing but can fetch remote data (files, databases)

•Workstation model (e.g., Sprite)

-Processing can also migrate

•Client-server Model (e.g., V system, world wide web)

-User has local workstation

-Powerful workstations serve as servers (file, print, DB servers)

•Processor pool model (e.g., Amoeba, Plan 9)

-Terminals are Xterms or diskless terminals

-Pool of backend processors handle processing

Weddle's rule in C programming language?

Code for TRAPEZOIDAL RULE in C Programming#include #include #include void main() { float x[10],y[10],sum=0,h,temp; int i,n,j,k=0; float fact(int); clrscr(); printf("\nhow many record you will be enter: "); scanf("%d",&n); for(i=0; i

Program of Matrix Chain Multiplication in c language?

# include <stdio.h>

# include <conio.h>

# include <stdlib.h>

# define sz 20

# define INF 200000

void print(unsigned long s[][sz], int i, int j)

{

if (i == j)

printf(" A%d ",i);

else

{

printf(" ( ");

print(s, i, s[i][j]);

print(s, s[i][j] + 1, j);

printf(" ) ");

}

}

void printm(unsigned long m[][sz], int n)

{

int i,j;

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

{

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

{

printf("%5d",m[i][j]);

}

printf("\n\n");

}

printf("\nThe No. of multiplication required is : %d",m[1][n]);

}

void Matrix_Chain_Order(int p[],int num)

{

unsigned long m[sz][sz] = {0};

unsigned long s[sz][sz] = {0};

unsigned int q = 0;

int i, j, k, l;

int n = num;

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

m[i][i] = 0;

for(l = 2; l <= n; l++)

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

{

j = i + l - 1;

m[i][j] = INF;

for(k = i; k <= j - 1; k++)

{

q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];

if(q < m[i][j])

{

m[i][j] = q;

s[i][j] = k;

}

}

}

print(s, i-1, j);

printf("\n\n");

printf("The Minimum No. of Multiplication Required is:\n\n");

printm(m,n);

}

void main()

{

int i,num=0,p[sz]={0};

clrscr();

printf("Enter the number of matrix : ");

scanf("%d",&num);

printf("Enter %d no. of order sequence for %d matrix :\n",num+1,num);

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

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

printf("\n\n");

printf("MULTIPLICATION SEQUENCE IS : ");

printf("\n\n\t");

Matrix_Chain_Order(p,num);

getch();

}

What do you mean by linearity in parameter and linearity in model?

Any model can be linear/nonlinear. Linearity can be in parameters or in variables.

In Y=a+ b*x1 + c*x2 + d*x3

the model is linear in both parameters (b,c,d) and variables(x1,x2,x3)

In Y=a+ (b+c)x1 + c*x2 + d*x3

the model is nonlinear in parameters (b,c,d) and linear in variables(x1,x2,x3)

In Y=a+ bx1 + c*x2*x3 + d*x3

the model is linear in parameters (b,c,d) and nonlinear in variables(x1,x2,x3)

In Y=a+ bx1 + c*x2*x3 + exp(b+d)*x3

the model is nonlinear in parameters (b,c,d) and nonlinear in variables(x1,x2,x3)

Does the C plus plus in computer language stand for Cobalt?

C was made in the 70s. Smalltalk was made in the 70s. Squeak was made in 1996, Croquet in 1999, and cobalt in 2007

C was the third in a progression of three languages named A, B, C, from what I heard

A is actually BCPL I think

BCPL B C C++ (P was taken for pascal p-code)

Which came first C or Unix?

Unix was created first. The C programming language was created for Unix.

How can you determine the byte offset of a field within a structure?

For C++ you can do this:

#define member_offset(Struct, Field) (&(reinterpret_cast(0)->member))

because the byte offset is usually the structure address + offset, so by setting the address to 0, you get 0 + offset == offset.


AnswerYou should the "offsetof" macro. This is a standard macro that has been a part of the C standard for 20 years now (it's part of C89 and C99), so all C and C++ compilers should support it.

#include
size_t offsetof(type, member);

For example:

struct s { int x, y; };
offsetof(struct s, y);

How do you name a batch program?

Assuming you mean a shell script (AKA batch file), you simply add a .bat as the extension to any plaintext file. There is no limitation for the actual filename aside from this (except for regularly unallowed charachters like > and /). For instance, if you wanted to name your batch file hello world, you would open up a new notepad document, enter your code, then save as File Name: hello world.bat and change the Save as Type: All Files. Windows automatically recognizes any file with the .bat extension as an executable batch file, so to run it, you would just double-click it like any other document or file. To edit the batch file again, you can right click it and select Edit, or use notepad to open it from its respective location. Hope that answers your question.

How do you convert hexadecimal 542 to binary?

Write each hexadecimal digit straight into binary:

5 = 0101

4 = 0100

2 = 0010

So 0x542 = 0101 0100 0010 = 10101000010 (without the spaces).

Hex digit to binary conversion:

0 = 0000, 1 = 0001, 2 = 0010, 3 = 0011

4 = 0100, 5 = 0101, 6 = 0110, 7 = 0111

8 = 1000, 9 = 1001, a = 1010, b = 1011

c = 1100, d = 1101, e = 1110, f = 1111

How do you make a proposal in C programming?

#include <stdio.h>

int main (void)

{ puts ("Marry me");

return 0; }

What is local declaration?

Declarations inside a function is called local declaration