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

If the statement in c program not terminated with semicolon what will it hinder?

Basically, because semicolons are required for terminating statements, it will hinder pretty much everything after the missing semicolon. Without it being there, the compiler will interpret your code incorrectly.

Write a program to calculate the area of a circle?

#include<stdio.h>

void main()

{

int r=10;

float pi=3.14,c;

c=pi*r*r;

printf("Area of the circle=%f",c);

getch();

}

When was Smooth Operator created?

Smooth Operator was created on 1984-09-15.

Write a program to generate the first 50 perfect numbers?

I don't believe that 50 perfect numbers have ever been found, last time I checked there were only about 47 known perfect numbers. It would also require an extremely powerful computer.

Write a program of displaying numbers in shape of triangles by using looping?

#include <stdio.h>

int main (void)

{

int i,j;

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

{

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

printf("%d",j);

printf("\n");

}

return 0;

}

What is a program to sort a two dimensional integer array?

Any multi-dimensional array can be flattened into a linear array. For instance,

[[1,2,3],[4,5,6],[7,8,9]]

can be flattened into

[1,2,3,4,5,6,7,8,9].

So a solution to your problem (certainly not the most efficient) would be to flatten the 2d array into a linear array, and sort using a traditional sorting algorithm or Arrays.sort. You would then insert the sorted elements back into the 2d array. This would have nlog(n) complexity.

An implementation below:

public static void sort2d(int[][] arr)

{

int r = arr.length;

int c = arr[0].length;

int[] flat = new int[r*c];

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

for (int j = 0; j < c; j++)

flat[i*c+j] = arr[i][j];

Arrays.sort(flat);

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

arr[i/r][i%c] = flat[i];

}

How do you toggle case of string in c code. Example is TogGle will turn into tOGgLE?

#include<stdio.h> int main() { char str[100]; int i; printf("Please enter a string: "); // gets(str); // fgets is a better option over gets to read multiword string . fgets(str, 100, stdin); // Following can be added for extra precaution for '\n' character // if(str[length(str)-1] == '\n') str[strlen(str)-1]=NULL; for(i=0;str[i]!=NULL;i++) { if(str[i]>='A'&&str[i]<='Z') str[i]+=32; else if(str[i]>='a'&&str[i]<='z') str[i]-=32; } printf("String in toggle case is: %s",str); return 0; }

How can we create an unsized array to c programme?

Use a pointer...

int a*;

a = malloc(sizeof(int)*100); //allocate space for 100 elements

free(a);

a = malloc(sizeof(int)*1000); // allocate space for 1000 elements

free(a);

How do you write a c function to produce a table of the numbers from 1 to 10their squares and their cubes?

#include<stdio.h>

const unsigned int rows = 10;

const unsigned int cols = 3;

int table[rows][cols];

int square (const int n) {

return n * n;

}

int cube (const int n) {

return n * n * n;

}

void initialise_table (void) {

int x, y, val;

for (x=0; x<rows; ++x) {

val = x+1;

table[x][0] = val;

table[x][1] = square (val);

table[x][2] = cube (val);

}

}

int main (void) {

int x, y;

initialise_table ();

printf ("Value\tSquare\tCube\n");

for (x=0; x<rows; ++x) {

printf("%d\t%d\t%d\n", table[x][0], table[x][1], table[x][2]);

}

return 0;

}

What happen when a c program passes an array as a function argument?

When an array name is passed as a function argument, the address of the first element is passed to the function. In a way, this is implicit call by reference. The receiving function can treat that address as a pointer, or as an array name, and it can manipulate the actual calling argument if desired.

Write a c programme to perform Lagrange's interpolation formula?

#include<stdio.h> #include<conio.h> #include<math.h> void

main() { float

x[10],y[10],temp=1,f[10],sum,p; int

i,n,j,k=0,c; clrscr(); printf("\nhow many record you will be enter: "

); scanf("%d"

,&n); for

(i=0; i<n; i++) { printf("\n\nenter the value of x%d: "

,i); scanf("%f"

,&x[i]); printf("\n\nenter the value of f(x%d): "

,i); scanf("%f"

,&y[i]); } printf("\n\nEnter X for finding f(x): "

); scanf("%f"

,&p); for

(i=0;i<n;i++) { temp = 1; k = i; for

(j=0;j<n;j++) { if

(k==j) { continue

; } else

{ temp = temp * ((p-x[j])/(x[k]-x[j])); } } f[i]=y[i]*temp; } for

(i=0;i<n;i++) { sum = sum + f[i]; } printf("\n\n f(%.1f) = %f "

,p,sum); getch(); }

Program to check whether the given number is an Armstrong number?

<html>

<head>

<Script Language="JavaScript">

var a,n,b=0,t;

n=parseInt(window.prompt("enter n","0"));

t=n;

while(n>0)

{

a=n%10;

b=b+a*a*a;

n=n/10;

}

if(b==t)

{

document.writeln("Armstrong no");

}

else

{

document.writeln("Not an Armstrong no");

}

</script>

</head>

</html>

How do you write a recursive function for summing ints?

for example "sumNums(12345)" would sum 1+2+3+4+5.

the recursive code is just really confusing me.

unsigned sumDigits (unsigned n)

{

. . if (n<10) return n;

. . else return n%10 + sumDigits (n/10);

}

Why array indexes starts from zero in c-language?

In order to provide modulo (%) facilities as far as mathematics and logic is concern.

for instance , if we have no of employees in our list say 1545 and if we want to accommodate it within small and effective range then by using % we can do it easily....

we can arrange it in the range within Array with maximum index 14 (0,1,2,.....14).

And 0,15,30,45......1545 will belongs to same category say index no 0.

Think if 0 is not included into index then where we would store 0,15,30,45....1530,1545 .

From a technical standpoint, you need to understand that an array is basically just the starting address of a chunk of memory. The "index" of the array is actually an address offset. So the value at the 0th position would be stored at the address of the array plus zero. The value at the 1st position would be stored at the address plus one, and so on.

What do you normally create when you want to run a function in the background while processing other things?

You normally create a thread when you want to run a function in the background while processing other things.

1's complement of 1000?

Ones complement simply switches the state of all the bits (0s becomes 1s and 1s becomes 0s). Assuming 1000 is binary (for decimal 8), the 1's complement would be 0111. But if 1000 is really decimal one thousand, the binary equivalent would 1111101000, thus the ones complement would be 0000010111.

Ones complement was originally used to represent signed integers. To flip the sign, all bits were flipped and the most-significant bit denoted the sign (0 for positive, 1 for negative). The problem with one's complement is that we end with two representations for the value zero: 00000000 and 11111111 in 8-bit notation. To eliminate this, most modern systems now use twos complement, which is ones complement plus one. Thus 00000000 is 11111111 + 00000001 which is 00000000.

Note that ones complement notation means that an 8-bit value has a valid range of -127 through +127 (with two representations for zero) while twos complement gives us a range of -128 through +127. Signed integer notation is also system-dependent, hence the reason why a char data type in C only has a guaranteed range of at least -127 through +127 across all implementations. For that reason it is not safe to assume that -128 has a valid representation in 8-bit signed notation across all implementations.