100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COMP1170 Lab Exercise 02 $13.99   Add to cart

Exam (elaborations)

COMP1170 Lab Exercise 02

 1 view  0 purchase
  • Course
  • COMP1170 Lab
  • Institution
  • COMP1170 Lab

COMP1170 Lab Exercise 02 Questions and Answers Task 1: Selection structures: if statement Task 2: Using only the techniques you learned in this chapter, write a program that calculate the squares and cubes of the number from 0 to 10 and uses tabs to print the following table o...

[Show more]

Preview 2 out of 5  pages

  • August 3, 2024
  • 5
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • comp1170 lab exercise 02
  • COMP1170 Lab
  • COMP1170 Lab
avatar-seller
StudyCenter1
COMP1170 Lab Exercise 02

Questions and Answers

Task 1: Selection structures: if statement

Task 2: Using only the techniques you learned in this chapter, write a
program that calculate the squares and cubes of the number from 0 to
10 and uses tabs to print the following table of values:
number sequare cube
0 0 0
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000

Reference Code:

#include <stdio.h>

int main(void)
{
// initialization
int i;

printf("Number\tSquares\tCubes\n");

// iterate i for ten times
for (i=0; i<=10; i++){
printf("%d\t%d\t%d\n", i, i*i, i*i*i);
}

return 0;
}

Note: we use a repetition sturcure by for statement.

, Task 3: Write a program that reads in the radius of a circle and prints
the circle’s diameter, circumference and area.

Hints:
1. using floating-point numbers %f instead of %d to print out the result.
2. float pi; pi = 3.14156.
3. diameter = 2*radius; circumference = 2*pi*radius; area = pi*radius*radius.

Reference Code:

#include <stdio.h>

int main(void)
{
// initialization
float radius, diameter, circumference, area;
float pi = 3.14156;

// input radius
printf("Please enter the radius:\n");
scanf("%f", &radius);

// calculate diameter, circumference and area
diameter = 2 * radius;
circumference = 2 * radius * pi;
area = radius * radius * pi;

// output and termination
printf("Diameter is: %f\n", diameter);
printf("Circumference is: %f\n", circumference);
printf("Area is: %f\n", area);

// return the value of main function
return 0;
}



Task 4: Write a program that asks the users to enter two numbers, and
obtains the two numbers from the user and prints the sum, product,
difference, quotient and remainder of the two numbers.

Reference Code:
#include <stdio.h>

int main(void)
{
// initialization
int num1, num2;

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller StudyCenter1. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $13.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

77254 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$13.99
  • (0)
  Add to cart