A program to explain POINTER with single dimensional array
C Programming Language 100
- Write a program to explain POINTER with single dimensional array
Program
#include <stdio.h>
void main()
{
int a[30], n, i, *p, sum = 0;
printf("Enter how many numbers you want to input: ");
scanf("%d", &n);
p = a;
printf("\nEnter numbers:\n");
for (i = 0; i < n; i++)
{
scanf("%d", p + i);
}
for (i = 0; i < n; i++)
{
sum = sum + (*(p + i));
}
printf("Sum of numbers = %d", sum);
printf("\n");
}
Result
Enter how many numbers you want to input: 4
Enter numbers:
1 2 3 4
Sum of numbers = 10
Last Updated on
Comments