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 number is equivalent to -4e3 in c language?

In C, it is -4000.0

In others languages, it is -4000.0

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;

}

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();

}

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*

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;

}

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();

}

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.

What is an example of using recursive functions?

Let's take the example of finding the factorial of a number (of a positive integer). The factorial of N is N * (N-1) * (N-2) * (N-3) ... * 3 * 2 *1 It is the product of all integers between that number (including that number) and 1. For example, factorial 2 = 2*1 = 2 factorial 3 = 3*2*1 = 6 factorial 4 = 4*3*2*1= 24 Now you define a recursive function Fac (N) as Fac (N) = Fac (N-1) * N, with Fac(1) predefined as 1. Thus, Fac(N-1) = Fac(N-2) * (N-1) and Fac(N-2) = Fac(N-3) * (N-2) and thus recursion takes over until such time fac(1) needs to be evaluated. We know the value of Fac(1) which is set as 1. Thus we can evaluate Factorial(N) using recursion.

How can the value of a j c Higgins 22 cal pellet pisol 12619380 be found?

Check "Blue Book of AirGuns 7th edition" Both Daisy and Crosman made Airguns under the J C Higgins name for Sears.

If then else statements and case statements essentially perform the same function when would you use one over the other?

I would recommend an If - then - else statement over a switch statement because:

1. It is simpler/easier

2. You do not get unexpected output because of missing break statements

A missed break statement in one of the conditions in a switch case statement means that all the conditions that come after the success condition are executed. In case of if else this is not the case and hence it is much safer for novice programmers.

> essentially perform the same function

No, they don't. Here is an example to prove this:

if (sin (alpha) > cos (alpha)) {

...

} else if (alpha / M_PI * 180 > 180) {

...

} else {

...

}

Why return 0 is used in int main function in c?

It depends on the context.

- it means "no" in functions that check something (like "isatty", "isascii", "isdigit")

- it means "success" in functions whose return value is an error code (0 means no error)

- it means "fail" or "not found" in functions that return a pointer (like strchr or fopen).

If the length of a piece of string... is any length of string cut from a spool... 'what is the maximum length of a piece of a piece of string' or 'how much string is on a spool'?

100 metres seems to be the length of a spool of gardeners cotton Discuss:How_long_is_a_piece_of_string...we are not talking about jute twine here!So the maximum length of a piece of string would be 999.99mm!So the real answer to 'how long is a piece of string?' would be...anything between 0.01mm to 999.99mm.

How many bytes in an address of an int variable?

32 bits or 4 bytes and an int is not an address, it is a primitive so it directly access the data without a reference.

What programming languages are used in programming an EEPROM?

In one sense, since EEPROM is memory, you don't program memory. You store things in memory, and the thing you are programming in this case would likely be a micro-processor or micro-controller that is on the same circuit as the EEPROM.

In theory, an EEPROM is just memory, so any language that would be able to produce machine language output for the CPU type connected to the EEPROM in any instance could be used.

In practice, many programs written to EEPROM would be for embedded systems. In this case, a lower level language like C could be used, or a higher level language that output C or the right kind of assembly.

A higher level language like C# or Java would likely not be used, as the overhead of the virtual machine might be considered to be too heavy for a micro-controller, or small micro-processor.

That being said, in practice, you could use anything. But it is likely you would have some libraries in C or C++ that you might want to use, so you would likely use a language that was compatible with any libraries you might use.

yah it's correct.