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

What are uses of return () statements?

The return statement has only one purpose: to return control back to the calling function.

Although return statements are not required in void functions, return statements can be placed anywhere in any function, void or not. For example:

void f (int x) { // x must be non-zero!

if (!x) return;

// ...

}

In the above example, a precondition is stated in a comment but compilers do not read comments therefore we must test that precondition at runtime. If the precondition fails, then there is no point in continuing any further, so it makes sense to return control to the caller. In a real-world example, we'd set an error condition before returning so that the caller can determine what went wrong.

Note that if we do not put a return statement in a void function, the function automatically returns at the end of the function. This is not the case for functions that return a value; we must explicitly return that value through a return statement. However, we can place the return statement anywhere that is convenient and we can include as many return statements as required. For example:

int g (int x) {

if (!x) return 0;

if (x<=10) return 1;

if (x<=20) return 2;

return 3;

}

In the above example we return the value 0 when x is zero, return 1 when x is in the range 1 to 10, return 2 when x is in the range 11 to 20 and return 3 in all other cases.

The previous example can also be written more succinctly (less verbosely) using the ternary operator:

int g (int x) { return !x ? 0 : (x<=10) ? 1 : (x<=20) ? 2 : 3;

}

However, a good compiler will produce the exact same machine code regardless of how we write the function, therefore it makes sense to use the version that is more readily understood by the reader. After all, code that is easy to understand is generally much easier to maintain.

What are the various operations in linked list which can be performed on linked list?

In linked list, there are various operations in linked list that you can perform on linked list, eg: adding new elements, deleting elements, getting the first element, getting the next element after an element, any many others.

What is the purpose of the national provider identifier?

The National Provider Identifier (NPI) is a unique identification number assigned to healthcare providers in the United States. Its primary purpose is to streamline the billing and identification process within the healthcare system, ensuring that providers are easily recognized by insurers and other entities. The NPI also helps improve the efficiency of healthcare operations and enhances the accuracy of patient records and claims processing. By standardizing provider identification, the NPI facilitates better communication and coordination among healthcare stakeholders.

Is it possible for the price level to fall while produstion and emplyment both riseIf it is possible how could this happen If it is not possible explain why not?

The price for a product might fall while production and employment both rise if there is no longer a demand for the product. If there is a product so new on the market that it takes over for another product, while the first product is still in high production, the price of the first object is going to fall because the demand is lost.

Can stack be called fifo data structure?

No. A stack is a LIFO (Last In First Out) data structure.

A queue is a FIFO (First In First Out) data structure.

Write a c program to print all combination of a 4 digits number?

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,k,l,m;

clrscr();

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

{

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

{

printf("%d",j);

}

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

{

printf("%d",k);

}

printf("\n");

for(k=i;k>=1;k--)

{

printf("%d",k);

}

for(j=4;j>=i+1;j--)

{

printf("%d",j);

}

getch();

}

What are Axioms of a binary tree?

A binary tree is a finite set of nodes which is either empty or consists of a root and two disjoint binary trees called the left subtree and the right subtree.

We can define the data structure binary tree as follows:

structure BTREE

declare CREATE( ) --> btree

ISMTBT(btree,item,btree) --> boolean

MAKEBT(btree,item,btree) --> btree

LCHILD(btree) --> btree

DATA(btree) --> item

RCHILD(btree) --> btree

for all p,r in btree, d in item let

ISMTBT(CREATE)::=true

ISMTBT(MAKEBT(p,d,r))::=false

LCHILD(MAKEBT(p,d,r))::=p; LCHILD(CREATE)::=error

DATA(MAKEBT(p,d,r))::d; DATA(CREATE)::=error

RCHILD(MAKEBT(p,d,r))::=r; RCHILD(CREATE)::=error

end

end BTREE

What number is equivalent to -4e3 in c language?

In C, it is -4000.0

In others languages, it is -4000.0

How do i find the current cursor position in C program?

You cannot do that "in C" but can in TurboC:functions wherex and wherey are you friends. Consult the help.
The cursor position, also known as the mouse position, is a function of the operating system, more specifically, not a function of the current window. Other than by hooking the mouse, a complex topic, there is no way to determine the current cursor position.

For TurboC: WhereX WhereY from conio.h

Write a program in 'C' to find perfect number?

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,sum;

clrscr();

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

{

j=1;

sum=0;

while(j<i)

{

if(i%j==0)

sum=sum+j;

j++;

}

if(sum==i)

printf("%d\n",i);

}

getch();

}

What is 15-12?

3 *Gee, that was not easy*

Sum of all the digits of a number for while loop?

#include<stdio.h>

void main()

{

int n,sum=0;

clrscr();

printf("enter the value"):

scanf("%d",&n);

do

{

sum=sum+n;

n=n-1;

printf("sum is %d"<sum);

}

while(n>0)

getch();

}

Write a program to generate CRC?

/*

written by: Bibhakar Jha;

objective : to implement CRC in c programming language;

*/

//Program code to add CRC check bit

#include

#include

#define N strlen(g)

char t[28],cs[28],g[]="10001000000100001";

int a,e,c;

void xor()

{

for(c = 1;c < N; c++)

cs[c] = (( cs[c] == g[c])?'0':'1');

}

void crc()

{

for(e=0;e

cs[e]=t[e];

do{

if(cs[0]=='1')

xor();

for(c=0;c

cs[c]=cs[c+1];

cs[c]=t[e++];

}while(e<=a+N-1);

}

int main()

{

clrscr();

printf("\nEnter data : ");

scanf("%s",t);

printf("\n----------------------------------------");

printf("\nGeneratng polynomial : %s",g);

a=strlen(t);

for(e=a;e

t[e]='0';

printf("\n----------------------------------------");

printf("\nModified data is : %s",t);

printf("\n----------------------------------------");

crc();

printf("\nChecksum is : %s",cs);

for(e=a;e

t[e]=cs[e-a];

printf("\n----------------------------------------");

printf("\nFinal codeword is : %s",t);

printf("\n----------------------------------------");

printf("\nTest error detection 0(yes) 1(no)? : ");

scanf("%d",&e);

if(e==0)

{

do{

printf("\nEnter the position where error is to be inserted : ");

scanf("%d",&e);

}while(e==0 e>a+N-1);

t[e-1]=(t[e-1]=='0')?'1':'0';

printf("\n----------------------------------------");

printf("\nErroneous data : %s\n",t);

}

crc();

for(e=0;(e

if(e

printf("\nError detected\n\n");

else

printf("\nNo error detected\n\n");

printf("\n----------------------------------------\n");

getch();

return 0;

}

How do you write C program using graphics to draw a house?

#include < stdio.h >

#include < graphics.h >

#include< stdlib.h >

#include< conio.h >

void main()

{

int gm,x,y,gd=DETECT,i;

// int midx, midy;

int stangle = 45, endangle = 50;

int radius = 50;

initgraph(&gd,&gm,"z:\\tc\\bgi");

x=getmaxx();// to get the co-ordinates i.e. x & y

y=getmaxy();

cleardevice();

fflush(stdout);// this is the function in c to clean the screen

line(200,150,350,150);

line(140,200,200,150);

line(140,330,140,200);

line(250,200,140,200);

line(200,150,250,200);

circle(196,180,15);

setfillstyle(2,14);

floodfill(196,180,15);

setfillstyle(1,2);

line(350,150,400,200);

floodfill(210,180,15);

line(400,200,400,330);

line(140,330,400,330);

line(250,200,250,330);

line(250,200,400,200); // Hut

setfillstyle(5,7);

floodfill(260,180,15);

line(170,260,170,330);

line(170,260,210,260);

setfillstyle(10,9);

floodfill(180,250,15);

line(210,260,210,330);

setfillstyle(9,9);

floodfill(210,250,15);

line(290,110,290,150);

line(310,110,310,150);

ellipse(300,110,0,360,10,3); // Chemney

setfillstyle(6,8);

floodfill(300,120,15);

line(300,250,350,250);

line(300,280,350,280);

line(300,250,350,280);

line(300,280,300,250);

line(350,280,350,250);

setfillstyle(9,9);

floodfill(252,300,15);

setfillstyle(8,9);

floodfill(342,270,15);

// midx = getmaxx() /4 ;

// midy = getmaxy() /4 ;

// setcolor(getmaxcolor());

setcolor(2);

/* draw arc */

arc(30,300,stangle, endangle, radius);

setcolor(8);

line(5,330,600,330);

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

{

setcolor(4);

settextstyle(7,0,5);

outtextxy(0+i,390,"Home Sweet Home");

delay(100);

setcolor(0);

settextstyle(7,0,5);

outtextxy(0+i,390,"Home Sweet Home");

}

getch();

closegraph();

}

Cursor implementation of c program?

#include<stdio.h>

#include<conio.h>

#include"curslist.h"

void main()

{

LIST L=-1;

POSITION P;

int choice,place,x;

clrscr();

printf("\n1.Create\n2.Insert\n3.Delete\n4.MakeEmpty\n5.Display\n6.Find\n7.Exit");

A:

printf("\nEnter ur choice:\t");

scanf("%d",&choice);

switch(choice)

{

case 1:

if(L==-1)

{

InitializeCursor();

L=CursorAlloc();

}

else

printf("\nList is already created");

break;

case 2:

if(L==-1)

printf("\nList is not yet initialized");

else

{

printf("\nWhere u want to insert?");

scanf("%d",&place);

printf("\nEnter the element to insert");

scanf("%d",&x);

Insert(x,place);

}

break;

case 3:

if(L==-1)

printf("\nList is not yet initialized");

else

{

printf("\nWhich element you want to delete?");

scanf("%d",&x);

Delete(x,L);

}

break;

case 4:

if(L==-1)

printf("\nList is not yet initialized");

else

MakeEmpty(L);

break;

case 5:

if(L==-1)

printf("\nList is not yet initialized");

else

Display();

break;

case 6:

if(L==-1)

printf("\nList is not yet initialized");

else

{

printf("\nWhich element you want to search?");

scanf("%d",&x);

P=Find(x,L);

printf("\nThe element is at %d",P);

}

break;

case 7:

exit(0);

default:

printf("\n *******WRONG ENTRY*******");

}

goto A;

}

Write a c program to print mean median and mode?

#include<stdio.h>

#define MAXVAL 1000

void sort1(int a[],int n);

void median(int a[],int n);

void mode(int a[],int n);

int main()

{

int n;

int arr[MAXVAL];

int i;

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

scanf("%d",&n);

printf("Enter the values:");

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

{

printf("a[%d]=",i);

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

}

sort1(arr,n);

median(arr,n);

mode(arr,n);

}

void sort1(int a[],int n)

{

int i;

int j;

int temp;

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

{

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

{

if(a[i]>a[j])

{

temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}

}

}

void median(int a[],int n)

{

int median;

int mid;

if((n%2)==0)

{

mid=n/2;

median=(a[mid-1]+a[mid])/2;

}

else

{

mid=(n+1)/2;

median=a[mid-1];

}

printf("The median is:%d\n",median);

}

void mode(int a[],int n)

{

int i;

int count1[MAXVAL];

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

{

count1[i]=0;

}

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

{

count1[a[i]]++;

}

i--;

int mode=count1[0];

int j;

int k;

int flag=0;

for(j=0;j<=a[i];j++)

{

if(count1[j]>count1[mode])

mode=j;

}

for(j=0;j<=a[i];j++)

{

for(k=j+1;k<=a[i];k++)

{

if(count1[j]=count1[k] && count1[j]>count1[mode])

{

flag=1;

}

}

}

if(flag==1)

{

printf("Mode cannot be calculated");

}

else

printf("the Mode is:%d",mode);

}

What is logic to find the even and odd no without use of modulus and division?

If you're using C, just check the low order bit. In binary, the low order bit of an odd number is 1, and the low order bit of an even number is 0.

Can array size be determined using sizeof operator in c?

Yes. The array name is a reference to the array, so you can use sizeof (name) / sizeof (name[0]) to determine the number of elements. Note that sizeof (name) alone gives the length of the array in bytes.

What will be the difference in running time of the heap sort algorithm if you start to apply heap sort with an array elements rather than max heap elements?

The heap sort algorithm is as follows:

1. Call the build_max_heap() function.

2. Swap the first and last elements of the max heap.

3. Reduce the heap by one element (elements that follow the heap are in sorted order).

4. Call the sift_down() function.

5. Goto step 2 unless the heap has one element.

The build_max_heap() function creates the max heap and takes linear time, O(n). The sift_down() function moves the first element in the heap into its correct index, thus restoring the max heap property. This takes O(log(n)) and is called n times, so takes O(n * log(n)). The complete algorithm therefore equates to O(n + n * log(n)).

If you start with a max heap rather than an unsorted array, there will be no difference in the runtime because the build_max_heap() function will still take O(n) time to complete. However, the mere fact you are starting with a max heap means you must have built that heap prior to calling the heap sort algorithm, so you've actually increased the overall runtime by an extra O(n), thus taking O(2n * log(n)) in total.