View Full Version : sino po marunong gumamit ng C language jan.. turuan nyo po ako...


paranoid_android
11th Mar 2008 Tue, 15:41
:help::pray::help::help::pray::help::help::pray:

Problem 1 – Is it Hot?

Your 8-year old brother is working on a very simple game for his friends. If he gives any number from 1-3, anyone can shout out HOT, LUKE WARM or COLD based on the table below; otherwise, the friends should shout OUT OF RANGE.

1 – HOT
2 - LUKE WARM
3 – COLD

You decided to write a program that will help your brother automate the process.

Input
The first line of input is the number of input cases (n), which is a positive number that does not exceed 30. Each line of the input will contain an integer.

Output
Your program should print HOT, LUKE WARM, COLD or OUT OF RANGE in a single line, for each case.


Sample Input








Sample Output

Problem 2 – Sum It!

Write a program that will generate every third integer, beginning with 2 and continuing for all integers that are less than N. Calculate the sum of those integers that are evenly divisible by 5.

Input
The first line of input is the number of input cases (n), which is a positive number that does not exceed 10. Each line of the input will contain a single positive integer N.

Output
Your program should print the sum in a single line, for each case.



Sample Input








Sample Output


Problem 3 - Perfect Numbers

Greek mathematicians took a special interest in numbers that are equal to the sum of their proper divisors (a proper divisor of n is any divisor less than n itself). They called such numbers perfect numbers. For example, 6 is a perfect number because it is the sum of 1, 2 and 3, which are the integers less than 6 that divide evenly into 6. Similarly, 28 is a perfect number because it is the sum of 1, 2, 4, 7 and 14.

Your job is to create a program that determines if a given positive number is a perfect number or not.

Input
The first line of input is the number of input cases (n), which is a positive number that does not exceed to 30. The succeeding n lines specify the arbitrary number that your program will check if it is a perfect number or not. These numbers are positive integers that should not exceed 4,294,967,296 as well.

Output
For each input case, print out the corresponding answer (“Perfect” or “Not Perfect”) in a single line as standard output.


Sample Input











Sample Output




Problem 4 – Prime Numbers

A prime number (or prime integer, often simply called a "prime" for short) is a positive integer p > 1 that has no positive integer divisors other than 1 and p itself. (More concisely, a prime number p is a positive integer having exactly one positive divisor other than 1.) For example, the only divisors of 13 are 1 and 13, making 13 a prime number, while the number 24 has divisors 1, 2, 3, 4, 6, 8, 12, and 24 (corresponding to the factorization ), making 24 not a prime number.

Your job is to create a program that determines if a given positive number is a prime number or not.

Input
The first line of input is the number of input cases (n), which is a positive number that does not exceed 3,000. The succeeding n lines specify the arbitrary number that your program will check if it is a prime number or not. These numbers are positive integers that should not exceed 50,000.

Output
For each input case, print out the corresponding answer (“Prime” or “Not Prime”) in a single line as standard output.


Sample Input









Sample Output







Problem 5 – The Cube

Write a program to get the surface area and the volume of a cube, given a length of its sides.

The surface area of a cube is six times the area of any side. In other words, the surface area of a cube is the area of the six squares that cover it. The area of one of them is a*a, or a2. Since these are all the same, you can multiply one of them by six, so the surface area of a cube is 6 times one of the sides squared.

The volume is calculated by cubing the side. Volume is measured in "cubic" units. The volume of a figure is the number of cubes required to fill it completely, like blocks in a box. The volume of a cube is side x side x side. Since each side of a square is the same, it can simply be the length of one side cubed.

Required: input(), surfaceArea(), volume() and display() FUNCTIONS

Input
The first line of input is the number of input cases (n), which is a positive number that does not exceed 100. The succeeding n lines specify the arbitrary number that represents the one side of a cube. These numbers are positive floating point numbers should not exceed 5,000.

Output
For each line of input, print out corresponding surface area and volume of the cube, preceded by the “Cube #x - “, where x is the line number. (See sample output format.) Take note that the program displays the values in 2 decimal places.

