Computer Science, asked by rinkunavita, 1 day ago

total la EXERICISE QUESTIONS: Q.1 Write a program to input the cost of a book and find the cost of 20 such books Q.2 Write a program to input the year of birth and current year and find the age of a student Q.3 Write a program to print the sum of three numbers taken as input Q.4 Write a program to input the side of a square and find its area Q.5 Write a program to input a number and find the sum of its square and cube. c++​

Answers

Answered by meghana6963
0

Answer:

 

class GFG {

     

    public static int minCost(int ratings[], int n)

    {

        int res = 0;

        int left2right[] = new int[n];

        int right2left[] = new int[n];;

      

        // fill 1 in both array

        Arrays.fill(left2right,  1);

        Arrays.fill(right2left, 1);

      

        // Traverse from left to right and assign

        // minimum possible rating considering

        // only left adjacent

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

            if (ratings[i] > ratings[i - 1])

                left2right[i] = left2right[i - 1] + 1;    

      

        // Traverse from right to left and assign

        // minimum possible rating considering only

        // right adjacent

        for (int i = n - 2; i >= 0; i--)

            if (ratings[i] > ratings[i + 1])

                right2left[i] = right2left[i + 1] + 1;      

          

        // Since we need to follow rating rule for

        // both adjacent, we pick maximum of two

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

            res += Math.max(left2right[i],

                            right2left[i]);

          

        return res;

    }

     

    /* Driver program to test above function */

    public static void main(String[] args)

    {

        int ratings[] = { 1, 6, 8, 3, 4, 1, 5, 7 };

        int n = ratings.length;

        System.out.print(minCost(ratings, n));

         

    }

}

import java.io.*;

 

class GFG {

    static void findAge(int current_date, int current_month,

                    int current_year, int birth_date,

                    int birth_month, int birth_year)

    {

        int month[] = { 31, 28, 31, 30, 31, 30, 31,

                             31, 30, 31, 30, 31 };

 

        // if birth date is greater then current

        // birth_month, then donot count this month

        // and add 30 to the date so as to subtract

        // the date and get the remaining days

        if (birth_date > current_date) {

            current_month = current_month - 1;

            current_date = current_date + month[birth_month - 1];

        }

 

        // if birth month exceeds current month,

        // then do not count this year and add

        // 12 to the month so that we can subtract

        // and find out the difference

        if (birth_month > current_month) {

            current_year = current_year - 1;

            current_month = current_month + 12;

        }

 

        // calculate date, month, year

        int calculated_date = current_date - birth_date;

        int calculated_month = current_month - birth_month;

        int calculated_year = current_year - birth_year;

 

        // print the present age

        System.out.println("Present Age");

        System.out.println("Years: " + calculated_year +

              " Months: " + calculated_month + " Days: " +

              calculated_date);

    }

    public static void main(String[] args)

    {

        // present date

        int current_date = 7;

        int current_month = 12;

        int current_year = 2017;

 

        // birth dd// mm// yyyy

        int birth_date = 16;

        int birth_month = 12;

        int birth_year = 2009;

 

        // function call to print age

Answered by devanandbhosale333
0

Explanation:

mark me as brainleast and give some thanks

Attachments:
Similar questions