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

Difference types of nonlinear data structure?

Tree, Graphs are the types of nonlinear data structure.

What is good programming style?

There are 2 major goals easily to say than done in any programming:

  1. The software works as desired
  2. The software is maintainable

Any technique that can lead you to those 2 goals are superbly good.

Flowchart to check if 12321 is palindrome or not?

i dnt have time to draw flow chart but i'll give the algorith..(only major steps)

1 :read n

2:m=n

3:if n=0 goto step 8,else goto step 4

4:r=n%10

5:rev=(rev*10)+r

6:n=n/10

7:goto step3

8:if m==rev,display "palindrome" else "not palindrome

9:stop

How to write an effective program using c plus plus?

Here is a simple program that will tell you how to make an algorithm:

int main();

{

int length;

int width;

int total;

printf("What is the width: ");

scanf("%d", &width);

printf("What is the length: ");

scanf("%d", &length);

total = width * 2 + 2 * length; /*Here is the algorithm for finding the perimeter of a square*/

printf("The perimeter is: %d", total);

return 0;

}

Output:

What is the width: 32

What is the length: 55

The perimeter is: 174

Write a c program to find Armstrong number using ifstatement?

#include<stdio.h>

int main(){

int num,r,sum,temp;

int min,max;

printf("Enter the minimum range: ");

scanf("%d",&min);

printf("Enter the maximum range: ");

scanf("%d",&max);

printf("Armstrong numbers in given range are: ");

for(num=min;num<=max;num++){

temp=num;

sum = 0;

while(temp!=0){

r=temp%10;

temp=temp/10;

sum=sum+(r*r*r);

}

if(sum==num)

printf("%d ",num);

}

return 0;

}

How do you print 1 to 10 numbers using while loop in C?

#include <iostream>

int main()

{

int i=0;

while( i<10 )

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

return( 0 );

}

What is the difference between dynamic implementation and linked list implemention?

The size or length of the list. For static, the size is a constant, while the size of a dynamic list may change over time.

The 7 weekdays is static (in size/length, though the content is static as well), while the questions and answers at answers.com are 2 dynamic lists (the sizes are not constants, although just growing)

What is the difference between null and void pointers?

A void pointer is a pointer that has no type information attached to it.

A null pointer is a pointer that points to "nothing". A null pointer can be of any type (void included, of course).

What is the decimal equivalent of 0XFFFF?

0X at the beginning represent a number in the hexadecimal system of units.

FFFF is the hexadecimal equivalent of

i) 65535 in decimal system of units

ii) 1111111111111111 in binary system of units

What is the decimal conversion of the binary number 1111 1111 1111?

4+2+1

A bit is a 1 or a 0

A byte is typically 8 bits, in which case it can have a value between 0 and 255.

There are 2 possible values for each digit and there are 8 digits. 28 is 256. Because 0 is also a number, 11111111 is equal to 255 (decimal) rather than 256.

The first digit is 20, the second digit is 21, the third digit is 22, and so on. The 1 is a yes and the 0 is a no.

20 = 1

21 = 2

22 = 4

23 = 8

24 = 16

25 = 32

26 = 64

27 = 128

So 10101101 would be:

[1 x 27] + [0 x 26] + [1 × 25] + [0× 24] + [1 × 23] + [1 × 22] + [0 × 21] + [1 × 20] =

[1 x 128] + [0 x 64] + [1 × 32] + [0× 16] + [1 × 8] + [1 × 4] + [0 × 2] + [1 × 1] =

128 + 32 + 8 + 4 + 1 = 173

So, 10101101 = 173

A more specific answer to you question:

00000111

[0 x 27] + [0 x 26] + [0 × 25] + [0× 24] + [0 × 23] + [1 × 22] + [1 × 21] + [1 × 20] =

[0 x 128] + [0 x 64] + [0 × 32] + [0× 16] + [0 × 8] + [1 × 4] + [1 × 2] + [1 × 1] =

4 + 2 + 1 = 7

So, 00000111 = 7

What is calling by reference How it is different from call by value?

Call By Value, the standard way of doing things in C and C++, is where a copy of an object is placed in the parameter stack. The called function can access and manipulate that copy at will, but it cannot change the original copy because it has no way of knowing where that original copy is located.

Call By Reference, on the other hand, is where the address of an object is placed in the parameter stack. Using extra syntax, the * or the ->, the called function can access and manipulate the original copy at will.

Write a java program to create human face?

Try this for a very, very simple face....

String hair = " /////// ";

String eyes = " | o o | ";

String noseEars = "(| ^ |)";

String mouth = " | [ ] | ";

String chin = " ------ ";

System.out.println(hair); //prints out the hair

System.out.println(eyes); //prints out the eyes

System.out.println(noseEars); //prints out the nose and ears

System.out.println(mouth); //prints out the mouth

System.out.println(chin); //prints out the chin

What are generalised linked list?

A generalized linked list contains structures or elements with every one containing its own pointer. It's generalized if the list can have any deletions, insertions, and similar inserted effectively into it.

How do you overcome the disadvantages of arrays?

There are many limitations of arrays. The greatest advantage of an array of course is performance. Arrays are by far the fastest means of referencing collection of items.

That said, arrays suffer incredible limitations since they are generally very slow for adding items in a sorted manor. Unless you preallocate a large enough area of memory to store all possible items you wish to use, arrays have to be reallocated over and over. There are some hackish functions which can be used to exploit the MMU of the system to grow arrays by creating multiple logical contiguous regions of memory, but if this is performed on a fine grain, the logical descriptor tables of the system will grow and overall system performance will be negatively impacted.

Even though you appear to want to program plain-C, there is no reason you can't develop in an object oriented manor. There are many libraries available for C which provide high-performance variable length collections. I am not familiar with all of them, but as part of the GNOME toolkit, there is GLib (if I recall) which provides excellent implementations of many of them. Alternatively, if you're interested in learning how they work in order to correctly choose the right one for each task, you may want to get a copy of Donald Knuth's "The Art of Computer Programming, Volume 1" which is effectively a bible of sorts on this specific topic and is quite easy to read.

If you want to learn the ABCs and 123s without an overly prolonged investment in time, I recommend experimenting with an object oriented language with good class libraries like Java or my favorite, C#. They are both great starting points for experimenting with data structures.

What is the difference between a database and word processing?

Authors are far more concerned with the actual content than the layout and will use word processors to produce that content. Desktop publishing is more concerned with layout than with content.

How do you write a C program to check for Armstrong numbers in three digit values from 100 to 999 using do while loop?

import java.io.*;

public class Arms

{

public static void main(String args[]) throws Exception

{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the number to be printed: ");

int n=Integer.parseInt(br.readLine());

int num,sum,r,temp;

System.out.println("Armstrong numbers upto given limit are:\n");

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

{

temp=num;

sum =0;

while (temp!=0)

{

r=temp%10;

sum=sum+(r*r*r);

temp=temp/10;

}

if(sum==num)

{

System.out.println(num);

}

}

}

}

Regards

Ramakrishna Nallapati

What type of data is gender?

Important. (Please, be more specific with your question, or else no-one could fathom what you wants to know.)

There needs to be a category for questions that as asked defy a sensible answer.

Is function always return a value?

no, every function can not return a value. for example

void name()

{

cout<<"Hello world";

}

this function does not return any value due to the key word void that tells the compiler that the function does not returns a value.

What is difference between Single pass compiler and double pass compiler?

i think a pass is reading the input file, i.e. the file in which the code is written in the source language.so in a single pass compiler, the input file is read only once and in doublepass compiler this is done 2 times

.

Why c is called high level language?

Because C is one of the high level programming languages. Other examples: Pascal, Fortran, List, JavaScript, APL

How do you write a c program for performing DFS and BFS operations?

#include<stdio.h>

#include<conio.h>

#include<alloc.h>

#include<process.h>

#include<string.h>

#define MAX 20

typedef struct queue

{

int data;

struct queue *next;

}queue;

typedef struct stack

{

int data;

struct stack *next;

}stack;

typedef struct adj_list

{

int vertex;

struct adj_list *next;

}adj_list;

adj_list *G[MAX];

int queue_empty(queue *front,queue *rear)

{

if(front==NULL && rear==NULL)

return 1;

else

return 0;

}

queue* getnode()

{

queue *newnode;

newnode = (queue*)malloc(sizeof(queue));

newnode->next = NULL;

return newnode;

}

void enqueue(queue **front, queue **rear, int data)

{

queue *newnode;

newnode = getnode();

newnode->data = data;

if(queue_empty(*front,*rear))

{

*front = *rear = newnode;

}

else

{

(*rear)->next = newnode;

(*rear) = newnode;

}

}

int dequeue(queue **front,queue **rear)

{

int data;

queue *temp;

if(queue_empty(*front,*rear))

return 0;

temp = *front;

data = (*front)->data;

if(*front==*rear)

{

*front = *rear = NULL;

}

else

{

*front = (*front)->next;

}

free(temp);

return data;

}

stack* create_node()

{

stack *newnode;

newnode = (stack*)malloc(sizeof(stack));

newnode->next = NULL;

return newnode;

}

void push(stack **top, int data)

{

stack *newnode;

newnode = create_node();

newnode->data = data;

newnode->next = *top;

*top = newnode;

}

int pop(stack **top)

{

stack *temp;

int data;

temp = *top;

data = (*top)->data;

*top = (*top)->next;

free(temp);

return data;

}

int stack_empty(stack *top)

{

if(top==NULL)

return 1;

else

return 0;

}

void insert(int vi, int vj)

{

adj_list *temp,*newnode;

newnode=(adj_list*)malloc(sizeof(adj_list));

newnode->vertex = vj;

newnode->next=NULL;

if(G[vi]==NULL)

{

G[vi]=newnode;

}

else

{

temp = G[vi];

while(temp->next!=NULL)

{

temp = temp->next;

}

temp->next = newnode;

}

}

void create(int count,char location[MAX][MAX])

{

int i,edges, vi,vj;

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

{

printf("\nEnter the name of node %d\t",i);

flushall();

scanf("%s",location[i]);

G[i] = NULL;

}

printf("\nEnter number of edges\t");

scanf("%d",&edges);

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

{

printf("\nEnter the edge (node u,node v)\t");

scanf("d",&vi,&vj);

insert(vi,vj);

insert(vi,vj);

}

}

void BFS(int v,int count,char location[MAX][MAX])

{

int w,i,visited[MAX];

queue *front=NULL,*rear=NULL;

adj_list *temp;

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

{

visited[i]=0;

}

enqueue(&front,&rear,v);

printf("\n%s",location[v]);

visited[v]=1;

while(!queue_empty(front,rear))

{

v = dequeue(&front,&rear);

for(temp=G[v];temp!=NULL;temp=temp->next)

{

w = temp->vertex;

if(visited[w]==0)

{

enqueue(&front,&rear,w);

visited[w]=1;

printf("\n%s",location[w]);

}

}

}

}

void DFS(int v,int count,char location[MAX][MAX])

{

adj_list *temp;

int visited[MAX],j,w;

stack *top=NULL;

for(j=0;j<count;j++)

{

visited[j]=0;

}

push(&top,v);

visited[v]=1;

while(!stack_empty(top))

{

w = pop(&top);

printf("\n%s",location[w]);

for(temp=G[w];temp!=NULL;temp=temp->next)

{

if(visited[temp->vertex]==0)

{

push(&top,temp->vertex);

visited[temp->vertex]=1;

}

}

}

}

int search(char location[MAX][MAX], char item[MAX])

{

int i;

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

{

if(stricmp(item,location[i])==0) /*string found*/

return i;

}

return -1;

}

void main()

{

int ch,count,i;

char location[MAX][MAX],start[MAX];

do

{

clrscr();

printf("\n*** MENU ***");

printf("\n1.Create");

printf("\n2.Depth First Search");

printf("\n3.Breadth First Search");

printf("\n4.Exit");

printf("\n\nEnter your choice\t");

scanf("%d",&ch);

switch(ch)

{

case 1:

printf("\nEnter number of nodes\t");

scanf("%d",&count);

create(count,location);

break;

case 2:

printf("\nEnter starting place\t");

scanf("%s",start);

i = search(location,start);

if(i==-1)

printf("\nInvalid Location Entered");

else

{

printf("\nDepth First Search...\n");

DFS(i,count,location);

}

break;

case 3:

printf("\nEnter starting place\t");

scanf("%s",start);

i = search(location,start);

if(i==-1)

printf("\nInvalid Location Entered");

else

{

printf("\nBreadth First Search...\n");

BFS(i,count,location);

}

break;

case 4:exit(0);

default:printf("\nPlease enter proper choice!!!");

}

getch();

}while(1);

}

This program performs both DFS and BFS operations.

Why not you simply put the decimal integer into the original string as compared to the format specifier?

You can certainly do that ...

printf ("This is a number: 12345\n");

... but that does not have the same value as placing the value in a variable and converting the variable into a string ...

int i = 12345;

printf ("This is a number: %d\n", i);

That's the whole point of format specifiers - to initiate a conversion from one place to another.