comp lab

13
A PAMANTASAN NG LUNGSOD NG MAYNIL (University of the City of Manila) IN PARTIAL FULLFILMENT IN THE SUBJECT COMPUTER FUNDAMENTALS AND PROGRAMMING I FOR COMPUTER STUDIES DEPARTMENT SUBMITTED BY REYES,ANTONI CARLO 2012-10562 SUBMITTED TO PROFESSOR CHARITO M. MOLINA OCTOBER 3, 2013

Upload: jonathan

Post on 16-Dec-2015

217 views

Category:

Documents


0 download

DESCRIPTION

comp lab

TRANSCRIPT

PAMANTASAN NG LUNGSOD NG MAYNIL(University of the City of Manila)IN PARTIAL FULLFILMENT IN THE SUBJECT COMPUTER FUNDAMENTALS AND PROGRAMMING I FOR COMPUTER STUDIES DEPARTMENTSUBMITTED BY

REYES,ANTONI CARLO 2012-10562SUBMITTED TO PROFESSOR CHARITO M. MOLINAOCTOBER 3, 2013EXERCISE NO. 3WRITE A PROGRAM TO READ A NUMBER OF UNITS OF LENGTH (A FLOAT) AND PRINT OUT

THE AREA OF A CIRCLE OF THAT RADIUS. ASSUME THAT THE VALUE OF PI IS 3.1416. YOUR OUTPUT SHOULD TAKE THE FORM: THE AREA OF A CIRCLE OF RADIUS UNITS IS SQUARE UNITS.

ALGORITHM1. Initialize value pi equals 3.14162. Input the value for radius(a).3. Get the value of area (b) of the circle using the formula b=pi*a*a4. Print the value of the area of the circle.5. End of program

#include

#include

#define pi 3.1416

float a,b;

main ()

{

printf("Enter the value of lenght/radius:\n");

scanf("%f",&a);

b=pi*a*a;

printf("The area of a circle of radius %f units is %f square units.",a,b);

getch ();

}

LINE 1: Declared preprocessor by means of #includeLINE 2: Declared #include< conio.h>, for getch functionLINE 3: Initialize value of pi to 3.1416LINE 4: Global declaration of variable a and b as float.LINE 5: main () function

LINE 6: open curly bracket

LINE 7: print f command to print the word Enter the value of lenght/radius:

LINE 8: Declared scan f

LINE 9: Declaration of formula for the area of the circleLINE 10: Print f command to print the value of area of the circle

LINE 11: declared getch()

LINE 12: close curly bracket,end of program.OUTPUT

EXERCISE NO. 1WRITE C PROGRAM TO PERFORM THE CONVERSIONS OF DOLLAR TO PESO.

ALGORITHM1. Input value of dollar(a)2. Get the corresponding value on peso(p) with the formula p=a*43.363. Print the value of peso4. End of program

#include

#include

int a;

float b;

main ()

{

printf("Enter the value of dollar:\n");

scanf("%d",&a);

b=a*43.36; printf("%d Dollars is equal to %.2f Pesos.\n",a,b); getch ();

}

LINE 1: Declared preprocessor by means of #include

LINE 2: Declared #include for getch functionLINE 3: Global Declaration of data type and variable a as integer

LINE 4: Global Declaration of data type and variable b as floatLINE 5: main () function

LINE 6: open curly bracket

LINE 7: print f command to print the word Enter the value of dollar:

LINE 8: Declared scan f

LINE 9: Declaration of formula for the conversion

LINE 10: Print f command to print the value in peso

LINE 11: declared getch()

LINE 12: close curly bracket, end of programOUTPUT

EXERCISE NO. 2WRITE A PROGRAM TO READ A FLOAT REPRESENTING A NUMBER OF DEGREES CELSIUS, AND PRINT AS A FLOAT THE EQUIVALENT TEMPERATURE IN DEGREES FARENHEIT. PRINT YOUR RESULTS IN A FORM SUCH AS 100.0 DEGREES CELSIUS CONVERTS TO 212.0 DEGREES FARENHEIT.

ALGORITHM1. Input value of temperature in degrees Celsius.2. Get the corresponding value of temperature in degrees fahrenheit with the formula f=c*9/5+32.3. Print the temperature value in degrees Fahrenheit.4. End of program

#include

#include

float a,b;

main ()

{printf("Enter temperature in degrees Celsius:\n");

scanf("%f",&a); b=a*9/5+32;

printf("%.1f degrees Celsius converts to %.1f degrees Fahrenheit.",a,b); getch ();

}

LINE 1: Declared preprocessor by means of #include

LINE 2: Declared #include< conio.h> for getch functionLINE 3: Global Declaration of data type and variable a and b as float

LINE 4: main () function

LINE 5: open curly bracket

LINE 6: print f command to print the word Enter temperature in degree celsius:

LINE 7: Declared scan f

LINE 8: Declaration of formula for the conversion

LINE 9: Print f command to print the value in peso

LINE 10: declared getch()

LINE 11: close curly bracket, end of program.

OUTPUT

A

CODES

CODING EXPLANATION

CODES

CODING EXPLANATION

CODES

CODING EXPLANATION