Sample Input






Sample Output










Problem 6 – Greatest Common Divisor

Write a program that implements the Euclidean Algorithm for finding the greatest common divisor (GCD) of two given positive integers. This algorithm transforms a pair of positive integers (m,n) into a pair (d,0) by repeatedly dividing the larger integer by the smaller integer and replacing the larger with the remainder. When the remainder is 0, the other integer in the pair will be the greatest common divisor of the original pair (and all the intermediate pairs).

For example, if m is 532 and n is 112, then the Euclidean Algorithm reduces the pair (532,112) to (28,0) by

(532,112) → (112,84) → (84,28) → (28,0)

So, 28 is the GCD of 532 and 112.

Required: Use of functions - input(), gcd() and display() and other functions that you believe are necessary (if there are).


Input

The first line of input is the number of input cases (n), which is a positive number that does not exceed 100. The succeeding n lines specify the pair of integers m and n (separated by a space) of which you are computing the GCD for.

Output
For each line of input, print out corresponding greatest common divisor of the given pair of integers preceded by “#x - “ where x is the line number. (See sample output format.)

Sample Input





Sample Output









Problem 7 – Peso-Dollar Conversion

Your brother, Harry, is in the States working. From time to time, he sends you money for some of your school expenses. However, sometimes, since the rate of exchange changes every now and then, you don’t know how much to ask from your brother or how much he has sent you. So, you decided to create a program that would help you and your brother in the conversion from Php to USD and vice versa.

PROGRAM DESIGN
In the program, the conversion should be performed by a function that returns a float value. Call this function from main() and pass the value to be converted. Since the conversion actually depends on the currency in which the value is specified, also pass an indication of the currency to the called function. Take note that you are not going to create an input function.

PROGRAM SKELETON
#include <stdio.h>

void display(int choice, float amount);
float convert( ... );

int main()
{
float rate_of_conversion, amount;
int choice;

scanf( "%f", &rate_of_conversion );
scanf( "%d %f", &choice, &amount );

while( ... )
convert( rate_of_conversion, choice, amount );
}

float convert( ... )
{
float result;
switch( choice )
{
case 1:
...
//computation here
...
case 2:
...
//computation here
...
default:
...
}
return ...
}

void display(int choice, float amount) {
switch( choice )
{
case 1:
printf( "USD%f", ...);
...
case 2:
printf( "Php%f", ...);
...
default:
...
}
}

INPUT
The first line of input indicates the equivalent (in floating-point) of 1 US Dollar in Philippine Peso. Each succeeding line of input contains an integer and a float, which are separated by a space. The integer indicates the conversion, that is, 1 for Peso-to-Dollar and 2 for Dollar-to-Peso. The float is the value to be converted. If the line of input, on the other hand, contains 0, the program will quit running.

OUTPUT
Your program should print the converted floating-point number in a single line for each corresponding line of input. Furthermore, if the first value indicated in the input is a value other than 1 or 2, your program should print the line “Invalid Input” for that line.

SAMPLE INPUT SAMPLE OUTPUT








Problem 8 – Quadratic Equation

In high school algebra, you learned that the standard quadratic equation ax2 + bx + c = 0 has two solutions given by the formula

The first solution is obtained by using + in place of ±; the second is obtained by using – in place of ±. Write a program that calculates the two solutions.

PROGRAM DESIGN
In the program, the computation should be performed by a function that does not return a value. Call this function from main() and pass the values for the a, b and c. The program needs to include math.h interface to be able to use the sqrt() function, which returns a double value. Notice that you are not required to create a separate display function.

PROGRAM SKELETON
#include <stdio.h>
#include <math.h>

double input();
void quadratic( ... );

int main()
{
double a, b, c;

while( 1 )
{
...
a = input();
if( ... ) ...;
b = input();
c = input();
quadratic( a, b, c );
}
return 0;
}

