Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Sunday, 31 March 2019

Aptitude Hack#36(31-3-19)

Question: In how many different ways can the letters of the word 'DETAIL' be arranged in such a way that the vowels occupy only the odd positions? A) 32 B) 48 C) 36 D) 60 ...

Saturday, 30 March 2019

Aptitude Hack#35(30-3-19)

Question: Given digits 2, 2, 3, 3, 3, 4, 4, 4, 4 how many distinct 4 digit numbers greater than 3000 can be formed? A) 50 B) 51 C) 52 D) 54 ...

Friday, 29 March 2019

Aptitude Hack#34(29-3-19)

Question: A shopkeeper sells one transistor for Rs. 840 at a gain of 20% and another for Rs. 960 at a loss of 4%. His total gain or loss percent is:      D) None of these ...

Thursday, 28 March 2019

Print a long int in C using putchar() only

Print a long int in C using putchar() only C program: #include <stdio.h> void print(long n) {     /* If the number is smaller than 0, put a - sign and change number to positive */     if (n < 0) {         putchar('-');         n = -n;     }  ...

Print characters without using format specifiers

Question: C program to print characters without using format specifiers C Program: // Prints characters without format specifiers #include <stdio.h> int main() {   //ASCII Values   printf("\x41 \n");     printf("\x4d \n");     printf("\x49 \n");     printf("\x54");     return...

Round off

Write a one-line C function to round floating point numbers Algorithm: roundNo(num)1. If num is positive then add 0.5.2. Else subtract 0.5.3. Typecast the result to int and return. Example:num = 1.67, (int) num + 0.5 = (int)2.17 = 2 C program: /* Program for rounding floating point numbers */ # include<stdio.h> int roundNo(float...

Print “Even” or “Odd” without using conditional statement

Question: Print “Even” or “Odd” without using a conditional statement C program: #include<stdio.h> int main() {     int no;     printf("Enter a no: ");     scanf("%d", &no);     (no & 1 && printf("odd"))|| printf("even");     return 0; } Output: Enter a no:...

C to convert a number to a string

Question: What is the best way in C to convert a number to a string? Solution: Use sprintf() function. C program: #include<stdio.h> int main() {     char result[50];     float num = 23.34;     sprintf(result, "%f", num); printf("\n The string for the num is %s", result); } Output:  The...

Program for Sum the digits of a given number

Program for Sum the digits of a given number Examples : Input : n = 687 Output : 21 C program: # include<stdio.h> /* Function to get sum of digits */ int getSum(int n) {     int sum;     /* Single line that calculates sum */     for (sum = 0; n > 0; sum += n % 10, n /= 10);  ...

To find sum of two numbers without using any operator

Write a program to find the sum of positive integers without using any operator. C program: #include<stdio.h> int add(int x, int y) {     return printf("%*c%*c", x, ' ', y, ' '); } int main() {     printf("Sum = %d", add(3, 4));     return 0; } Output: Sum = 7...

Activity Selection Problem

Activity Selection Problem 1) Sort the activities according to their finishing time 2) Select the first activity from the sorted array and print it. 3) Do following for remaining activities in the sorted array. a) If the start time of this activity is greater than or equal to the finish time of previously selected activity then select this activity...

Minimum number of Coins

 Find the Minimum number of Coins 1) Initialize result as empty. 2) find the largest denomination that is       smaller than V. 3)  Add found denomination to result.     Subtract the value of found denomination from V. 4) If V becomes 0, then print result.      Else repeat steps...

Aptitude Hack#39(3-4-19)

Question: A person borrows Rs. 5000 for 2 years at 4% p.a. simple interest. He immediately lends it to another person at 25/4  p.a for 2 years. Find his gain in the transaction per year. A) Rs 112.50 B) Rs 125 C) Rs 150 D) Rs 167.5...

Aptitude Hack#33(28-3-19)

Question: 5 skilled workers can build a wall in 20 days; 8 semi-skilled workers can build a wall in 25 days; 10 unskilled workers can build a wall in 30 days. If a team has 2 skilled, 6 semi-skilled and 5 unskilled workers, how long will it take to build the wall? A) 20 days B)...

Breath First Search

ALGORITHM BFS(G)//Implements a breadth-first search traversal of a given graph//Input: Graph G = V, E//Output: Graph G with its vertices marked with consecutive //integers in the order they are visited by the BFS traversalmark each vertex in V with 0 as a mark of being “unvisited”count ← 0for each vertex v in V doif v is marked...

Wednesday, 27 March 2019

Sieve of Eratosthenes Algorithm

ALGORITHM Sieve(n) //Implements the sieve of Eratosthenes //Input: A positive integer > 1 //Output: Array L of all prime numbers less than or equal to n for p ← 2 to n do A[p] ← p for p ← 2 to √n do  if A[p] = 0...

SortAnalysis Aglorithm

ALGORITHM SortAnalysis(A[0..n - 1]) //Input: An array A[0..n - 1] of n orderable elements //Output: The total number of key comparisons made count ← 0 for i ← 1 to n - 1 do v ← A[i] j ← i - 1 while j ≥ 0 and A[j] > v do count ← count + 1 A[j + 1] ← A[j] j ← j - 1 A[j + 1] ← v return count C program: #include<stdio.h> int main(){ int n,v,i,j,count=0,arr[100]; printf("Enter...

Factorial Algorithm

ALGORITHM F(n) //Computes n! recursively //Input: A nonnegative integer n //Output: The value of n! if n = 0 return 1 else return F (n - 1) ∗ n C program: #include <stdio.h>  int factorial(int c){      if(c==1){        ...

Binary Algorithm

ALGORITHM Binary(n) //Input: A positive decimal integer n //Output: The number of binary digits in n’s binary representation count ← 1while n > 1 do count ← count + 1 n ← n/2 return count Another Way ALGORITHM BinRec(n) //Input: A positive decimal integer n //Output:...