write a program to find whether the sum of the triplet is equal to the given value.

#include<stdio.h>
#include<conio.h>
int main()
{
int a[5]={4,2,3,8,12};
int i,j,k,sum=15,p=0;
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
for(k=j+1;k<5;k++)
{
if(a[i]+a[j]+a[k]==sum)
{
p=1;
}
}
}
}
printf("%d",p);
return 0;
}


#include<stdio.h>
#include<conio.h>
int main()
{
int a[5]={4,2,3,8,12};
int i,j,k,sum=25,p=0;
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
for(k=j+1;k<5;k++)
{
if(a[i]+a[j]+a[k]==sum)
{
p=1;
}
}
}
}
printf("%d",p);
return 0;
}

Comments

Popular posts from this blog

write a program for insertion sort with example.