Question

In: Computer Science

1. Write an application that prints the following diamond shape. You may use output statements that...

1. Write an application that prints the following diamond shape. You may use output statements that print a single asterisk (*), a single space or a single newline character. Maximize your use of repetition (with nested for statements), and minimize the number of output statements

2. Modify the application you wrote in Exercise 5.20 (Question 1 Above) to read an odd number in the range 1 to 19 to specify the number of rows in the diamond. Your program should then display a diamond of the appropriate size.

3. (World Population Growth) World population has grown considerably over the centuries. Continued growth could eventually challenge the limits of breathable air, drinkable water, arable crop land and other limited resources. There is evidence that growth has been slowing in recent years and that world population could peak some time this century, then start to decline. For this exercise, research world population growth issues online. Be sure to investigate various viewpoints. Get estimates for the current world population and its growth rate (the percentage by which it is likely to increase this year). Write a program that calculates world population growth each year for the next 75 years, using the simplifying assumption that the current growth rate will stay constant.The first column should display the year from year 1 to year 75. The second column should display the anticipated world population at the end of that year. The third column should display the numerical increase in the world population that would occur that year. Using your results, determine the year in which the population would be double what it is today, if this year's growth rate were to persist.

(Only C programming language) Also, write codes with comments

Solutions

Expert Solution

#include <stdio.h>
#include <stdlib.h>
int main()
{
   for (int i = 0; i <= 4; i++)
   {
       for (int j = i; j < 4; j++)
       {
           printf(" ");
       }
       for (int k = i; k >= 0; k--)
       {
           printf("*");
       }
       for (int k = i-1; k >= 0; k--)
       {
           printf("*");
       }
       printf("\n");
   }


   for (int i = 0; i <= 3; i++)
   {
       for (int j = i; j >=0; j--)
       {
           printf(" ");
       }
       for (int k = i; k <=3; k++)
       {
           printf("*");
       }
       for (int k = i+1; k <= 3; k++)
       {
           printf("*");
       }

       printf("\n");
   }
   system("pause");
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
   int a=7,b,c;
   if (a % 2 == 0)
   {
       b = (a / 2);
       c = (a / 2) -2;
   }
   else
   {
   b = (a / 2) ;
       c = (a / 2)-1;

   }
   for (int i = 0; i <= b; i++)
   {
       for (int j = i; j < b; j++)
       {
           printf(" ");
       }
       for (int k = i; k >= 0; k--)
       {
           printf("*");
       }
       for (int k = i-1; k >= 0; k--)
       {
           printf("*");
       }
       printf("\n");
   }


   for (int i = 0; i <= c; i++)
   {
       for (int j = i;j >=0; j--)
       {
           printf(" ");
       }
       for (int k = i; k <=c; k++)
       {
           printf("*");
       }
       for (int k = i+1; k <= c; k++)
       {
           printf("*");
       }

       printf("\n");
   }
   system("pause");
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
   int count = 0,year=0;
   float previ = 0, population = 7.8;
   float doub = population * 2;
   float rate=1.05;
   printf("Year");
   printf(" Population in billions");
   printf("\n");
   printf("%d", 2020); printf(" %f", population); printf(" %f", 0);
   printf("\n");
   for (int i = 2021; i < 2095; i++)
   {
       float diff=0;
       previ = population;
       population *= rate;
       if ((population >= doub) && (count==0))
       {
           year = i;
           count++;
       }
       diff = population - previ;
       printf("%d",i); printf(" %f", population*rate); printf(" %f", diff);
       printf("\n");
   }

   printf("\n");
   printf("year in which population wil double is %d", year-1);
   system("pause");
}

Comment Down For Any Queries
Please Give A Thumbs Up If You Are Satisfied With The Answer


Related Solutions

Use if statements to write a Java program that inputs a single letter and prints out...
Use if statements to write a Java program that inputs a single letter and prints out the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way: 2 = ABC    3 = DEF   4 = GHI    5 = JKL 6 = MNO   7 = PRS   8 = TUV 9 = WXY No digit corresponds to either Q or Z. For these 2 letters your program should print a message indicating that they are not...
Write an assembly language program that prints your first name in the output. Use immediate addressing...
Write an assembly language program that prints your first name in the output. Use immediate addressing with a hexadecimal constant to designate the operand of CHARO for each letter of your name. Comment each line except STOP and END. Cut and paste the Assembler Listing into your document and paste a screen shot of the Output area of the Pep8. Use the name "Kevin" as example Assembler Listing Screen Shot of Output area of the Pep8 program
Write an application that prints a table of the binary and octal equivalent of the decimal...
Write an application that prints a table of the binary and octal equivalent of the decimal numbers in the range 1 through 256. **Write in JAVA**
Write an application, CylinderStats, that reads the radius and height of a cylinder and prints its...
Write an application, CylinderStats, that reads the radius and height of a cylinder and prints its surface area and volume. Use the following formulas. Print the output to five decimal places. In the formulas, represents the radius and the height.Surface are 2πr(r+ h) Volume:πr2h Design and implement a class Cylinder that contains instance data that represents the cylinder’s radius and height. Define a Cylinder constructor to accept and initialize the radius and height.Include getter and setter methods for all instance...
Write the program that prints the product of 79 and 3.684. The output statement should be...
Write the program that prints the product of 79 and 3.684. The output statement should be descriptive, and should include the printing of all three variables (the two operands as well as the product). Write In C++
Creation of Program Application (Development Task 1) This program should create two output files. You may...
Creation of Program Application (Development Task 1) This program should create two output files. You may use .txt files. Create the following files: Deposists.txt Withdrawls.txt 1. The program application should have the following inputs: Amount for Deposits (Only Accept Positive Amounts) Amount for Withdrawals (Only Accept Positive Amounts). The subsequent program will subtract the positive amount. 2. The program application should have the following outputs: Deposists.txt Withdrawals.txt Total of Deposits and Withdrawals back to the console
Write an application, Phone Numbers, that creates and prints a random phone number of the form...
Write an application, Phone Numbers, that creates and prints a random phone number of the form XXX-XXX-XXXX. Include the dashes in the output. The phone number has some constraints. Do not let the first three digits contain an 3 or 7 (but do not be more restrictive than that) and ensure that the second set of three digits is not greater than 825. Note that any of the digits can be zero and zeroes should be shown.
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Write a...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Write a method public static Object removeSecond (): It removes and returns the element just behind the front element. Precondition: The queue has at least two elements. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ // Queue.java // demonstrates queue // to run this program: C>java QueueApp //////////////////////////////////////////////////////////////// class Queue { private int maxSize; private long[] queArray; private int front; private int rear; private int nItems; //-------------------------------------------------------------- public Queue(int s) // constructor {...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Write a...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Write a method public static void removeDownTo (long n): It pops all values off the stack down to but not including the first element it sees that is equal to the second parameter. If none are equal, leave the stack empty. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ // stack.java // demonstrates stacks //////////////////////////////////////////////////////////////// class StackX { private int maxSize; // size of stack array private long[] stackArray; private int top; //...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Ex1: Write...
You may not use the java.util.Stack class. You may not use the java.util.Queue class. Ex1: Write a program that converts a decimal to binary using a stack. My professor gave me this question to code, is this even possible? if it is can someone code it, in java.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT