0% found this document useful (0 votes)
44 views8 pages

Ternary Operators (2) (1) - 1

The document contains 23 C programming examples demonstrating the use of ternary operators and conditional statements. The programs test different logical conditions and print the resulting values of variables assigned using ternary operators. Some programs produce errors due to incorrect syntax or multiple ternary operators. The last few programs demonstrate using printf statements within ternary operators to print values conditionally.

Uploaded by

Fake Acc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views8 pages

Ternary Operators (2) (1) - 1

The document contains 23 C programming examples demonstrating the use of ternary operators and conditional statements. The programs test different logical conditions and print the resulting values of variables assigned using ternary operators. Some programs produce errors due to incorrect syntax or multiple ternary operators. The last few programs demonstrate using printf statements within ternary operators to print values conditionally.

Uploaded by

Fake Acc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Program 1

#include<stdio.h>

void main()

{
20
int a;

a=10?20:30;

printf("%d",a);

Program 2

#include<stdio.h>

void main()

int a;

a=5<2?20:30; 30

printf("%d",a);

Program 3

#include<stdio.h>

void main()

int a;

a=2<5 && !0 ? 10:20; 10

printf("%d",a);
}

Program 4

#include<stdio.h>

void main()

int a;

a=10?20;

printf("%d",a);

} error

Program 5

#include<stdio.h>

void main()

int a;

a=10:20?50;

printf("%d",a); error

Program 6

#include<stdio.h>

void main()

int a;

a=10<20?50:30:60;
reeor
printf("%d",a);

Program 7

#include<stdio.h>

void main()

int a; error

a=20>10?10:30:60<70?20;

printf("%d",a);

Program 8

#include<stdio.h>

void main()

int a;

a=20>100?100: !12!=3>50 ? 300 : 400 ;

printf("%d",a); 400

Program 9

#include<stdio.h>

void main()

int a;

a=20>100>100: !12!=3>50 ? 300 : 400 ;

error
printf("%d",a);

Program 10

#include<stdio.h>

void main()

int a;

a= 20<60 ? 12!= 200 >346 ? 10 : 20 :30 ;

printf("%d",a); 10

Program 11

#include<stdio.h>

void main()

int a;

a= 20<60 ? 12! = 200 >346 ? 10 : 20 :30 ;

printf("%d",a); 10

Program 12

#include<stdio.h>

void main()

int a;

a= 2>5 ? 10 : 5<8!=1?20: !5 ? 30 :40 ;


printf("%d",a); 40

Program 13

#include<stdio.h>

void main()

int a;

a= 5>2 != 1?10:2<5?1!=2>5?20:30:40;

printf("%d",a); 20

Program 14

#include<stdio.h>

void main()

int a;

a= 10!=12>50? !4!=4?8>8!=0?10:20:30:40;

printf("%d",a);
20
}

Program 15

#include<stdio.h>

void main()

int a;

a= 2 > 5 !=1?5<8 && 8>2 ? !5?10:20:30:40;

printf("%d",a);
20
}

Program 16

#include<stdio.h>

void main()

int a;

a= 2 > 5 ? 1!=2>5?10:20:5<8?2!=2>5?!5?30:!1!=1?40:50:60:70;

printf("%d",a);
40
}

Program 17

#include<stdio.h>

void main()

int a;

a= 12 > 50 ? 1!=2>5?10:20<30||!2:5<8?2!=2>5?!5?30:!1!=1?40:50:60:70;

printf("%d",a); 40

Program 18

#include<stdio.h>

void main()

int a;

a= 12 > 50 ? printf("pankaj"):printf("neeraj");

printf("%d",a); 6

}
Program 19

#include<stdio.h>

void main()

int a;

a= 120 > 50 ? printf("%d",printf("pankaj")):printf("neeraj");

printf("%d",a);
pankaj61
}

Program 20

#include<stdio.h>

void main()

int a;

a= 12 > 50 ? printf("GATE")||printf("%d",printf("pankaj")):printf("neeraj");

printf("%d",a); 6

Program 21

#include<stdio.h>

void main()

int a;

a= 120 > 50 ? printf("GATE") && printf("CSE")||printf("pankaj"):printf("neeraj");

printf("%d",a);
gatecse1
}

Program 22
#include<stdio.h>

void main()

int a;

a= 120 > 50 ? !printf("GATE") && printf("CSE")||printf("pankaj"):printf("neeraj");

printf("%d",a); gatepankaj1

Program 23

#include<stdio.h>

void main()

int a;

a= 120 > 50 ? !(printf("GATE") && printf("CSE"))||printf("pankaj"):printf("neeraj");

printf("%d",a);
gatecsepankaj1
}

You might also like