Develop a C program to take total of an elements available in array (with float data type) using pointer
Code
#include<stdio.h>int main(){int i;float array[5];float sum=0;float *ptr;printf("\nEnter array elements (5 float values):");for(i=0;i<5;i++)scanf("%f",&array[i]);/* array is equal to base address* array = &array[0] */ptr = array;for(i=0;i<5;i++){//*ptr refers to the value at addresssum = sum + *ptr;ptr++;}printf("\nThe sum is: %f\n",sum);}
Output
0 Comments
Post a Comment