In: Computer Science
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
#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