Jumat, 11 November 2011

Tugas C++ exercises Statement

3.1

#include <iostream.h>
#include <conio.h>
int main ()
{
 int weight;
 int height;
 int hasil;

    cout<<"masukan berat badan anda: ";
    cin>>weight;
    cout<<endl<<"masukan tinggi badan anda: ";
    cin>>height;

    if(weight<height/2.5){
    cout<<"underweight";
    cout<<endl;
    }
    else if (height/2.5<=weight && weight <=height/2.3){
    cout<<"normal";
    cout<<endl;
    }
    else
    cout<<"overweight";
    getch ();
    }
--------------------------------------------------------------
3.2

#include <iostream.h>
#include <conio.h>

int main()
{
 int n=20;
 if(n>=0)
 if(n<10)
 cout<<"small";
 else
 cout<<"negative";
 getch ();
}
--------------------------------------------------------------
3.3

#include <iostream.h>
#include <conio.h>

int main()
{
 int day;
 int month;
 int year;
 char ch;
 cout << "masukan tanggal dd/mm/yy :";
 cin >> day >> ch >> month >> ch >> year;
 switch(month){
 case 1:cout << "january";break;
 case 2:cout << "febuary";break;
 case 3:cout << "maret";break;
 case 4:cout << "april";break;
 case 5:cout << "mey";break;
 case 6:cout << "juni";break;
 case 7:cout << "juli";break;
 case 8:cout << "agustus";break;
 case 9:cout << "september";break;
 case 10:cout << "oktober";break;
 case 11:cout << "november";break;
 case 12:cout << "desember";break;
 }
 cout <<' '<< day <<", "<< 1900 + year << '\n' ;
getch ();
}
--------------------------------------------------------------
3.4

#include <iostream.h>
#include <conio.h>

long faktorial(long n)
{
 if (n>1)
 return (n* faktorial(n-1));
 else
 return (1);
}

int main ()
{
 long l;
 cout<<"Masukkan Bilangan : ";
 cin>>l;
 cout<<l<<"! = "<<faktorial(l);
 getch();
 return 0;
}
--------------------------------------------------------------
3.6

#include <iostream.h>
#include <conio.h>

void main()
{
int a, b;

for (a = 1; a <= 10; ++a)
{

for (b = 2; b <= 10;++b)
cout<<a<<" x "<<b<<" = "<<a*b<<"\n";
}
getch();

Tidak ada komentar:

Posting Komentar