Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- int main() {
- int n, i,j,p,s,p1;
- s = 0;
- p1 = 1;
- printf("please enter your integer:");
- scanf_s("%d", &n);
- for (i = 0; i <= n - 1;i++) {
- for (j = i + 1;j <= n; j++)
- {
- p = i*j;
- }
- }
- printf("%d", s);
- _getch();
- return 0;
- }
- #include<stdio.h>
- #include<conio.h>
- #include<math.h> //inclue math.h for pow()
- int main() {
- int n, i,j,p,s,p1;
- s = 0;
- p1 = 1;
- printf("please enter your integer:");
- scanf("%d", &n); //you can simply use scanf() here
- s=p1; //you forgot this
- for (i = 1; i <= n - 1;i++) {
- s+=pow ((i*(i+1)),i); // you dont need 2 for loops
- }
- printf("%d", s);
- _getch();
- return 0;
- }
- #include <stdio.h>
- int main(void)
- {
- int n;
- int sum = 0;
- printf("Please enter the number of terms to sum: ");
- scanf("%d", &n);
- sum += 1; // First term
- /* Start loop with second term */
- for (int i = 2; i < n+1; i++) {
- int base = (i * (i + 1));
- int term = 1;
- for (int j = 0; j < i; j++) {
- term *= base;
- }
- sum += term;
- }
- printf("The sum of the first %d terms of the series is: %dn", n, sum);
- return 0;
- }
- Please enter the number of terms to sum: 2
- The sum of the first 2 terms of the series is: 37
- Please enter the number of terms to sum: 3
- The sum of the first 3 terms of the series is: 1765
- Please enter the number of terms to sum: 4
- The sum of the first 4 terms of the series is: 161765
- 1 + (1*2)^1 + (2*3)^2 + (3*4)^3 + ... + ((n-1)*n)^(n-1)
- int main(void)
- {
- int n;
- unsigned long long sum = 0;
- printf("Please enter the number of terms to sum: ");
- scanf("%d", &n);
- /* Start loop with second term */
- for (int i = 1; i < n+1; i++) {
- unsigned long long base = ((i - 1) * i);
- unsigned long long term = 1;
- for (int j = 0; j < i-1; j++) {
- term *= base;
- }
- sum += term;
- }
- printf("The sum of the first %d terms of the series is: %llun", n, sum);
- return 0;
- }
- Please enter the number of terms to sum: 2
- The sum of the first 2 terms of the series is: 3
- Please enter the number of terms to sum: 3
- The sum of the first 3 terms of the series is: 39
- Please enter the number of terms to sum: 4
- The sum of the first 4 terms of the series is: 1767
- Please enter the number of terms to sum: 5
- The sum of the first 5 terms of the series is: 161767
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement