this procedure work for ternary search
int tsearch(int *a,int i,int j,int k)
{
int m1,m2,len;
len = j - i + 1 ;
m1=i + (int)floor((float)(len))/3;
m2=i + (int)ceil((float)(len))/3;
if(k==a[m1])
{
printf("\nno found at %d",m1);
return m1;
}
else if(k==a[m2])
{
printf("\nno found at %d",m2);
return m2;
}
if(len!= 0) {
if(k<a[m1])
return(tsearch(a,i,m1-1,k));
if(k>a[m2])
return(tsearch(a,m2+1,j,k)); }
else
return -1 ;
}
write a c program to fine largest/smallest of 3no (using ?:ternary operator/conditional operator)
R = (A > B && A > C) ? A : (B > C) ? B : C; // parentheses not necessary - for clarity only
execution
You can use the ternary operator, in an expression such as: result = a > b ? a : b; This is equivalent to: if (a > b) result = a; else result = b;
You could use an if, but the ternary operator is especially compact for this purpose: result = a > b ? a : b;
syntax is the way you write your code in it defines the meaning of keywords & how to write
exp ? exp : exp
Selection constructs in C++if...elseswitch/caseconditional ternary operator (?:)
C does not support templates. Templates are supported by C++ and make it possible to write generic code.
This is a request, not a question.
In music Binary, Ternary and Rondo are like the layout of a song. So say A represents a verse, B a chorus and C would represent a Bridge! Binary would be A,B (Verse, chorus) Ternary would be A,B,A (Verse, chorus, verse) Then Rondo would be A,B,A,C,A (Verse, chorus, verse, bridge, verse)
Conditional Operator- Its the only ternary operator in c/c++.- Its syntax is-(condition)?statement1:statement2;-Shruti Jain