একটি 'নেস্টেড যদি' একটি if বিবৃতি যা হয় যদি (বা) অন্যের বস্তু। 'if' আরেকটি if (বা) অন্যের ভিতরে স্থাপন করা হয়।
সিনট্যাক্স
নিচে দেওয়া সিনট্যাক্স পড়ুন -
if (condition1){
if (condition2)
stmt1;
else
stmt2;
}
else{
if (condition3)
stmt3;
else
stmt4;
}

উদাহরণ
নেস্টেড ইফ অন্য শর্তসাপেক্ষ অপারেটর -
চালানোর জন্য সি প্রোগ্রামটি নীচে দেওয়া হল#include<stdio.h>
void main (){
int a,b,c,d;
printf("Enter the values of a,b,c: \n");
scanf("%d,%d,%d",&a,&b,&c);
if((a>b)&&(a>c)){//Work with 4 numbers//
if(a>c){
printf("%d is the largest",a);
} else {
printf("%d is the largest",c);
}
} else {
if(b>c){
printf("%d is the largest",b);
} else {
printf("%d is the largest",c);
}
}
} আউটপুট
আপনি নিম্নলিখিত আউটপুট দেখতে পাবেন -
Enter the values of a,b,c: 3,5,8 8 is the largest
উদাহরণ
সংখ্যাটি ইতিবাচক না নেতিবাচক তা পরীক্ষা করার জন্য C প্রোগ্রামটি নিচে দেওয়া হল −
#include <stdio.h>
int main(){
int num;
printf("Enter a number:\n ");
scanf ("%d ", &num);
if(num > 0){
printf("This is positive num:%d\n", num);
}
else if(num < 0){
printf("This is a negative num:%d",num);
} else {
printf("This is a zero:%d",num);
}
return 0;
} আউটপুট
আপনি নিম্নলিখিত আউটপুট দেখতে পাবেন -
Run 1: Enter a number: 23 23=This number is positive Run 2: Enter a number: -56 -56=This number is negative