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 number between 1 and 5 can array 3 times?

Please improve your question so we do not have to guess at what you are asking.

Is this a math, c Programming or algebra problem, please pick one because it cannot be all 3 at the same time.

Evaluate a post fix expression?

Okay, here is a postfix expression:

3 4 * 5 6 * +

the evaluation:

3*4 + 5*6

12 + 30

42

How do you convert decimal 23 from binary to decimal?

To convert a decimal number to binary, you simply need to divide by 2 and take note of the remainder.

Example:

23 / 2 = 11 Remainder 1

11 / 2 = 5 Remainder 1

5 / 2 = 2 Remainder 1

2 / 2 = 1 Remainder 0

2 / 1 = 0 Remainder 1

The answer is therefore 10111.

NB: If the question is to answer is 8-bit you must pad it out with zeroes as follows:

00010111

What is the program to input 5 numbers and find maximum of them?

#include

void input(double arr[], const int numElems);

double max(double arr[], const int numElems);

int main()

{

const int numElems = 5;

double arr[numElems] = {0.0};

input(arr, numElems);

std::cout << "Maximum is: " << max(arr, numElems);

std::cout << std::endl;

system("PAUSE");

return 0;

}

void input(double arr[], const int numElems)

{

std::cout << "Enter " << numElems << " elements." << std::endl;

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

{

std::cout << "Enter " << (i + 1) << " element: ";

std::cin >> arr[i];

}

}

double max(double arr[], const int numElems)

{

double maximum = arr[0];

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

{

if (maximum < arr[i])

{

maximum = arr[i];

}

}

return maximum;

}

*The code was compiled in VS2008/2010

Programme to find the count of each digit in a number using while loop?

Implement this method in Java:

public static int[] countNums(int n) {

int x = n;

int[] nums = new int[10];

while(x != 0) {

nums[x % 10]++;

x /= 10;

}

return nums;

}

That will return an array of the counts of the digits from 0 to 9.

How do you convert octal to binary with 2 decimal nos?

The conversion of octal number to binary can be obtained by using two methods. First, it can be converted into decimal and then obtained decimal is converted into binary. In the second method

What do you mean by a mod function?

A modulo function finds the remainder term when you divide one number by another number.

For example, if you divide 20 by 3 you're left with a remainder term of 2.

So 20 mod 3 = 2.

If you divide 21 by 3 you're left with no remainder term.

So 21 mod 3 = 0.

Write a program in C to print 1 to10 as 1 2 3 4 5 6?

int main() { for(int i = 1; i <= 10; i++)
printf("%d ", i);


return 0;
}

How do you convert Binary-to-Decimal and Decimal-to-Binary?

You can use a table to convert binary to decimal & back:

MSBBinary DigitLSB2827262524232221202561286432168421

Figure out the greatest power that will fit into the number you want to convert to binary. Move to the next lower power of two. If you can fit into the next lower number write down a "1", if it can't put down "0". Put together the binary answer.

How do you find the largest of 3 numbers in computer programming?

To find the largest of three numbers you must first find the largest of two numbers:

int max (int a, int b) { return a>b?a:b; // or, equivalently: if (a>b) return a; else return b;

}

Now we can use this function to find the maximum of three:

int max3 (int a, int b, int c) {

return max (max (a,b), c);

}

How do you calculate the volume of a circle?

Circles do not have volume because they are 2 dimensional. The area of a circle is PI*r2 . A sphere has volume and the volume of a sphere is 4/3*pi*r3 where r is the radius.

What is the value of B?

Hexadecimal B = Decimal 11. Otherwise, the question is too ambiguous.

What is the Program to find sum of first YT odd natural numbers in c?

Writing answers used to be enough.

Now we have to fix the questions too.

I think it's supposed to be 76, but who can really know.

ahhh, proofreading, it's such a lost art . . .

C program to find sum of two sparse matrices?

