C++
Program untuk menghitung 10 deret bilangan genap dengan
hasilnya :
2 + 4 + 6 + 8 + 10 + 12 + 14 + 16 + 18 + 20 = 110
#include<iostream.h>
#include<conio.h>
main()
{
int a=2,b=20,n;
for(a=a;a<=b;a+=2)
{
cout<<a;
if(a<b)
{
cout<<"+";
}
}
cout<<"=";
n=b/2;
n=n*(n+1);
cout<<n;
getch();
}
hasilnya :
2 + 4 + 6 + 8 + 10 + 12 + 14 + 16 + 18 + 20 = 110
jawaban :
#include<iostream.h>
#include<conio.h>
main()
{
int a=2,b=20,n;
for(a=a;a<=b;a+=2)
{
cout<<a;
if(a<b)
{
cout<<"+";
}
}
cout<<"=";
n=b/2;
n=n*(n+1);
cout<<n;
getch();
}
No comments: