+ 6

How can we use nested if with turnary operator? Is it possible?

I want nested if condition with turnary operator i have to run both if condition be sure i am not talking about else if condition ...

14th Aug 2019, 4:51 PM
Prince Raj
Prince Raj - avatar
10 odpowiedzi
+ 5
~ swim ~ i know program has some bug but still i want to know how to deal with with turnary operator with nested if i will try this ... Thank you very much 😊
14th Aug 2019, 7:36 PM
Prince Raj
Prince Raj - avatar
+ 4
Prince, you have not nested if() in code. scanf("%d",&n) is_upper = (y>x&&a!=0)? 0: is_upper; is_lower = (y<x&&a!=0)? 0: is_lower; } } // for1, for2 printf( (is_upper==1 || is_lower==1)? "yes" : "no"); } if() is efective here because ternary 1,2 must do assign in every times, but if() not. int main() must be declared with int return type
14th Aug 2019, 7:48 PM
zemiak
+ 2
~ swim ~ This is program for upper or lower triangular matrix #include<stdio.h> void main(){ int n,a; int is_upper=1; int is_lower=1; scanf("%d",&n); for(int x=0;x<n;x++){ for(int y=0;y<n;y++){ scanf("%d",&n); if(y>x&&a!=0){ is_upper=0; } if(y<x&&a!=0){ is_lower=0; } } } if( is_upper==1 || is_lower==1) printf("yes"); else printf("no"); } Can you please change this to nested turnary operator i m having trouble?
14th Aug 2019, 7:11 PM
Prince Raj
Prince Raj - avatar
+ 2
I know zemiak above program is only for example, to ask how to deal with nested turnary operator...
14th Aug 2019, 7:53 PM
Prince Raj
Prince Raj - avatar
+ 1
int fn(int a){ return (a<50) ? 50 : (a<75)? 75: 100; }
14th Aug 2019, 9:19 PM
zemiak
+ 1
Nesting ternaries is considered by many to be bad practice because it makes code extremely unreadable. Also, ternary means "an operator that takes three arguments" so even though you can cheat that it kinda goes against the idea.
16th Aug 2019, 4:52 PM
TelFiRE
TelFiRE - avatar