0% found this document useful (0 votes)
14 views4 pages

assignment 1 pro vipul

The document outlines an assignment for a C-Programming course, where the student G. Vipul is required to write a program that calculates the sum of elements in an array using pointers. It includes a detailed explanation of the program's functionality, an algorithm, and pseudocode for the implementation. Additionally, it specifies the submission date and the instructor's name.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

assignment 1 pro vipul

The document outlines an assignment for a C-Programming course, where the student G. Vipul is required to write a program that calculates the sum of elements in an array using pointers. It includes a detailed explanation of the program's functionality, an algorithm, and pseudocode for the implementation. Additionally, it specifies the submission date and the instructor's name.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Name of the Student: G.

Vipul Academic Year: 2024-28


Student Registration Number: 241U1R1022 Year & Term: I & II
Study Level: UG Class & Section: CSE-1A
Name of the Course: C-Programming Name of the Instructor: Mr. K. Ravikanth
Name of the Assessment: Assignment - 1 Date of Submission: 26- 01- 2025

Assignments - 01
1. Write a C program to find the Sum of Elements in an Array
Using Pointers

Explanation of the above the code.

Input the Number of Elements: The first thing that the program
does is ask the user to enter the number of elements he intends to
place in the array.
Declare the Array: The program declares an array of integers, based
on the user's input.
Input Elements: The program now asks the user to input elements of
the array.
Pointer Initialization: A pointer (ptr) is initialized to point to the first
element of the array.
Sum Calculation: The program uses a loop to iterate through the
array with pointer arithmetic. The sum of the elements is computed by
dereferencing the pointer and adding the values to the sum variable.
Output the Result: Finally, the program prints the sum of the
elements in the array.

Algorithm: Sum of Elements in an Array Using Pointers


 Start.
 Declare Variables:
o n: to store the number of elements in the array.
o i: for loop iteration.
o sum: to store the sum of the elements (initialize to
0).
o arr[n]: an array to hold the elements (size n).
o ptr: a pointer to an integer (to point to the first
element of the array).
 Input the Number of Elements:
o Print "Enter the number of elements in the array: ".
o Read the value of n.
 Input Elements into the Array:
o Print "Enter n elements: ".
o For i from 0 to n-1:
o Print "Element i+1: ".
o Read the value of arr[i].
 Initialize Pointer:
o Set ptr to point to the first element of the array (ptr
= arr).
 Calculate the Sum:
o For i from 0 to n-1:
o Add the value pointed to by ptr +
i to sum (i.e., sum += *(ptr + i)).
 Output the Result:
o Print "The sum of the elements in the array is: sum".
 End.

Pseudocode:-
 START
 DECLARE n, i, sum
 INITIALIZE sum = 0
 DECLARE arr[n]
 DECLARE ptr
 PRINT "Enter the number of elements in the array: "
 READ n
 PRINT "Enter n elements: "
 FOR i FROM 0 TO n-1 DO
o PRINT "Element ", i + 1, ": "
o READ arr[i]
 END FOR
 SET ptr = arr
 FOR i FROM 0 TO n-1 DO
o sum = sum + *(ptr + i)
 END FOR
 PRINT "The sum of the elements in the array is: ", sum
 END
Flow Chart:-

You might also like