Skip to content

Instantly share code, notes, and snippets.

@sohan110111
Created December 28, 2022 21:09
Show Gist options
  • Save sohan110111/819bcc8268c153e3a067f457248f87e1 to your computer and use it in GitHub Desktop.
Save sohan110111/819bcc8268c153e3a067f457248f87e1 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
int main(void)
{
int max;
int res = 0;
// input last term
// printf("Enter the maximum: ");
scanf("%d", &max);
int i = 1;
char c = 253; // 253 is the ascii code for the square symbol
while (1)
{
if (i > max)
{
printf(" = %d", res);
break;
}
else
{
if (i == max)
{
printf("%d%c", i, c);
}
else
{
printf("%d%c+", i, c);
}
res = res + pow(i, 2);
i++;
}
}
}
#include <stdio.h>
#include <math.h>
int main(void)
{
int max;
int res = 0;
// input last term
// printf("Enter the maximum: ");
scanf("%d", &max);
int i = 1;
while (1)
{
if (i > max)
{
printf(" = %d", res);
break;
}
else
{
if (i == max)
{
printf("%dx%d", i, i + 1);
}
else
{
printf("%dx%d + ", i, i + 1);
}
res = res + i * (i + 1);
i++;
}
}
}
#include <stdio.h>
int main(void)
{
// sum of the series
int sum = 0;
// input last term
// printf("Enter the maximum: ");
int max;
scanf("%d", &max);
// loop
int i = 5;
while (1)
{
if (i > max)
{
break; // the last term cannot exceed the maximum
}
printf("%d", i);
i += i;
if (i > max)
{
break;
}
else
{
printf(",");
}
}
return 0;
}
@sohan110111
Copy link
Author

  1. Write a C program that will print all the numbers of the following series up to n (i.e. the last term cannot exceed n).
    SAMPLE INPUT
    30
    100
    SAMPLE OUTPUT
    5,10,20
    5,10,20,40,80

  2. Write a C program that will calculate the sum of the mentioned series up to its n terms.
    SAMPLE INPUT
    5
    8
    SAMPLE OUTPUT
    12+22+32+4²+52 = 55
    1²+2²+3²+4²+5²+6²+7²+8² = 204

  3. Write a C program that will calculate the sum of the mentioned series up to its n terms.
    SAMPLE INPUT
    5
    8
    SAMPLE OUTPUT
    1x2 + 2x3 + 3x4 + 4x5 + 5x6 = 70
    1x2 + 2x3 + 3x4 + 4x5 +5x6+6x7+7x8+ 8x9= 240

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment