Sunday, October 28, 2012

Membuat Program Loop For

NAMA : ILFAN RIFA'I
NIM : TI111025

Membuat Program Loop For

Soal :
Gunakan loop for untuk membuat program sebagai berikut :
input : n
output : 1 -2 3 -4 5 -6 7 -8 …n 
 
Jawab :
 
#include "iostream.h"

int main()
{
    int i, x;
    cout<<"\t                             Loop For"<<'\n';
    cout<<"\t                           ILFAN RIFA'I"<<'\n';
    cout<<"\t                             TI111025"<<'\n';
    cout<<"\t               ****www.ilfan-rifai.blogspot.com****"<<'\n';
    cout<<"       ===================================================================="<<'\n'<<'\n';

    cout<<"\tMasukkan Angka : ";
    cin>>i;
    for(x=1;x<=i;x++)
        {if(x%2==0)
        {cout<<" "<<x*-1;}
        else cout<<"  "<<x;
        }
}
Output :





Related Post



Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 comments: on "Membuat Program Loop For"

Post a Comment