C Interview Questions
- 0of 0 votes
AnswerWrite a C program to check biggest among two numbers with out using any relational operators.
- D PRAVEEN KUMAR September 22, 2016 in India| Report Duplicate | Flag | PURGE
Skill Subsist Impulse Ltd Tech Lead C - 0of 0 votes
Answersfind the best way to write zig zag sign change algorithm !
- bharadwajdya March 17, 2016 in United States| Report Duplicate | Flag | PURGE
Roxar Software Engineer Intern C - 0of 0 votes
AnswersCan someone please help me with this? I just started C and i want to know how can i solve this, please help.
- darkicewb820 March 10, 2016 in United States
#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.| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswersWrite a recursive function:
- darkicewb820 March 07, 2016 in United States
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| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswersWrite 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.
- darkicewb820 March 07, 2016 in United States
I cannot figure it out, please help me.| Report Duplicate | Flag | PURGE
C - 0of 0 votes
Answer#include <stdio.h>
- darkicewb820 March 07, 2016 in United States
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| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswerWrite a C program charcount.c that
- darkicewb820 March 07, 2016 in United States
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.| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswersWrite a C program called string3.c that reads in a string of no more than 80 characters and then prints it back out (within double quotes) with all lower case characters changed to upper case.
- darkicewb820 March 07, 2016 in United States
Your string? C programming is fun
Modified to: "C PROGRAMMING IS FUN"| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswerSo i have this code :
- darkicewb820 March 07, 2016 in United States
#include <stdio.h>
int main()
{
int i, j;
int * p, * q;
int ** x;
i = 100;
j = 200;
p = &i;
q = &j;
x = &p;
*p = *p + *q;
*q = **x / 2;
**x = *p + j;
printf(" i = %d\n", i);
printf("&i = %p\n", &i);
printf(" j = %d\n", j);
printf("&j = %p\n", &j);
printf(" p = %p\n", p);
printf("&p = %p\n", &p);
printf("*p = %d\n", *p);
printf(" q = %p\n", q);
printf("&q = %p\n", &q);
printf("*q = %d\n", *q);
printf(" x = %p\n", x);
printf("&x = %p\n", &x);
printf("*x = %p\n", *x);
printf("**x= %d\n", **x);
return 0;
}
I need to modify the program by adding a new variable that stores the address of x. Then use your variable to update (indirectly) the value of i and then print out the new value to demonstrate that your modification has worked.| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswersSo i have this :
- darkicewb820 March 07, 2016 in United States
#include <stdio.h>
int main()
{
int i = 200, *p, *q;
p = &i; q = p;
*q = *q + 1;
printf("*p = %d\n", *p);
return 0;
}
I need to 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.| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswersWrite a program in C that:
- Dominykas1.Katilius March 01, 2016 in United States
declares a string variable called buffer with maximum size 80
inputs a string from the keyboard into the buffer
modifies the string contained in buffer by replacing any vowels (upper or lower case 'a', 'e', 'i', 'o' or 'u') with a plus sign (+)
prints out the modified string
prints out the total number of vowels that were replaced| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswersWrite the function READ, which is passed two double pointers pointing to the head pointers of two linked lists.
- J@sper February 08, 2016 in United States
One list will hold even integers, the other one will hold odd integers. READ reads a series of integers. It separates adds odd integers to the first list, and even ones to the second, all in sorted order.| Report Duplicate | Flag | PURGE
Google C - 1of 1 vote
Answershow can i merge 2 nodes in a graph in 1 node , need to save the in and out edges and the nodes that was merged for contribution after that
- KabhaD82 January 30, 2016 in United States
for example a graph implementation in adj list:
1->3->4->6
2->3->4->6
5->4->6
and i want to merge the nodes 3 and 4 , then new nodes should be created 7 as :
1->7->6
2->7->6
5->7->6
7->6
the node 7 also will save [include 3,4 the merged nodes]
any one can help with that please
typedef struct AdjListEntry {
int visited;
int index;
struct AdjListNode current; // node iniformation
struct AdjListEntry* next;
} AdjListEntry;
typedef struct AdjListNode {
int Uind;
char name[10];
char label[10];
adjOutEddgeLists *outEddges;
//adjInEddgeLists *inEddges;
} AdjListNode;
typedef struct adjOutEddgeLists{
AdjListNode *listNode;
adjOutEddgeLists *next;
}adjOutEddgeLists;| Report Duplicate | Flag | PURGE
Amazon Software Engineer C - -12of 12 votes
Answers-
- J@sper January 17, 2016 in United States| Report Duplicate | Flag | PURGE
Google Jr. Software Engineer C - 0of 0 votes
AnswersAllocate a 2-D array of size m*n using malloc(). The array should be accessible as a[i][j].
- Saurabh Singhal January 16, 2016 in India| Report Duplicate | Flag | PURGE
Arista Networks Software Engineer Arrays C Data Structures Matrix - 0of 0 votes
Answersint main() {
- J@sper January 13, 2016 in United States
int google = ??
if ( google == -google)
return 1;
return 0;
}
There are two answers, the first being zero. What's the second value?| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswersGiven a number (200), compare it to four variables (E.G A,B,C,D) and return true if they are all equal to the given number.
- J@sper January 09, 2016 in United States
Do this in the most efficient way, and if possible without if statements.| Report Duplicate | Flag | PURGE
Amazon Computer Scientist C - 0of 0 votes
AnswersI have an array with 60% sorted and 40% unsorted, which algorithm will give fastest accurate sorted output in C? And for Linked list which sorting algorithm suited?
- The Puzzler 2.0 January 06, 2016 in India| Report Duplicate | Flag | PURGE
Kony India Private Limited Software Engineer / Developer C - 0of 0 votes
AnswerHow can I find factorial of positive integers using structures in C?
- The Puzzler 2.0 January 06, 2016 in India| Report Duplicate | Flag | PURGE
Kony India Private Limited Software Engineer / Developer C - 3of 3 votes
AnswersAssume there are 10000 stars in sky, how would you find which star is closest to the earth? in C
- The Puzzler 2.0 January 05, 2016 in India| Report Duplicate | Flag | PURGE
Software Engineer / Developer C - 0of 0 votes
Answersi need to write code that union two nodes from graph G Vi ,Vj
- KabhaD82 December 30, 2015 in Isreal
then new node will generated Vm = ViUVj| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer C - 0of 0 votes
AnswersCounting the number of digits before and after the decimal point without using string ( using double data type).
- Rohit Hajare December 29, 2015 in India| Report Duplicate | Flag | PURGE
Software Developer C - 0of 0 votes
AnswersWrite a function that will operate on a C-string and convert all instances of "AB" to "C" without using a second string for temporary storage. Use the following function signature:
- bradpitt119 December 15, 2015 in United States
void translate(char *str)
So for example:
char astring[] = "helloABworld";
translate(astring);
// Now astring holds "helloCworld";
Your function should handle strings of arbitrary length.| Report Duplicate | Flag | PURGE
N/A xyz C - 0of 0 votes
AnswersWrite a program to display 1st, 2nd and 4th multiples of 7which also gives the remainder 0 (ZERO) when it divided by 2,3,4,5 and 6.
- D PRAVEEN KUMAR December 10, 2015 in India| Report Duplicate | Flag | PURGE
PRATIAN Java Developer C - 0of 0 votes
AnswersWrite a program to display the series 1,2,6,15,31,56,......,N
- D PRAVEEN KUMAR December 10, 2015 in India| Report Duplicate | Flag | PURGE
PRATIAN Java Developer C - 1of 1 vote
AnswersWrite a C program to calculate multiplication between two numbers with repetitive additions
- D PRAVEEN KUMAR December 07, 2015 in United States| Report Duplicate | Flag | PURGE
C - 0of 0 votes
Answerwrite a program to accept a value for 4x4 matrix. find the total of matrix, minimum and maximum number in matrix
- harshitaY31 November 27, 2015 in United States| Report Duplicate | Flag | PURGE
C C - 0of 0 votes
AnswersYou have a memory location. It is actually a character array abc... upto z .
- ahmad.husain.khan November 17, 2015 in India
I have a integer pointer p pointing to a ie the first character of the array.
How do I print the character array using the integer pointer ?| Report Duplicate | Flag | PURGE
HCL Software Engineer C - 0of 0 votes
AnswersProblem Statement
- bharadwajdaya November 14, 2015 in India
Given an integer N, express it as the sum of at least two consecutive positive integers. For example:
10 = 1 + 2 + 3 + 4
24 = 7 + 8 + 9
If there are multiple solutions, output the one with the smallest possible number of summands.
Input Format
The first line of input contains the number of test cases T. The descriptions of the test cases follow:
Each test case consists of one line containing an integer N (1 ≤ N ≤ 109).
Output Format
For each test case, output a single line containing the equation in the format:
N = a + (a + 1) + ...+ b
as in the example. If there is no solution, output a single word ‘IMPOSSIBLE’ instead.
Sample Input
3
8
10
24
Sample Output
IMPOSSIBLE
10 = 1 + 2 + 3 + 4
24 = 7 + 8 + 9| Report Duplicate | Flag | PURGE
IIT-D Student C