QUESTION
QUESTION DESCRIPTION
Ramu willing to play a game with Manimaran. So he decided to ask three numbers from the given array to make whose sum is zero. For this purpose he created an array with distinct elements. The task is to find three numbers in array whose sum is zero. Take the array as input.
Ramu willing to play a game with Manimaran. So he decided to ask three numbers from the given array to make whose sum is zero. For this purpose he created an array with distinct elements. The task is to find three numbers in array whose sum is zero. Take the array as input.
TEST CASE 2
INPUT
INPUT
1 -2 1 0 5
OUTPUT1 -2 1
Answer--------------
#include <stdio.h>
int main() {
int a[5],i,j,k,p;
for(i=0;i<5;i++)
{scanf("%d",&a[i]);}
for(i=4;i>=0;i--){
for(j=0;j<i;j++){
for(k=0;k<j;k++){
p=a[i]+a[j]+a[k];
if(p==0)
{
if(i<j&&j<k)
{printf("%d %d %d",a[i],a[j],a[k]);
printf("\n");}
if(j<i&&i<k)
{
printf("%d %d %d",a[j],a[i],a[k]);
printf("\n");
}
if(k<i&&i<j)
{
printf("%d %d %d",a[k],a[i],a[j]);
printf("\n");
}if(i<k&&k<j)
{
printf("%d %d %d",a[i],a[k],a[j]);
printf("\n");
}
if(j<k&&k<i)
{
printf("%d %d %d",a[j],a[k],a[i]);
printf("\n");
}
if(k<j&&j<i)
{
printf("%d %d %d",a[k],a[j],a[i]);
printf("\n");
}
}
}}}
return 0;
}
Comments
Post a Comment