## C Interview Questions

- 0of 0 votes
Hi, my question is about linked list? If I read .txt file (there is 5000 words inside) in to linked list. Is it possible to print 100 mostly repeated words and print them ??

example:

cat cat dog dog dog

dog3

cat 2

Thank you in advance for any help you can provide.

- 0of 0 votes
Sachin's sister loves chocolates a lot. So he decided to gift her N boxes of delicious chocolates. Every box has the capacity of 1000 chocolates. Filling more than 1000 chocolates in a box will break it and all the chocolates in it will fall down and will become uneatable. Sachin is also concerned about her health, so he advised her to eat as minimum as possible chocolates. So she decided that every day she will pick a box containing the minimum amount of chocolates and will eat half of its chocolates and will put remaining chocolates in the box having next minimum amount of chocolates. If there is no next box remaining then she will eat all of the chocolates from the current box. She will throw away all the empty and broken boxes every day. This will continue until all the boxes are gone. Being concerned about her health Sachin asked her to tell him the number of chocolates she eats every day. But she forgets the number every day. So help her to find out how many chocolates she eats every day. Basically, you have to output the total sum of chocolates she eats.

Input Format

Your function contains one argument- A One dimensional Integer array of Size N in which ith element denotes the number of chocolates in ith box.

First line of input contains an Integer N denoting the size of Array. (1<=N<=10^5)

Next N lines of input contain a single integer from 1 to 1000.

Constraints

1<=N<=10^5

Output Format

You must return a integer

Sample TestCase 1

Input

3

1

2

3

Output

6

- 1of 3 votes
(Q2)what is output and explain why?

struct abc

{

double d;

char c;

int b;

}st;

int main()

{

int i=sizeof(st);

printf("%d",i);

}

- -2of 2 votes
please help me ...i am confused

(Q1)what is output and explain why?

struct abc

{

char c;

double d;

int b;

}st;

int main()

{

int i=sizeof(st);

printf("%d",i);

}

......................................................................................................................................................................................................

- 0of 0 votes
Write a program to print the list of the maximum repeating number from an array.

Example:

Input:: a[]={1, 2, 1, 0, 5, 2, 4, 2, 3, 0, 1, 3, 2, 4}

output: 2, 1, 0, 4, 3, 5

- 0of 0 votes
A string has multiple spaces like "Fung ible is" .When ever there a space keep one space and remove all other spaces. output "Fung ible is"

- 1of 1 vote
fun(n){

if (n==0) return k;

else if n==1 return 1

else return 2*f(n-1)+4*f(n-2);

}

If fun(4) is 88, then what is the value of k.

- 1of 1 vote
We define an undirected graph g,such that: The total number of nodes in the graph is g_nodes. The nodes are numbered sequentially as 1,2,3….g_nodes. The total number og edges in the graph is g_edges. Each edge connect two distinct nodes(i.e no edge connect a node to itself). The weight of the edge connecting nodes g_to[i] and g_from[i] is g_weight[i]. We define the weight of the path from some start node to some end node to the sum of all edges traversed on the path. Input formate: The first line contain two space-seperated integer describing the respective value of g_node and g_edge. Each line I of the g_edge subsequent lines contain three space –seperated integer describing the respective value of g_to[i],g_from[i] and g_weight[i]. The next line contain an integer denoting start The next line contain an integer denoting end. The next line contain an integer denoting w_extra. input 1:

4 4

1 2 2

2 3 1

2 4 2

3 4 3

1

4

5

Output:4

input2:

5 5

1 2 2

1 4 4

2 3 1

3 4 3

4 5 1

1

4

2

output:3

Int mincost(int g_nodes,int g_edged,int* g_from,int* g_to,int* weight,int start,int end,int w_extra)

{

}

- 0of 0 votes
As you guys know, C did not have,and does not have anything called class. C++ has them. Now, C++ was written using C. In fact, C++ initially was called C with classes.

Thus, here is the problem for you.

Given you have C, and you need to implement class like behaviour, how you would do it? Specifically, implement the following in C :

1. A Simple Hello class with hello() function printing "Hello, World" .

2. A new operator which enables creating this constructor less class.

3. A delete operator that deletes the pointer.

How would you do it?

- 0of 0 votes
Write a program to print pascal triangle using binomial formula.

- 0of 0 votes
Write a program to check a given matrix is Idempotent or not.

- -1of 1 vote
Write a program to check a given matrix is involutive or not.

- -1of 1 vote
Write a program to check a given matrix is orthogonal or not.

- 0of 0 votes
Write a program to check a given matrix is A symmetric matrix or not.

