// ---------------------------------------------------------
// Algorithm and Programming in C
// ---------------------------------------------------------
//
// Author : adhita muslim
// Written in C Language using MS Visual C++
// Copyright : 2007
//
// ---------------------------------------------------------
#include
int total(int n)
{
int i,deret_genap,deret_ganjil,jum;
for(i=1;i<=n;i++)
{
printf("%2i",i);
if(i!=n)
{
for(i=2;i<=n;i++)
{
if(i%2==0)
{
printf(" + %2i",i);
deret_genap+=i;
}
else
{
printf(" - %2i",i);
deret_ganjil+=i;
}
}
}
}
jum=1+deret_genap-deret_ganjil;
return jum;
}
void main()
{
int n;
printf("Input number : ");scanf("%d",&n);
printf("\n");
printf(" = %2i\n",total(n));
printf("\n");
}
Home »Unlabelled » Deret Plus dan Minus
Deret Plus dan Minus
Posted by
Adhit
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment