1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nlexa [21]
3 years ago
7

Write a program in C to: a) Calculate Sn=1+1.2+1.2.3+…+1.2.3…n , n>0

Computers and Technology
1 answer:
mezya [45]3 years ago
4 0

Answer:

// Program in C to calculate sum of 1+1.2+.....+1.2.3...n

// include header

#include <stdio.h>

// main function

int main()

{

   // variable Declaration and initialization

   int n,a,prod=1,sum=0;

   // ask to enter the value of n

   printf("enter the value of n:");

   // read the value of n

   scanf("%d",&n);

   for(a=1;a<=n;a++)

   {

       // calculate product

       prod=prod*a;

       // calculate sum of the series

       sum=sum+prod;

   }

   // print the sum

   printf("sum of the series is:%d",sum);

   return 0;

}

Explanation:

Read the value of n from user.initialize variables "prod=1" and

"sum=0".Iterate over a for loop to calculate product term as "prod=prod*a".Here prod will have product of all till "a-1" for each "a".Then "a" is multiplied with "prod" and then add to sum.After the loop ends, "sum" will have the total of all the terms.

Output:

enter the value of n:5

sum of the series is:153

You might be interested in
3. Write a program that inputs 4 hexadecimal digits as strings (example 7F), converts the string digits to a long – use strtol(i
never [62]

Answer:

#include <stdio.h>

#include <stdlib.h>

int main()

{

char num1[20],num2[20],num3[20],num4[20];

//Checks where the conversion of string to long stops and is required by strtol

char *ptr;

//Stores the converted number string into long.

long result_num1,result_num2,result_num3,result_num4;

//Prompt to enter all the four hexadecimal numbers.

printf("Enter the first hexadecimal number: ");

scanf("%s",num1);

printf("Enter the second hexadecimal number: ");

scanf("%s",num2);

printf("Enter the third hexadecimal number: ");

scanf("%s",num3);

printf("Enter the fourth hexadecimal number: ");

scanf("%s",num4);

//Converting the hexadecimal numbers into long using strtol() function with base 16 for hexadecimal.

result_num1 = strtol(num1,&ptr,16);

result_num2 = strtol(num2,&ptr,16);

result_num3 = strtol(num3,&ptr,16);

result_num4 = strtol(num4,&ptr,16);

//Casting the long to unsigned chars.

unsigned char numb1 = (unsigned char)result_num1;

unsigned char numb2 = (unsigned char)result_num2;

unsigned char numb3 = (unsigned char)result_num3;

unsigned char numb4 = (unsigned char)result_num4;

//Applying the boolean operation on unsigned chars and storing the resultant value in result.

unsigned char result = ((numb1&numb2)|numb3)^numb4;

//Printing the result in capital hex ("%X" take care of this).

printf("%X",result);

return 0;

}

Code OUTPUT

Enter the first hexadecimal number: 1 Enter the second hexadecimal number:2

Enter the third hexadecimal number: 3 Enter the fourth hexadecimal number: 4 Resultant Value: 7 Process returned o (0×0) execution time : 3.076 s

Press any key to continue

4 0
3 years ago
Xcvasdfgfdsasdfghjhgf
Cerrena [4.2K]

Well, The answer would be zxnisdnkfnxkzl since ndlsfd;gjfsdd is a forsfgfd operation. Also, the ffsldflslc is like the dfgfd. Keep that in mind when you are studying the ffsldflslc. It could be tough on the test.

3 0
3 years ago
Difference between multidimensional arrays and an example​
weqwewe [10]

Answer:

The generic data structure of a n-dimensional array is a tensor.

An example with 3 dimension can be a cube that contains the following dimensions: users, items, time. That cube can represent the interactions of  users with verifiied pages of public interests (influencers or company/media pages) in time slots (e.g. weekly timeslots).

Explanation:

You can represent in a sparse 3-dimensional array (tensor) the combinations of which user interacted with wich item in a given timeslow.

5 0
3 years ago
What are the uses of DVD Ram​
Verdich [7]

Answer:

Like ordinary random access memory (RAM), it can be repeatedly read, written to, and erased. Intended mostly for removable computer storage, DVD-RAM provides the capabilities of Rewriteable CD (CD-RW) - users can run programs from the discs, copy files to them and rewrite or delete them.

4 0
3 years ago
Read 2 more answers
The acronym GUI is short for
Y_Kistochka [10]
Graphical user interface.

Hope I helped :)
4 0
3 years ago
Other questions:
  • Using a text editor, create a file that contains a list of at least 15 six-digit account numbers. Read in each account number an
    12·1 answer
  • Consider an application that transmits data at a steady rate (for example, the sender generates an N-bit unit of data every k ti
    8·1 answer
  • At which layer of the osi model is the entire message referred to as the payload
    15·1 answer
  • You recently created several new user accounts in the Sales OU and configured them with the appropriate group membership, logon
    12·1 answer
  • Read this excerpt from The Outsiders. Or I could have gotten one of the gang to come along, one of the four boys Darry and Soda
    10·2 answers
  • WILL UPVOTE ALL plz
    11·1 answer
  • What is HTML ? <br>Give a small description about html
    12·2 answers
  • If you are trying to improve your budget and spending, which option would save you the most money?
    13·2 answers
  • What does FLUX do when soldering an electrical joint?
    13·2 answers
  • Write the following abbreviations in full next to the question number
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!