A Galaxy of beautiful minds to help you out the best possible solution to your problems in c fundamentals, data structures through c programming language.
This is one of the most common interview question.
Given an array of integers (positive and negative) find the largest continuous sum.
If the array is all positive, then the result is simply the sum of all numbers. The negative numbers in the array slightly complicate things. The algorithm is, we start summing up the numbers and store in a current sum variable. After adding each element, we check whether the current sum is larger than maximum sum encountered so far. If it is, we update the maximum sum. As long as the current sum is positive, we keep adding the numbers. When the current sum becomes negative, we start with a new current sum. Because a negative current sum will only decrease the sum of a future sequence. Note that we don’t reset the current sum to 0 because the array can contain all negative integers.
Assume that the size of an integer is 4 bytes. Predict the output? #include int fun() { puts(" Hello "); return 10; } int main() { printf("%d", sizeof(fun())); return 0; }
This is one of the most common interview question.
ReplyDeleteGiven an array of integers (positive and negative) find the largest continuous sum.
If the array is all positive, then the result is simply the sum of all numbers. The negative numbers in the array slightly complicate things. The algorithm is, we start summing up the numbers and store in a current sum variable. After adding each element, we check whether the current sum is larger than maximum sum encountered so far. If it is, we update the maximum sum. As long as the current sum is positive, we keep adding the numbers. When the current sum becomes negative, we start with a new current sum. Because a negative current sum will only decrease the sum of a future sequence. Note that we don’t reset the current sum to 0 because the array can contain all negative integers.
Given an integer array, output all pairs that sum up to a specific value k. Write a program for this.
ReplyDeleteWhat is the output of this program?
ReplyDeleteint main()
{
int a;
a = 3;
fun(a);
printf("\n");
return 0;
}
void fun(int n)
{
if(n > 0)
{
fun(--n);
printf("%d",n);
fun(--n);
}
}
Int main()
ReplyDelete{
int x = 032;
printf("%d", x);
return 0;
}
what should be the output??
Assume that the size of an integer is 4 bytes. Predict the output?
ReplyDelete#include
int fun()
{
puts(" Hello ");
return 10;
}
int main()
{
printf("%d", sizeof(fun()));
return 0;
}