Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. int main() {
  4.  
  5. int n, i,j,p,s,p1;
  6. s = 0;
  7. p1 = 1;
  8. printf("please enter your integer:");
  9. scanf_s("%d", &n);
  10.  
  11.  
  12.  
  13. for (i = 0; i <= n - 1;i++) {
  14.  
  15. for (j = i + 1;j <= n; j++)
  16.  
  17. {
  18. p = i*j;
  19.  
  20. }
  21. }
  22.  
  23.  
  24.  
  25.  
  26. printf("%d", s);
  27. _getch();
  28. return 0;
  29. }
  30.  
  31. #include<stdio.h>
  32. #include<conio.h>
  33. #include<math.h> //inclue math.h for pow()
  34. int main() {
  35.  
  36. int n, i,j,p,s,p1;
  37. s = 0;
  38. p1 = 1;
  39. printf("please enter your integer:");
  40. scanf("%d", &n); //you can simply use scanf() here
  41. s=p1; //you forgot this
  42.  
  43.  
  44. for (i = 1; i <= n - 1;i++) {
  45.  
  46. s+=pow ((i*(i+1)),i); // you dont need 2 for loops
  47.  
  48.  
  49. }
  50.  
  51. printf("%d", s);
  52. _getch();
  53. return 0;
  54. }
  55.  
  56. #include <stdio.h>
  57.  
  58. int main(void)
  59. {
  60. int n;
  61. int sum = 0;
  62.  
  63. printf("Please enter the number of terms to sum: ");
  64. scanf("%d", &n);
  65.  
  66. sum += 1; // First term
  67.  
  68. /* Start loop with second term */
  69. for (int i = 2; i < n+1; i++) {
  70. int base = (i * (i + 1));
  71. int term = 1;
  72.  
  73. for (int j = 0; j < i; j++) {
  74. term *= base;
  75. }
  76. sum += term;
  77. }
  78. printf("The sum of the first %d terms of the series is: %dn", n, sum);
  79.  
  80. return 0;
  81. }
  82.  
  83. Please enter the number of terms to sum: 2
  84. The sum of the first 2 terms of the series is: 37
  85.  
  86. Please enter the number of terms to sum: 3
  87. The sum of the first 3 terms of the series is: 1765
  88.  
  89. Please enter the number of terms to sum: 4
  90. The sum of the first 4 terms of the series is: 161765
  91.  
  92. 1 + (1*2)^1 + (2*3)^2 + (3*4)^3 + ... + ((n-1)*n)^(n-1)
  93.  
  94. int main(void)
  95. {
  96. int n;
  97. unsigned long long sum = 0;
  98.  
  99. printf("Please enter the number of terms to sum: ");
  100. scanf("%d", &n);
  101.  
  102. /* Start loop with second term */
  103. for (int i = 1; i < n+1; i++) {
  104. unsigned long long base = ((i - 1) * i);
  105. unsigned long long term = 1;
  106.  
  107. for (int j = 0; j < i-1; j++) {
  108. term *= base;
  109. }
  110. sum += term;
  111. }
  112. printf("The sum of the first %d terms of the series is: %llun", n, sum);
  113.  
  114. return 0;
  115. }
  116.  
  117. Please enter the number of terms to sum: 2
  118. The sum of the first 2 terms of the series is: 3
  119.  
  120. Please enter the number of terms to sum: 3
  121. The sum of the first 3 terms of the series is: 39
  122.  
  123. Please enter the number of terms to sum: 4
  124. The sum of the first 4 terms of the series is: 1767
  125.  
  126. Please enter the number of terms to sum: 5
  127. The sum of the first 5 terms of the series is: 161767
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement