Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

COMP1170 Lab Exercise 02

Beoordeling
-
Verkocht
-
Pagina's
5
Cijfer
A+
Geüpload op
03-08-2024
Geschreven in
2024/2025

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 Reference Code: #include stdio.h int main(void) { // initialization int i; printf("NumbertSquarestCubesn"); // iterate i for ten times for (i=0; i=10; i++){ printf("%dt%dt%dn", 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

Meer zien Lees minder
Instelling
COMP1170 Lab
Vak
COMP1170 Lab

Voorbeeld van de inhoud

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;

Geschreven voor

Instelling
COMP1170 Lab
Vak
COMP1170 Lab

Documentinformatie

Geüpload op
3 augustus 2024
Aantal pagina's
5
Geschreven in
2024/2025
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

$14.49
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
StudyCenter1 Teachme2-tutor
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
227
Lid sinds
2 jaar
Aantal volgers
91
Documenten
3850
Laatst verkocht
1 week geleden
Nursing school is hard! Im here to simply the information and make it easier!

My mission is to be your LIGHT in the dark. If you"re worried or having trouble in nursing school, I really want my notes to be your guide! I know they have helped countless others get through and thats all i want for YOU! Stay with me and you will find everything you need to study and pass any tests,quizzes abd exams!

4.3

28 beoordelingen

5
18
4
4
3
4
2
0
1
2

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen