home
Learn
screen_rotation
#include <stdio.h> #include <stdlib.h> #include <conio.h> void main(){ int n,i,*ptr,sum=0; clrscr(); printf("\nEnter number of elements: "); scanf("%d",&n); ptr=(int*)malloc(n*sizeof(int)); if(ptr==NULL) { printf("\nSorry! Number of element has not given by you."); exit(0); } for(i=0;i< n;i++) { printf("\nEnter elements of array: "); scanf("%d",ptr+i); } for(i=0;i< n;i++) { printf("\n given element: %d",*(ptr+i)); sum = sum + *(ptr+i); } printf("\n Sum=%d",sum); free(ptr); getch(); }
Program Output
Enter number of elements: 5 Enter elements of array: 10 Enter elements of array: 20 Enter elements of array: 30 Enter elements of array: 40 Enter elements of array: 50 given element: 10 given element: 20 given element: 30 given element: 40 given element: 50 Sum=150