#include <stdio.h> #include <stdlib.h> typedef struct node { int column; int value; int row; struct node *next; } element; /* MENU */ void Menu() { printf("\n***\tADDING SPARSE MATRICES\t***\n"); printf("\n 1.) Insert in A"); printf("\n 2.) Insert in B"); printf("\n 3.) Printout both"); printf("\n 4.) A + B = "); printf("\n 0.) EXIT"); printf("\nChoose ---------> "); } /* Initialize*/ void Init (element *x[]) { int i; for (i=0; i<3; i++) x[i] = NULL; } /* Printout */ void Printout (element *x[]) { int i, test = 0; element *temp; for (i=0; i<3; i++) { temp = x[i]; while (temp != NULL) { printf("Element position (%d,%d) = %d\n", i, temp->column, temp->value); test = 1; temp = temp->next; } } if (test == 0) printf("This matrix is empty!!\n"); } /* INSERT */ void Insert(element *x[], int row, int column, int value) { int r = row; element *p; element *new = malloc(sizeof(element)); new->row = row; new->column = column; new->value = value; if (x[r] == NULL) { x[r] = new; new->next = NULL; } else { p = x[r]; if (new->column < p->column) { new->next = p; x[r] = new; } else if (new->column > p->column) { while (p->next != NULL && p->next->column < new->column) { p = p->next; } new->next = p->next; p->next = new; } else printf("An element already exists there!!\n"); } } /* A + B */ void Add (element *x[],element *y[],element *z[]) { int i; element *p, *q; for (i=0; i<3; i++) { /*row of x empty, row of y not*/ if (x[i] == NULL && y[i] != NULL) { q = y[i]; while (q != NULL) { Insert(z, i, q->column, q->value); q = q->next; } } /*row of y empty, row of x not*/ if (x[i] != NULL && y[i] == NULL) { q = x[i]; while (q != NULL) { Insert(z, i, q->column, q->value); q = q->next; } } /*row of x and y not empty*/ if (x[i] != NULL && y[i] != NULL) { p = x[i]; q = y[i]; /*stay in while loop until one row runs out*/ while (p != NULL q != NULL) { /*columns match*/ if (p->column == q->column && p != NULL && q != NULL) { Insert(z, i, p->column , p->value + q->value); p = p->next; q = q->next; } /*column of x is smaller than column of y*/ else if (p->column < q->column) { Insert(z, i, p->column , p->value); p = p->next; } /*column of x is bigger than column of y*/ else { Insert(z, i, q->column , q->value); q = q->next; } } /*if row of x had more elements and didn't run out*/ if (p != NULL) { while (p != NULL) { Insert(z, i, p->column , p->value); p = p->next; } } /*if row of x had more elements and didn't run out*/ if (q != NULL) { while (q != NULL) { Insert(z, i, q->column , q->value); q = q->next; } } } } Printout(z); } /* FREE MEMORY*/ void Freedom (element *x[]) { int i; element *p; for (i=0; i<3; i++) { if (x[i] != NULL) { p = x[i]; x[i] = x[i]->next; free(p); } } } /* MAIN */ int main (int argc, const char * argv[]) { int choice, column, row, value, number; element *a[3], *b[3], *sum[3]; Init(a); Init(b); Init(sum); do { Menu(); scanf("%d",&choice); switch (choice) { case 1: /*Insert in A */ do { printf("Enter row -> "); scanf("%d",&row); } while (row < 0 row > 3); do { printf("Enter column -> "); scanf("%d",&column); } while (column < 0); printf("Enter value -> "); scanf("%d",&value); Insert(a,row,column,value); break; case 2: /*Insert in B */ do { printf("Enter row -> "); scanf("%d",&row); } while (row < 0 row > 2); do { printf("Enter column -> "); scanf("%d",&column); } while (column < 0); printf("Enter value -> "); scanf("%d",&value); Insert(b,row,column,value); break; case 3: /* Printout A & B */ printf("\n::::::: MATRIX A :> \n\n"); Printout(a); printf("\n::::::: MATRIX B :> \n\n"); Printout(b); break; case 4: /* A + B */ Init(sum); printf("\n::::::: MATRIX A + B :> \n\n"); Add(a,b,sum); break; default: printf("\nWRONG CHOICE"); } } while (choice != 0); Freedom(a); Freedom(b); Freedom(sum); return 0;

}

Write a c program to find factors of given number?

#include<stdio.h>

void findfact(int num)

{

int i;

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

{

if(num%i==0)

printf("Factor for %d is %d\n",num,i);

}

}

main()

{

int a;

printf("\nEnter a number:");

scanf("%d",&a);

findfact(a);

}

Program in c finding average of two and three digits nos?

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,k,a[10],n;

clrscr();

scanf("%d",&n);

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

{

n=n%10;

j=0;

a[j]=n;

j++;

}

for(j=0;j>3;j++)

{

a[k]=0;

a[k]=a[k]+a[j];

avg=(a[k]/3);

printf("the average value of digit will be %d",avg);

}

getch();

}

}