SUBMISSION LINK
https://www.hackerrank.com/contests/y16csecs/challenges/y16-sum-of-alternative-sum
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
long long n,se=0,so=0,i;
scanf("%lld",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
{
se+=i;
}
else
{
so+=i;
}
}
printf("%lld %lld",se,so);
return 0;
}
https://www.hackerrank.com/contests/y16csecs/challenges/y16-sum-of-alternative-sum
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
long long n,se=0,so=0,i;
scanf("%lld",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
{
se+=i;
}
else
{
so+=i;
}
}
printf("%lld %lld",se,so);
return 0;
}
Comments
Post a Comment