===========================================================================
CODING
#include<all.h>
void main()
{
clrscr();
int i,n,N=0,W,sum;
cout<<"\nEnter number: ";
cin>>n;
cout<<"\n\n\n";
for(i=1,sum=0;i<=n;i=i+1)
{
N=i;
if(i%2!=0)
{
sum=i+sum;
if(N<=n-1)
cout<<N<<" - ";
else if(N==n)
cout<<N<<" = ";
}
else
{
sum=-i+sum;
if(N<=n-1)
cout<<N<<" + ";
else if(N==n)
cout<<N<<" = ";
}
}
cout<<sum;
getch();
}
CODING
#include<all.h>
void main()
{
clrscr();
int i,n,N=0,W,sum;
cout<<"\nEnter number: ";
cin>>n;
cout<<"\n\n\n";
for(i=1,sum=0;i<=n;i=i+1)
{
N=i;
if(i%2!=0)
{
sum=i+sum;
if(N<=n-1)
cout<<N<<" - ";
else if(N==n)
cout<<N<<" = ";
}
else
{
sum=-i+sum;
if(N<=n-1)
cout<<N<<" + ";
else if(N==n)
cout<<N<<" = ";
}
}
cout<<sum;
getch();
}
===========================================================================
No comments:
Post a Comment