How do you change the color of background of output screen in c program?
Platform-dependent. For TurboC use functions of header conio.h (use built-in help).
What is the advantage of an outline function?
Outline functions are primarily advantageous in debug code. By default, functions are never inline expanded in debug code (where NDEBUG is not defined) because debug code should never be optimised. This is simply because it much easier to map the assembly to the source code using outline functions.
In release builds (where NDEBUG is defined), functions are only inline expanded when there is an advantage in doing so. Trivial one-line functions are good candidates, as are complex functions that are only invoked in one place. Functions that increase code size are rarely good candidates so these will remain outline functions. Note that the programmer has no real control over which functions will be inline expanded. In particular, the inlinekeyword has had no bearing on inline expansion since 1998; it is used solely as a linkage directive when defining a non-member function in a header.
What are the disadvantage of linker?
Linkers can introduce additional overhead during the linking process, potentially increasing build times, especially in large projects with many dependencies. They may also lead to larger executable sizes due to the inclusion of unnecessary code or libraries. Additionally, debugging can become more complex, as issues may arise from how different modules interact, making it harder to trace errors back to their source.
Write a Programs in C for Fabonic Series?
I am going to assume you want a program to print out the Fibonacci series.
#include <stdio.h>
int main(int argc, char **argv)
{
if (argc < 2) {
printf("Usage: %s max\n", argv[0]);
return -1;
}
int a = 1, b = 1, c;
int max = atoi(argv[1]);
printf("%d %d ", a, b);
while (b < max) {
c = a + b;
a = b;
b = c;
if ((b <= max)) printf("%d ", b);
}
printf("\n");
return 0;
}
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();
}
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.
How do you overcome drawbacks of linked list?
Overcoming the "drawbacks" of a linked list requires knowing what drawback is at stack.
If you need to iterate backwards as well as forwards, then you could create a doubly linked list.
If you need to search for elements quickly, then you could implement a binary tree.
If you have a static size, then you could implement an array.
It's all a matter of tradeoff, and of what your particular issue is...
Its badsector...
According to my self disadvantage of link list that searching in link list is sequential if you compare it with arrays its very slow. Because in link list we have to search every node for that. if any one uses binary tree that is in some cases more faster than arrays.
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.
How do you write the following numbers as the sum of two primes a. 50 b. 36 c. 44?
43 + 7 = 50
17 + 19 = 36
41 + 3 = 44
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];
}
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 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.
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);
#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;
}
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(); }