- 0of 0 votes
write a program to count number of prime number between two numbers entered by the user

- 0of 0 votes
write an abstract class with two member function NextDate and Leapyear. Nextdate to print next day and leap year to check whether the year is leap year

- 0of 0 votes
write a function called reverse to print the reverse of the digit entered by the user.

- 0of 0 votes
write a program to implement following logic

If the price of the book in between 100 to 500 book is “Normal Book”

If the price is between 501 and 5000 book is “Costly book”

If greater than 5000 than book is “precious book”

- 0of 0 votes
Write a program to implement following logic

An employee can be promoted if

a) He has good communication skills

b) He is good in training

c) He is either good in programming or debugging.

- 0of 0 votes
Write a C program to convert date from 24 hrs format to 12 hrd format? Ex: 23:10 = 11:10PM

- 0of 0 votes
Write C program such that if an element in an MxN matrix is 0, its entire row and column is set to 0.

- 0of 0 votes
Either C or C++ is faster and which one is efficiently access memory?

- 0of 0 votes
Can we execute a C program with out main?

- 0of 0 votes
Write a C program to check biggest among two numbers with out using any relational operators.

- 0of 0 votes
find the best way to write zig zag sign change algorithm !

- 0of 0 votes
Can someone please help me with this? I just started C and i want to know how can i solve this, please help.

#include <stdio.h>

int main()

{

int i = 200, *p, *q;

p = &i; q = p;

*q = *q + 1;

printf("*p = %d\n", *p);

return 0;

}

Modify the program by adding another integer pointer variable r which is also an alias for variable i. Add print statements to output the dereferenced values of q and r.

- 0of 0 votes
Write a recursive function:

int sum( int x, int max )

{

/* complete the code */

}

that calculates the sum of the numbers from x to max (inclusive). For example, sum (4, 7) would compute 4 + 5 + 6 + 7 and return the value 22. The function must be recursive so you are not allowed to use any conventional loop constructs

- 0of 0 votes
Write a program fact.c that asks the user to enter an integer number N. The program then prints out the first N factorial numbers. Remember thatfac(1)=1, fac(n)=n*fac(n-1). You should use a function fac that is written recursively.

I cannot figure it out, please help me.

- 0of 0 votes
#include <stdio.h>

float add (float x, float y)

{

return x + y;

}

int main()

{

float a, b, r;

char op;

do {

printf("number op number? ");

scanf(" %f %c %f", &a, &op, &b);

switch (op)

{

case '+' : r = add(a,b);

break;

case 'q' : break;

default : op='?';

}

if (op=='?')

printf("Unknown operator\n");

else if (op=='q')

printf("Bye\n");

else

printf("%f %c %f = %f\n", a, op, b, r);

}

while (op != 'q');

return 0;

}

The program behaves like a calculator asking the user to type in binary expressions (like 2.5 + 3.7) and printing out the results. If the user enters 'q' for the operator (e.g. 0 q 0) then this is taken as a signal to stop the program.

Add a new function to the program that multiplies its two arguments together and returns their product. Then modify the switch statement so that the operator '*' causes this new product function to be called. Test the program by using a mixture of '+' and '*' calculations.

Add operators for subtraction ('-') and division ('/') and test your program again.

We introduce some special operators. Write functions to implement each of these (adding one at a time and testing after each new operator is incorporated into your calculator).

Symbol Description Example

m Minimum 2.3 m 1.7 = 1.7

M Maximum 2.3 M 1.7 = 2.3

- 0of 0 votes
Write a C program charcount.c that

reads in a string of no more than 255 characters from the user;

counts how many instances there are of each letter in the string; (note, for this program we ignore case so, e.g., the number of letter 'a' characters includes the total number of lower case 'a's and upper case 'A's.)

prints out the resulting count for each letter.

i.e. if the user enters "Time and Tide Wait for No Man", the program should print

a: 3 b: 0 c: 0 d: 2 e: 2 f: 1 g: 0 h: 0 i: 3 j: 0 k: 0 l: 0 m: 2

n: 3 o: 2 p: 0 q: 0 r: 1 s: 0 t: 3 u: 0 v: 0 w: 1 x: 0 y: 0 z: 0

Hint: This program is a bit trickier than the others so here is an outline of the processing required

declare a char array to store the string

declare an int array of size 26 to store the count for each letter e.g. count[0] is the number of a's, count[1] the number of b's etc.

read in the string and then process it element by element

if the element is not an alphabetic character i.e. A -Z or a - z, ignore it

otherwise, convert it to a number between 0 and 25 (i.e. a or A become 0, z or Z become 25) and update the corresponding count.