Computer Science, asked by theepikashree, 8 months ago

Vijay and Ruchi so much interested in gardening and hence she plants more trees in her garden. She plants trees in a rectangular fashion with the order of rows and columns and numbers the trees in a row-wise order. She planted the mango tree only in the 1st row, 1st column and last column. So, given the tree number, your task is to find out whether the given tree is a mango tree or not? Now, write a program to check whether the given number denotes a mango tree or not. INPUT FORMAT: Input consists of 3 integers. The first input denotes the number of rows. The second input denotes the number of columns. The third input denotes the tree number. OUTPUT FORMAT: If the given number is a mango tree, print "Yes". Otherwise, print "No" Refer the sample output for formatting.

Answers

Answered by Shreeya3709
2

Answer:

Answer:

pls pls pls mark it as a brainlist and follow me and also thank me.

#include<iostream>

using namespace std;

int main()

{

 int rows,columns,tree_no;  

 int loc_i,loc_j,count=0;

 cin>>rows;      //no of rows

 cin>>columns;   //no of columns

 cin>>tree_no;  

 int arr[rows][columns];  //2D array

 for(int i=0;i<rows;i++)

   for(int j=0;j<columns;j++)

   {

     count++;

     if(count==tree_no)

     {

       loc_i=i;   //to get exact location of tree in 2D array

       loc_j=j;

     }

   }

 int i=0;  

 int j=0;

 for(j=0;j<columns;j++)

 {

   if(i==loc_i && j==loc_j)

   {

     cout<<"Yes";

     break;

   }

 }

 int flag=0;

 if(flag==0)

 {

    j=0;

     for(i=0;i<rows;i++)

     {

       

       if(i==loc_i && j==loc_j)

       {

       cout<<"Yes";

        break;

       }

     }

   flag=1;

 }

 else if(flag==1)

 {

    j=columns-1;

   for(i=0;i<rows;i++)

   {

     if(i==loc_i &&j==loc_j)

     {   cout<<"Yes";

       break;

     }

   }

 }  

if(loc_i!=0 && loc_j!=0)

   cout<<"No";  

}

Answered by Anonymous
2

Answer:

#include<stdio.h>

#include<stdlib.h>

int main()

{

   int r,c,n,p=1,count=0,a[10][10];

   scanf("%d%d%d",&r,&c,&n);

   for(int i=1;i<=r;i++)

   {

       for(int j=1;j<=c;j++)

       {

           a[i][j]=p;

           p++;

       }

   }

   for(int i=1;i<=c;i++)

   {

       if(a[1][i]==n)

       {

           count++;

       }

   }

   for(int i=1;i<=r;i++)

   {

       if(a[i][1]==n)

       {

           count++;

       }

   }

   for(int i=1;i<=r;i++)

   {

       if(a[i][c]==n)

       {

           count++;

       }

   }

   if(count==1)

   {

       printf("Yes");

   }

   else

   {

       printf("No");

   }

}

Explanation:

Similar questions