Skip to main content
Area Split

Pandu, the farmer, has three sons named, Bhima, Arjuna and Nakula. He has also planed for Three field crop rotation and hand over each field to his three sons.
His sons are fond of even numbers. So they wanted to split the field only if he is able to split it into 3 even number(wrt area) fields. Pandu was so particular that the difference in area of the fields should be minimum because he equally like his three sons. He would split the field only if it is possible, else he would do the normal farming.
Note that it is possible to split only if all three land have positive area.
Write a program to help Pandu in spliting the land.
Input Format:
The first (and the only) input line contains integer that corresponds to the area of the field.
Note: Assume input are positive.

Output Format:
In the first line of the output, print "Yes", if the field can be divided into three parts as per the requirements of Pandu, else print "No".
 
If the first line of the output is "Yes", the next line of the output consists of 3 integers separated by a space, which corresponds to the areas of the divided field. In case of distinct integers, the smallest number should appear first.

Sample Input 1:
6
Sample Output 1:
Yes
2 2 2
 
Sample Input 2:
7
Sample Output 2:
No

//Program
#include<stdio.h>
int main()
{
    int c,k,t,n;
    scanf("%d",&n);
if((n>=6)&&((n%2)==0))
{
    printf("Yes\n");
    if((n%3)==0)
    {
        c=n/3;
        k=n/3;
        t=n/3;
        printf("%d %d %d",c,k,t);
    }
    else if((n%3)==2)
    {
        c=(n-2)/3;
        k=(n-2)/3;
        t=(n+4)/3;
        printf("%d %d %d",c,k,t);
    }
    else if((n%3)==1)
    {
        c=(n-4)/3;
        k=(n+2)/3;
        t=(n+2)/3;
        printf("%d %d %d",c,k,t);
    }
}
else
printf("No");
return 0;

}

Comments

Popular posts from this blog

C Program To Calculate The Revenue The demand for organic food increases every year by 8.9%. Write a program to find the increase in revenue after 3 years. Given the revenue in the first year is ‘x’ crores. Input Format: The first line of the input is an integer that corresponds to the ‘x’ value. Output Format: Output is a float value that corresponds to the revenue after 3 years, rounded off to 2 decimal places. Sample Input: 4 Sample Output: 5.17 //PROGRAM #include<stdio.h> int main() {     int x,i;     float rev;     scanf("%d",&x);     rev=x;     for(i=0;i<3;i++)     {         rev=rev*(1.089);     } printf("%.2f",rev); return 0; }
CROP DETAILS Crop Details A small farmer, Mr.John, use to grow different crops every year in his field. All the crops are being grown using goat manure, farmyard manure, groundnut and neem cake. All the crops are grown organically. He got high yield by using sufficient water and fertilizers at in this year. He will sell his crops in the market. In the market, he wants to maintain the details of each crop that are purchased by customers. Details like crop name, the weight of the crop, cost of the crop Display the details of crops in ascending order of crop names. Create a structure called crop. struct crop{ char cropName[30]; float weight; int cost; }; Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correctly to 2 decimal places. All text in bold corresponds to the input and the rest corresponds to output. Sample Input and Output: Enter the number of Crops 2 Enter the details of Crop 1 Enter name...
FRUIT YIELDING TREE Fruit yielding tree Jack owned a farm which had ‘n’ fruit trees. He sold a tree from the farm which yielded the maximum number of fruits. Now, he wanted to find the tree that yielded the second maximum number of fruits. Write a program to help Jack in finding the second largest fruit yielding tree without sorting. Function Specification: int secondLargest(int *, int); Input format: The first line of the input corresponds to the n. The next n inputs correspond to the number of fruits yielded by each tree.(Assume number of fruits yielded by each tree is unique) Output format: The output is an integer which corresponds to the second largest fruit yielding tree from the farm. Sample Input: 7 7 5 8 6 9 4 3 Sample Output: 8 #include #include int secondLargest(int*a,int n); int main() { int i,n; int *p; scanf("%d",&n); p=(int*)malloc(n*sizeof(int)); for(i=0;i f) ...