0% found this document useful (0 votes)
34 views14 pages

Name: Carbajal Genylle H. Course/Year: BSIT 1D Computer Programming 112

The document contains code snippets from exercises on computer programming. It includes code to print odd numbers from 20 to 1, calculate the Fibonacci sequence, find the factorial of a number, print triangle shapes, debug for loops, perform math operations on variables, calculate the area of a triangle, convert between Celsius and Fahrenheit, find the largest number in an array, and store negative numbers from an array in a new array. The code demonstrates basic programming concepts like loops, arrays, math functions, and conditional statements.

Uploaded by

Rennie Hapor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views14 pages

Name: Carbajal Genylle H. Course/Year: BSIT 1D Computer Programming 112

The document contains code snippets from exercises on computer programming. It includes code to print odd numbers from 20 to 1, calculate the Fibonacci sequence, find the factorial of a number, print triangle shapes, debug for loops, perform math operations on variables, calculate the area of a triangle, convert between Celsius and Fahrenheit, find the largest number in an array, and store negative numbers from an array in a new array. The code demonstrates basic programming concepts like loops, arrays, math functions, and conditional statements.

Uploaded by

Rennie Hapor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Name: CARBAJAL GENYLLE H.

Course/Year: BSIT 1D
COMPUTER PROGRAMMING 112

EXERCISE 6.1: Odd Number from 20 to 1

Start

Int x=20

for(x=20; x>1; No
x--)

Yes

No

If(x%2 !=0)

Yes

cout<<x<< “ ”<<endl;

End
Name: CARBAJAL GENYLLE H. Course/Year: BSIT-1D COMPUTERPROGRAMMING 112
Exercise 6.2: Fibonacci Sequence

Start

int n = 11, t1 = 0, t2 = 1, nextTerm = 0;

cout<<”Fibonacci Series: ”;

int i =1;

While(i<=n) No
i++;

Yes

No
if(i==1)

Yes

cout<<t1<< “,”;

No
if(i==2)

Yes

cout<<t2<<”,”;

End

nextTerm = t1 +t2;

t1 + t2;
cout<< t2 = nextTerm;
nextTerm<<”,”;
Name:CARBAJAL GENYLLE H. Course/Section: BSIT 1D
COMPUTER PROGRAMMING 112

Exercise 6.3: Factorial Number

Start

int n, f=1, i=1;

cout<<”\n Enter The


Number:”;

cin>>n;

f=f*I;

i++;

No
while(i<=n);

Yes

cout<<”n\ Factorial Number


is “<<f;

End
Name: CARBAJAL GENYLLE H. Course/Year: BSIT 1D
COMPUTER PROGRAMMING 112

Exercise 6.4: Shape of Triangle

Start

for(int x=10;
x>=1; x--)

NO

YES

for(int y=1;
y<=x; y++)

cout<<”*”;

cout<<endl;

End
YES
Name: CARBAJAL GENYLLE H. Course/Year: BSIT 1D COMPUTER
PROGRAMMING 112

Exercise 6.5: Debugging

Start

int i;

for(int i = 1; No
i<=5; i++)

Yes

cout<<i<<” “;

End
Name: CARBAJAL GENYLLE H. Course/Year: BSIT 1D COMPUTER
PROGRAMMING 112

Exercise 7.1: Math Operation

Start

double num1, num2;


int sum, sub, mul, div, mod;

sum = num1 + num2;


sub = num1 - num2;
mul = num1 * num2;
div = num1 / num2;
mod = num % num2;

cout << "Addition :"<< sum;


cout << "Subtraction :<< sub;
cout<<”Multiplication :”<< mul;
cout<<”Division :”<< div;
cout<<”Modulos :<< mod;

End
Name: CARBAJAL GENYLLE H. Course/Yea: BSIT 1D COMPUTER
PROGRAMMING 112

Exercise 7.2: Area of Triangle

Start

double compute(int base, int


height)

int res;

int res = (base * height) / 2

cout<<”Area of Triangle is : ”<<


res;

End
Name: CARBAJAL GENYLLE H. Course/Year: BSIT 1D
COMPUTER PROGRAMMING 112

Exercise 7.3: Degrees Celcius and Fahrenheit

Start

int choices, celcius, depth

double res;

No No
else if(choices cout << "Invalid
if (choices == 1)
== 2) Entry" ;

Yes Yes

res = (1.8 * celcius) + 32; res = (10 * depth) + 20;

cout << "Converted to


cout << "Converted to
celcius" << res;
fahrenheit" << res;

End
Name: CARBAJAL GENYLLE H. Course/Year: BSIT 1D COMPUTER
PROGRAMMING 112

Exercise 7.4: Debugging

Start

cout<<”You Called me!!!”;

cout<<”Yes, I called you…”;

End
Name: CARBAJAL GENYLLE H. Course/Year: BSIT 1D COMPUTER
PROGRAMMING 112

Exercise 8.1: Largest Integer in the array

Start

int arr[10] =
{42,21,80,12,14,54,31,53,32,58};

int index =0;

for(int i = 0;i <=9 ; No


++i)

Yes

No
if(arr[0] < arr[i])

Yes

arr[0] = arr[i];

index = i;

cout << endl<< endl << "Largest


number in the array is " << arr[0]
<< " @ index " << index;

End
Name: CARBAJAL GENYLLE H. Course/Year: BSIT 1D COMPUTER
PROGRAMMING 112

Exercise 8.2: Negative Numbers

Start

int i, n;

int arr[100];

int negativeArr[9];

int j =0;

int total = 0;

for(i = 0;i < n;


++i)

Yes

No No
if(arr[i] < 0)

Yes

negativeArr[j++]= arr[i];

Yes No
for(i = 0;i < if(negativeA
9; ++i) rr[i] !=0)

Yes

cout << negativeArr[i] << " ";

End cout << endl << total <<"


Negative number”;
Name: CARBAJAL GENYLLE H. Course/Year: BSIT 1D COMPUTER
PROGRAMMING 112

Exercise 8.3: Insert and Display

Start

int row, col, i, j, arr[10][10];

row=10;

col =10;

int count =1;

No
for(i=0;
i<row; i++)

Yes

for(j=0; No
j<col; j++)

Yes
End
arr[i][j] = count;

count++;

No

for(i=0; cout << arr[i][j] << " ";


i<row; i++)

Yes

Yes

No No if(arr[i]
for(j=0;
Yes [j] < 10)
j<col; j++)
Name: CARBAJAL GENYLLE H. Course/Year: BSIT 1D COMPUTER
PROGRAMMING 112

Exercise 8.4: Debugging

Start

int array[5];

array[0] = 3;

array[1] = 4;

array[2] = 5;

array[3] = 1;

array[4] = 2;

for(int i=0;
i<5; i++)

cout<<array[i]<<" ";

End

You might also like