Computer Programming C Laboratory: Pointers C Programs

Write a C program to add the sum of the numbers using pointer (Using Pointer and Array)

Using Pointers and Arrays - C Programming

Write a C program to add the sum of the numbers using pointer.

/* C Program to add the sum of number using pointer */

#include <stdio.h>

main()

{

 /* Local definitions */

int b, total;

int a[5]; /* a[5] is an array elements */

int *c; /**c is a pointer variable */

/* Statements */

for (b=0;b<5;b++)

{

           printf ("Enter the number %d", b+1);

          scanf ("%d", &a[b]);

} /* for */

c=a,

for (b=0;b<5;b++)

{

        printf ("%d", *c);

        total = total + *c;

        с = c + 1;

} /* for */

printf ("\n Total = %d", total);

} /* main */

OUTPUT

Enter the number 10 20 30 40 50

Total = 150

EXPLANATION: In the above program, the variable a is declared as an integer type array. c is declared as a pointer variable. The for loop reads the 5 integer elements from the keyboard. The array a is assigned to pointer variable c. The second for loop gets each element of array through pointer variable c and adds to the variable total. Finally the variable total is printed as output.

Computer Programming C Laboratory: Pointers C Programs : Tag: C Programming : - Write a C program to add the sum of the numbers using pointer (Using Pointer and Array)


Computer Programming C Laboratory: Pointers C Programs



Under Subject


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation



Related Subjects


English Essentials I

EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


தமிழர் மரபு - Heritage of Tamils

UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Calculus

MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I

PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Chemistry I

CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Makerspace

ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming Python

CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Fundamentals of Electrical and Electronics Engineering

EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Mechanical Engineering

ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Civil Engineering

CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing

CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I Laboratory

PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Applied Chemistry I Laboratory

CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming Python Laboratory

CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electronics and Electrical Engineering

EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing - Laboratory

CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation