Develop a function to calculate sum of n even integers starting from a given even integer.
#include <stdio.h>
#include <conio.h>
void main ( )
{
int s, n, t;
clrscr ( );
do
{
printf("\n\n\n\t Enter an even integer to start with..:"); scanf("%d",&s);
}while ( s % 2 != 0 );
printf("\n\t Enter the number of even integers..:"); scanf("%d",&n);
t = sumeven ( s, n );
printf("\n\n\n\t Starting from %d sum of %d even integers = %d",s,n,t);
getch ( );
}
int sumeven ( int s, int n )
{
int i, t = 0;
for ( i = 1; i <= n; i++, s = s+2 )
{
t = t + s;
}
return t;
}
Click here to contact us
#include <stdio.h>
#include <conio.h>
void main ( )
{
int s, n, t;
clrscr ( );
do
{
printf("\n\n\n\t Enter an even integer to start with..:"); scanf("%d",&s);
}while ( s % 2 != 0 );
printf("\n\t Enter the number of even integers..:"); scanf("%d",&n);
t = sumeven ( s, n );
printf("\n\n\n\t Starting from %d sum of %d even integers = %d",s,n,t);
getch ( );
}
int sumeven ( int s, int n )
{
int i, t = 0;
for ( i = 1; i <= n; i++, s = s+2 )
{
t = t + s;
}
return t;
}
Click here to contact us
No comments:
Post a Comment