double input()
{
...
return ...
}
void quadratic( ... )
{
double first, second;
...
printf( "%lf %lf\n", first, second );
}

INPUT
Each line of input contains three ints, which are separated by a space. The first indicates the value of a, the second the value of b while the third the value of c. If the value of a is zero, the program will quit running.

OUTPUT
Your program should print the two solutions in a single line for each corresponding line of input. If the quantity under the square root sign is negative, the equation has no real solutions. The program should print the line "No Solutions" in this case.

SAMPLE INPUT


SAMPLE OUTPUT

















Problem 9 – Working with HiLo

Write a program that will get the minimum, maximum and average of N numbers.

Required: Use of functions - minimum(), maximum(), average() and display() and other functions that you believe are necessary (if there are).


Input
The first line of input is the number of input cases (n), which is a positive number that does not exceed 100. The succeeding n lines specify the contents specified for the cases.

Output
For the given inputs, print out each element of the array preceded by “#x-“ where x is the element number. Then, print out the minimum, maximum and average of the elements. (See sample output format.)


Sample Input






Sample Output




















Problem 10 – Goodbye Duplicates!

Write a program that will read in N numbers, each of which is between 1 and 100, inclusive. As each number is read, print it only if it is not a duplicate of a number already read.

Required: Use of functions

Input
The first line of input is the number of input cases (N), which is a positive integer that does not exceed 100. The succeeding N lines specify the integers that the program reads.

Output
Print out each unique element preceded by “#x - “, where x is the element number. Then, print out the elements with duplicates, in the order of their occurrence during input, separated by a space. (See sample output format.)


Sample Input










Sample Output


------=extPart_01C5FBF1.AEC3













Problem 11 – Simple Decimal-to-Roman Conversion

In Roman numerals, characters of the alphabet are used to represent integers as shown in the table below:

Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000

Each character in a Roman numeral stands for the corresponding value. In the simplest case, the value of the Roman numeral as a whole is the sum of the individual character values given in the table. For example, the string "LXXVI" denotes 50 + 10 + 10 + 5 + 1, or 76.

Write a program that returns the ROMAN NUMERAL counterpart of the DECIMAL NUMBER entered by the user using the simplest case in which any of its characters is NOT preceded by a character representing a smaller value, unlike in "CDXL" where 'L' is preceded by 'X' and 'D' is preceded by 'C'.

The conversion should be performed by a function named DecimalToRoman() that takes a decimal number and returns the corresponding roman numeral number.

INPUT
The first line of input is the number of input cases (n), which is a positive number that does not exceed 20. The line of input should be a decimal value to be converted.

OUTPUT
Each line of output contains the ROMAN NUMERAL (I, V, X, L, C, D, and M) equivalent of the DECIMAL NUMBER keyed in.

SAMPLE INPUT SAMPLE OUTPUT




Problem 12 - The King’s Order

Once upon a time, in a far land, a king ordered his people to change their currency system, converting paper bills into gold and silver coins.

Rules in Exchange:

You could only pay a good only by using all gold or all silver coins.
No instance shall gold and silver coins will be used at the same time in paying or in changing.

For example:

Value of GOLD: 2
Value of SILVER: 1

Amount to Pay 3 11 1 8
Amount Given 2 Golds 6 Golds 1 Silver 4 Golds
Amount Returned 1 Silver 1 Silver None None

Input
The first line of input contains the values for gold and silver coins respectively. The second line of input is an unsigned integer which represents the number of test cases. The following lines contain the Amount to Pay.

Output
For each line of test cases, display the possible combination of the Amount to Pay using the defined values of gold and silver coins. Note: Output the least number of possible combination of coins.

Sample Input

5 3
3
3
5
7

Sample Output

1 Gold
2 Golds, 1 Silver
3 Silvers



Problem 13 – Write My Check

A business firm is hiring you to automate their billing system. One of the features of the system is to automate the conversion of the amount in the check into words.

Input
Each line of input contains one unsigned integer which is less than 100,000,000. The last line of the input must contain “0”.

Output
For each of the test cases except the last, display the resulting word conversions.

Sample Input

55
3998
1000001

Sample Output

Fifty-five
Three thousand, nine hundred, ninety-nine
One million one























Problem 14 - Primary Arithmetic

Children are taught to add multi-digit numbers from right to left, one digit at a time. Many find the “carry operation”, where 1 is carried from one digit position to the next, to be a significant challenge. Your job is to count the number of carry operations for each of a set of addition problems so that educators may assess their difficulty.

Input
Each line of input contains two unsigned integers with less than 10 digits. The last line of input contains “0 0”.

Output
For each line of input except the last, compute the number of carry operations that result from adding the two numbers and print them in the format shown.

Sample Input

123 456
555 555
123 594
0 0

Sample Output

No carry operations.
3 carry operations.
1 carry operation.



















Problem 15 – Uni-directional TSP

Background
Problems that require minimum paths through some domain appear in many different areas of computer science. For example, one of the constraints in VLSI routing problems is minimizing wire length. The Traveling Salesperson Problem (TSP) -- finding whether all the cities in a salesperson's route can be visited exactly once with a specified limit on travel time -- is one of the canonical examples of an NP-complete problem; solutions appear to require an inordinate amount of time to generate, but are simple to check.
This problem deals with finding a minimal path through a grid of points while traveling only from left to right.

The Problem
Given an matrix of integers, you are to write a program that computes a path of minimal weight. A path starts anywhere in column 1 (the first column) and consists of a sequence of steps terminating in column n (the last column). A step consists of traveling from column i to column i+1 in an adjacent (horizontal or diagonal) row. The first and last rows (rows 1 and m) of a matrix are considered adjacent, i.e., the matrix ``wraps'' so that it represents a horizontal cylinder. Legal steps are illustrated below.

The weight of a path is the sum of the integers in each of the n cells of the matrix that are visited.
For example, two slightly different 5x6 matrices are shown below (the only difference is the numbers in the bottom row).

The minimal path is illustrated for each matrix. Note that the path for the matrix on the right takes advantage of the adjacency property of the first and last rows.

The Input
The input consists of a sequence of matrix specifications. Each matrix specification consists of the row and column dimensions in that order on a line followed by integers where m is the row dimension and n is the column dimension. The integers appear in the input in row major order, i.e., the first n integers constitute the first row of the matrix, the second n integers constitute the second row and so on. The integers on a line will be separated from other integers by one or more spaces. Note: integers are not restricted to being positive. There will be one or more matrix specifications in the input.
For each specification the number of rows will be between 1 and 10 inclusive; the number of columns will be between 1 and 100 inclusive. No path's weight will exceed integer values represented using 30 bits.

The Output
Two lines should be output for each matrix specification in the input file, the first line represents a minimal-weight path, and the second line is the cost of a minimal path. The path consists of a sequence of n integers (separated by one or more spaces) representing the rows that constitute the minimal path. If there is more than one path of minimal weight the path that is lexicographically smallest should be output.

Sample Input
5 6
3 4 1 2 8 6
6 1 8 2 7 4
5 9 3 9 9 5
8 4 1 3 2 6
3 7 2 8 6 4
5 6
3 4 1 2 8 6
6 1 8 2 7 4
5 9 3 9 9 5
8 4 1 3 2 6
3 7 2 1 2 3
2 2
9 10 9 10

Sample Output
1 2 3 4 4 5
16
1 2 1 5 4 5
11
1 1
19



kelangan ko po talaga itoo.. salamat po talaga...:pray::pray::pray::pray:

chester0607
11th Mar 2008 Tue, 18:27
project mu yan noh!!!!!!!!too bad hanggang 4x4 matrix plng alam ko

dodsss
29th Feb 2012 Wed, 21:43
HI MERON KA NABANG CODES NIYAN???PWEDE PA HINGEE?PLSSSSSSSSSSSSS? KAILANGAN KU TALAGA CODES NA YAN:pray: