Monday, October 29, 2012

Tugas C++


bikin puyeng aja neh tugas.. tapi akhirnya nemu juga rumus listingnya.. hehehe.. :D.. lets cekidot..


#include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{
int a;
for (a=2;a<=10;a+=2)
cout<<a;
getch();
}

output
246810

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{
int a=1;
do
{cout<<a;a+=2;}
while (a<=10);
getch();
}

output
13579

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{
int a=10;
clrscr();
while (a>=1)
{cout<<a;--a;}
getch();
}

output
10987654321

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{
int a,b;
for(a=1;a<=5;a++)
{cout<<endl;
for(b=1;b<=a;b++)
cout<<b;}
for(a=4;a>=1;a--)
{cout<<endl;
for(b=1;b<=a;b++)
cout<<b;}
getch();
}

output
1
12
123
1234
12345
1234
123
12
1

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{
int a,b,c;
for(a=1;a<=5;a++)
{c=0;
for(b=1;b<=a;b++)
{cout<<b;
c+=b;}
cout<<"="<<c<<endl;}
getch();
}

output
1=1
12=3
123=6
1234=10
12345=15

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{
int a,b,c;
for(a=1;a<=10;a+=2)
{c=1;
for(b=1;b<=a;b+=2)
{if(b!=1)
cout<<"*";
cout<<b;
c*=b;}
cout<<"="<<c<<endl;}
getch();
}

output
1=1
1*3=3
1*3*5=15
1*3*5*7=105
1*3*5*7*9=945

#include<conio.h>
#include<iostream.h>
main()
{
int a,b,c;
for(a=1;a<=10;a+=2)
{c=0;
for(b=10;b>=a;b-=2)
{if(b!=10)
cout<<"+";
cout<<b;
c+=b;}
cout<<"="<<c<<endl;}
getch();
}

output
10+8+6+4+2=30
10+8+6+4=28
10+8+6=24
10+8=18
10=10

0 comments:

Post a Comment