About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Monday, September 2, 2013

C Program : Reading Array Elements

  1. #include  
  2. #include  
  3. void main()  
  4. {  
  5.  int i,a[50],sum,n;  
  6.  printf("\n Enter no of elements :");  
  7.  scanf("%d",&n);  
  8.   
  9.  /* Reading values into Array */  
  10.    
  11.  printf("\n Enter the values :");  
  12.  for(i=0;i < n;i++)  
  13.  scanf("%d",&a[i]);  
  14.   
  15.  /* computation of total */  
  16.    
  17.  sum=0;  
  18.  for(i=0;i < n;i++)  
  19.  sum=sum+a[i];  
  20.   
  21.  /* printing of all elements of array */  
  22.   
  23.  for(i=0;i < n;i++)  
  24.  printf("\n a[%d]=%d",i,a[i]);  
  25.   
  26.  /* printing of total */  
  27.   
  28.  printf("\n sum=%d",sum);  
  29.   
  30. getch();  
  31. }  
  32.   

No comments: