You are on page 1of 13

Republic of the Philippines

Sorsogon State University

Bulan Campus


Milena Mariel
BSIT 1-2

If n is an integer greater than 0, n factorial (n!) is the product: n* (n-1) * (n-2) * (n-3)… *
by convention, 0! = 1. You must write a program that allows a user to enter an integer between
1 and 7. Your program must then compute the factorial of the number entered by the user. Your
solution MUST actually perform a computation (i.e., you may not simply print “5040” to the
screen as a literal value if the input is 7). Example 1 Enter a number: 4 4! = 24 Example 2 Enter a
number: 7 7! = 5040.
Solution: Output:

A binary number is a sequence of bits (binary digits – 0’s and 1’s) of the form BnBn-1……B1
B0, where each Bi is a bit. The decimal equivalent is calculated by Bn * 2n+ Bn-1 * 2n-1 + … + B1
* 2 + B0. Write a program to input a binary number and output the decimal equivalent. The
sample input will not have more than 8 individual bits (i.e., the largest value to be entered is
11111111). Example 1 Enter binary number: 101 In decimal: 5 Example 2 Enter binary number:
11111 In decimal: 31
Solution: Output:
An identifier in C# and most other programming languages must begin with a letter and
then may be followed by any number of letters or digits. It is possible that underscores (_) will
also appear, but only in the middle and never two consecutively. Write a program to read a string
and output whether it is a valid or invalid identifier. Each string will be 10 characters or less in
size. Example 1: Enter id: UAB_HSPC Answer: UAB_HSPC is a valid identifier Example 2: Enter id:
a_b_c__2 Answer: a_b_c__2 is not a valid identifier.
Solution: Output:

General Statement: A town in Death Valley has a water tank that contains 10,000 gallons
of water. If there is no rain, calculate the number of weeks the water will last for an input
weekly water usage. Input: The data set is on a single line. There are an unknown number
of integers in the data set. The integer 0 is used to indicate the end of the data. Output:
Use all upper case letters. The output is to be formatted exactly like that for the sample
output given below. Assumptions: The weekly usage does not exceed 10,000 gallons.
The 0 used to indicate the end of the data is not part of the data for the problem.


General Statement: Given a pair of words (the first is the correct spelling and the second is the
contestant’s spelling of the word) determine if the word is spelled correctly.
The degree of correctness is as follows: CORRECT if it is an exact match ALMOST CORRECT if no
more than 2 letters are wrong WRONG if 3 or more letters are wrong Input:
The first line of the data set for this problem is an integer that represents the number of pairs of
words in the list. Each word is on a separate line.
Output: Output the contestant’s spelling of the word and the rating. All letters are upper case.
The output is to be formatted exactly like that for the sample output given below. Assumptions:
Words contain only upper case letters. The maximum word length is 10.

DECODE Decode a secret message that has been encoded as follows:
1) all letters are upper case
2) a space is indicated by an underscore (_)
3) a number is preceded by the number symbol (#)
4) all other non-letter characters are unchanged
5) each letter was converted to a number that is the sum of its base number and its position in
the word
6) for the base number, A=1, B=2, C=3, etc.

Input: The first line of the data set for this problem is an integer that represents the
number of messages that follow. Each message is on a separate line.
Output: All letters are upper case. The only position a space is to be output is where the
underscore symbol (_) appears in the encoded message.
The output is to be formatted exactly like that for the sample output given below. Assumptions:
There is 1 space between each item on the data line.

Solution Output
General Statement: Read a sentence and output the count of the number of 1 letter words, the
number of 2-letter words, etc. Input: The first line of the data set for this problem is an integer
that represents the number of sentences that follow. Each sentence is on a separate line. Output:
Do not output any counts of 0. The letter counts are to be in ascending order by the number of
letters in the word. All letters are upper case. The output is to be formatted exactly like that for
the sample output given below. Assumptions: Any punctuation in the sentence is not part of the
word length. The maximum word length is 10 letters. The maximum sentence length is 70


General Statement: You have a colleague that is extremely competitive and always tries to “top”
one of your stories. If you say your car is fast, your colleague will say his or her car is faster. If you
say your car is faster, your colleague will say his or her car is fastest. After a few such
conversations, you realize that you can always predict what your colleague will say next.
To demonstrate how annoying this is, you decide to write a program that can accurately predict
the responses of your colleague. Your task is to write this program. Specifically, given any
adjective, your program will return its comparative form by appending “er” to it. Note that if the
adjective already ends in “e”, you should only append “r”. If your program is given an adjective
already in its comparative form, your program should return the superlative form of the adjective
created by simply replacing the “er” with “est”. Your program should consider any string that
ends in “er” to be an adjective in comparative form.
Input: The first line of the input contains an integer n that represents the number of data
collections that follow where each data collection is on a single line. Each input line contains a
string representing an adjective or its comparative form. Each string will be given in all lower case
Output: Your program should produce n lines of output (one for each data collection). Each line
should be in lower case letters. If the input is the comparative form of an adjective (ends in “er”),
your program should output the superlative form. Otherwise, your program should output the
comparative form of the string given as input.
The output is to be formatted exactly like that for the sample output given below. Assumptions:
The value of n will be between 1 and 100, inclusive. Each input word will have between 1 and 30
characters, inclusive.
CS50, Harvard University's introduction to the intellectual enterprises of computer science and the art of


In week 1 I learned about command line conditionals statements and also the data types according to Ug
Lloyd he talks about how to use the Linux command line. the CS50 IDE, or in fact, even a CS50 appliance,
if were familiar with that, or were taking an older version of CS50, it is a cloud-based machine which runs
Ubuntu, which is one of the many flavors of the Linux operating system. Linux operating system is favored
by programmers, many modern Linux distributions have graphical user interfaces, which we also call GUIs,
G-U-I, to allow easy mouse-based navigation, moving around your mouse, double-clicking on icons, and
so on. Still though, as a programmer, and even though the IDE contains the ability to do some graphical
user stuff, clicking, and dragging, and all that, you’ll still be using your terminal window pretty frequently.
And you can do many of the same tasks that you can do with a mouse with keyboard commands. In
conditional statements. conditional expressions allow your programs to make decisions and take different
forks in the road, depending on the values of variables, or based on what the user inputs at the
programmer, at the command line, or if you have a prompt or something like that. And also about data
types, loops and operators.

Week 2

In week 2 it’s all about algorithm summary, arrays, binary search, bubble sort, command line, debugging,
functions, insertion sort, linear search, merge sort, and last the selection sort in CS50 we learned about a
variety of sorting and searching algorithms. And sometimes it can be a little tricky to keep track of what
algorithm does what. We've really only skimmed the surface too, there are many other searching and
sorting algorithms. In this video the basic idea behind selection sort is find the smallest unsorted element
in an array and swap it with the first unsorted element of that array. In Bubble sort, the idea behind that
one is to swap adjacent pairs. So that's the key that helps you remember the difference here. Selection
sort is, so far, find the smallest—bubble sort is swap adjacent pairs. We swap adjacent pairs of elements
if they are out of order, which effectively bubbles larger elements to the right, and at the same time it
also begins to move smaller elements to the left. The worst-case case run time of bubble sort is n squared.
In insertion sort, the basic idea here is shifting. That's the keyword for insertion sort. We're going to step
once through the array from left to right. And as we do, we're going to shift elements we've already seen
to make room for smaller ones that need to fit somewhere back in that sorted portion.

Week 3

In week 3 theirs a lot of knowledge I encounter like call stacks, dynamic memory allocation, file pointers
and so on According to Zamlya Chan in walkthroughs In Recover for example in the memory card,
accidentally deleted all of the photos on it. So the job is to recover all of those JPEGs so that we can see
those pictures again this might seem a little bit daunting, especially because there's no distribution code
to work off of. So first, she talk about how to open the memory card file. Then she talk about how all JPEGs
have a distinct header, so we can use this to find the beginning of a new JPEG. After you’ve done that,
we'll open the JPEG and write 512 bytes at a time until we reach the end of that JPEG and the beginning
of another. From there, we also need to detect once we've reached the end of the memory card. First
things first, we have to open the memory card file. Using the fopen function, but always remember to
check the return value of fopen to ensure that you didn't get some null value.
Week 4

Week 4 in CS50 it covered a lot of different data structures, arrays, and linked lists, and hash tables, and
tries, stacks and queues. I also learn a little about trees and heaps, but really these all just end up being
variations on a theme. There really are these kind of four basic ideas that everything else can boil down
to. Arrays, linked lists, hash tables, and tries. It also discuss about the pros and cons of each in separate
videos on them, but there's a lot of numbers getting thrown around. There's a lot of general thoughts
getting thrown around. I also learned about the speller in walkthroughs Zamlya Chan said it calls check on
each word in a text file that the user provided and prints all of the misspelled words found in that file.
Then, it calls size to determine the number of words in the dictionary. And finally, calls unload to free up
all of the memory used while doing the process. The job is to implement the four functions in dictionary.
c. Load, which loads the dictionary into a data structure that they created. Check, which then checks that
data structure to see if a given word is in the dictionary. Size, which returns the number of words in the
dictionary. And finally, unload, which frees the dictionary from memory.

Week 5

In this week I learned about CSS which is short for Cascading Style Sheets, It is another language we use
when constructing websites. If HTML is what we use to organize the content we want to put on our page,
CSS is the tool that we generally use to customize how our websites look, and how the user experience
really is, interacting with our website. CSS is similar to HTML, CSS is not a programming language. It doesn't
have logic. It doesn't have variables. It doesn't have any sort of that flow related things that C does. It's a
styling language. And its syntax is pretty simple, and just describes how the elements of our page have
certain HTML elements should be modified.

Week 6

In week 6 it’s all about python based on the shorts and also in walkthroughs python is an example of a
pretty commonly used modern programming language. A great language choice for making some complex
operations in C a lot easier. And it also simplifies things like networking and really it's a general purpose
utility language that you can use to do a lot of stuff. It's also very popular right now among data scientists
for processing large sets of data and generating graphs, charts, and results from that. Python is pretty
inspired by C as a lot of modern programming languages are honestly. And its syntax is going to look a
little bit different, but it has some pretty consistent look and feel things to it.

Week 7
It’s all about AJAX, FLAX, JavaScript, and Python in Ajax used to stand for something called Asynchronous
JavaScript in XML. This is a backronym. That's not really what it's called anymore. And actually, most
commonly now, instead of XML, we use JSON. But Ajax has just been the name that's kind of stuck for the
technique. And what Ajax allows us to do is to refresh, basically, sections of our page without the entire
page. Flask in CS50 specifically because it is very lightweight and still quite feature-rich, which means that
it will work well on CS50 IDE where you are using a cloud-based infrastructure, and the amount of space
and memory you have is limited by design. Last is the JavaScript is most commonly used as a client side
scripting language. This means that JavaScript code is written into an HTML page. When a user requests
an HTML page with JavaScript in it, the script is sent to the browser and it's up to the browser to do
something with it.

Week 8

In this week I learned about SQL which stands for the Structured Query Language. The Structure Query
Language is a programming language whose sole purpose in life is to query or ask questions of or retrieve
data from a database. And there are many different implementations of SQL. We can also store date and
time stamps in SQL databases. There's no data type for that that's native to C. But in SQL, there are a
couple of different ways to do this. We can even do more exotic things like store geometry or line strings.
Two of the most popular are the MySQL which is an open-source platform. It is very commonly used to
establish relational databases. And another type, which actually have used in CS50 since 2016, is SQLite,
which has a very similar feature set to MySQL. But it's just a little more lightweight. It's a little easier to
use on CS50 IDE.

Week 9

In week 9 there’s no lecture or problems set that given.

Week 10

In this week I learned about the Reactive programming according to Jordan Reactive programming is a
programming paradigm that allows us to manipulate streams of data with functions. And everything works
asynchronously, meaning that we don't have to wait for the result of operations. It’s an approach problem
solving, and it focuses on three aspects, which were kind of conveyed in that sentence before. One, data
streams. So this is a flow of data objects that start somewhere and are consumed elsewhere. Functional
programming, and you're used to using functions in your normal style of imperative programming. And
so we use functions throughout programming, but functional programming means using functions in a
certain way. And he talk about applying functions to manipulate a stream of data functional programming
is also kind of a central focus topic for CS51. And the last part is asynchronous observers it means that our
code has some parts of our code will execute at different times than other parts.