Sunteți pe pagina 1din 6

CS10-2L Introduction to Programming Laboratory

Laboratory Exercise
3 (Iterative Program Structure
!ate
"ame Section
#i$e "ame% LE3&Surname'doc
(o be u)$oaded in *ood$e
Problem Statement:
1' Create a +$o,c-art and C.. )rogram t-at ,i$$ )rom)t t-e user to in)ut a number and
out)ut its +actoria$' /y de+au$t +actoria$ o+ 0ero (0 is e1ua$ to 1' 2n in)ut o+ negative
number s-ou$d dis)$ay an error message'
Exam)$e %
In)ut number % 3
#actoria$ o+ 3 % 3 (Sam)$e com)utation % 1 x 2 x 3 4 3
2' Create a a +$o,c-art and C.. )rogram t-at ,i$$ generate a 10 X 10 Multiplication
table.
Sam)$e 5ut)ut%
1 x 1 4 1
%
%
1 x 10 4 10
%
%
10 x 1 4 10
%
%
10 x 10 4 100
3' 2 )rime number is a number t-at -as on$y t,o +actors6 t-at is one (1 and itse$+'
Create a +$o,c-art and C.. )rogram t-at ,i$$ generate t-e +irst ten Prime numbers'

(-e +irst ten )rime numbers are% 26 36 76 86 116 136 186 196 236 and 29
Laboratory Exercise Score Sheet
Criteria Score
1'1

"eatness and Correctness o+ #$o,c-art :


1'2

Pro)er Indention o+ C.. )rogram 2


1'3

Inte$$igent;!escri)tive naming o+ variab$es :


1':

In+orms t-e <ser ,-at to in)ut :


1'7

Correct Process (Condition and #ormu$a 1:


1'3

Correct 5ut)ut :
2'1

"eatness and Correctness o+ #$o,c-art :


2'2

Pro)er Indention o+ C.. )rogram 2


2'3

Inte$$igent;!escri)tive naming o+ variab$es :


2':

Correct Process (Condition and #ormu$a 17


2'7

Correct 5ut)ut :
3'1

"eatness and Correctness o+ #$o,c-art :


3'2

Pro)er Indention o+ C.. )rogram 2


3'3

Inte$$igent;!escri)tive naming o+ variab$es :


3':

Correct Process (Condition and #ormu$a 17


3'7

Correct 5ut)ut :
:' Exercise +inis-ed;submitted ,it-in time-+rame 10

(ota$ 100
_______________________ _______________
Engr' Cristina 2' Pascua !ate
CS10-2L Introduction to Programming Laboratory
Laboratory Exercise
3 (Iterative Program Structure
!ate
"ame Morcoso, James Oliver C. Section
2ns,er S-eet%
1.) Flowchart
C++ Program
#include<iostream>
using namespace std;
int main()
{
int n, B, C=1;
cout<<"Please enter a positive
integer ";
cin>>n;
i!(n<")
cout<<"#nvalid
$alue%&n";
else
!or (B=1; B<=n; B'')
C= C ( B;
cout<<")our *actorial
is "<<C<<endl;
return ";
+
2' Flowchart
C++ Program
#include<iostream>
using namespace std;
int main()
{
cout << ", multiplication ta-le" << endl
<< " 1&t.&t/&t0&t1&t2&t3&t4&t5" << endl
<< "" << endl;
!or(int c = 1; c < 1"; c'')
{
cout << c << "6 ";
!or(int i = 1; i < 1"; i'')
{
cout << i ( c << 7&t7;
+
cout << endl;
+
return ";
+
3' Flowchart
C++ Program
#include<iostream>
using namespace std;
int main()
{
int primenum,!actor,ctr;

primenum=.;
do{
ctr=1;
!actor=";
do{
i!(primenum 8 ctr==")
!actor = !actor'1;
ctr=ctr'1;
+9:ile(ctr<=primenum);

i!(!actor==.)
cout<<primenum<<endl;
primenum=primenum'1;
+9:ile(primenum<=.5);
return ";
+

S-ar putea să vă placă și