Saturday, April 14, 2012

C language program to add numbers using pointers

 #include<stdio.h>  
 #include<conio.h>  
  void main()  
  {  
  int a[10],sum=0;  
  int *j;  
  int i,n;  
  clrscr();  
  printf("How many elements you want to add:");  
  scanf("%d",&n);  
  printf("Enter element:");  
  for(i=0;i<n;i++)  
  {  
  scanf("%d",&a[i]);  
  }  
  j=&a[0];  
  for(i=0;i<n;i++)  
    {  
     sum=sum+*j;  
     j++;  
    }  
  printf("sum=%d",sum);  
 }  

No comments:

Post a Comment