Exercise P3.3
Write a program that reads in three
floating point numbers and prints the largest of the three inputs. For example:
Please enter three
numbers: 4 9 2.5
The largest number is 9
#include
<iostream>
#include
<math.h>
using namespace std;
int main()
{
float num1, num2, num3 ;
cout<<"Please enter three
number : ";
cin>>num1>>num2>>num3;
if (num1>num2)
cout<<"The largest number
is "<<num1;
else if
(num2>num3)
cout<<"The
largest number is "<<num2;
else if (num3>num1)
cout<<"The
largest number is "<<num3;
cin.get ();
cin.get ();
return 0;
}
Exercise P3.5
Write a program that translates a number between 0 and 4 into the closest
letter grade. For example, the number 2.8 (which might be the average of
several grades) would be converted to
B-. Break ties in favour of the better grade, for example. 2.85 should be
a B.
#include
<iostream>
#include
<math.h>
using
namespace std;
int
main()
{
double pointer;
int grade;
cout<<"Enter the pointer
: ";
cin>>pointer;
if (pointer == 4.00)
cout<<"Grade : A+";
else if (pointer >=
3.67)
cout<<"Grade
: A";
else if (pointer >= 3.33)
cout<<"Grade
: B+";
else if (pointer >= 3.00)
cout<<"Grade
: B";
else if (pointer >= 2.67)
cout<<"Grade
: B-";
else if (pointer >= 2.33)
cout<<"Grade
: C+";
else
if (pointer >= 2.00)
cout<<"Grade
: C";
else
cout<<"Fail.";
cin.get();
return 0;
}
Exercise P3.7
Write a program that reads in three
strings and sorts them lexicographically.
Example:
Enter three strings: Charlie Able Baker
Able
Bake
Charlie
????? apakah
Exercise P3.12
A year
with 366 days is called a leap year. A year is a leap year if it is divisbile
by four (for example , 1980), except that it is not a leap year if it is
divisible by 100 (for example, 1900);
however, it is a leap year if it is divisible by 400 (for example, 2000). There
were no exceptions before the introduction of the Gregorian calender on October
15, 1582 (1500 was a leap year). Write a program that asks the user for a year
and computes whether that year is a leap year. Your program should only contain
a single if statement.
Apakah?????????
Exercise P3.21
Write a program that prompts the user
for an integer and then prints out all prime numbers up to that integer. For
example, when the user enters 20, the program should print:
2
3
5
7
11
13
17
19
Ooooooooooooooo.......
Bila aku tak tau nak buat..........
Arghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.....
solat dulu.
wassalaam.
2 ulasan:
haha. natang pa ni weh. atas aku paham g. teruk2. hahaha gudluck! hihi :P contact pn latifah weh. haha
hahaha...xtau..macam nak gila buat benda nih..
Catat Ulasan