Wap to add 1st and last element of an array

 

#include <stdio.h>

#include <conio.h>

main() 

{

             int i,a[10],b,n,sum,c;


  printf("enter the size of an array");

   scanf("%d",&n);  

  

printf("enter the elements of array :\n");

      for(i=0;i<n;i++)

     {

            scanf("%d",&a[i]);

     }


printf("yr array is ");


     for(i=0;i<n;i++)

    {

           printf("\n%d",a[i]);

    }


b=a[0];

c=a[n-1];


sum=b+c;


printf("\nsum of 1st and last no. is %d",sum);


getch ():


}


Output :


enter the size of an array7

enter the elements of array :

65

34

23

43

98

21

35


yr array is

65

34

23

43

98

21

35

sum of 1st and last no. is 100


[Process completed - press Enter]

    

Comments

Popular Post

Define a class to represent a Bank Account. Include the following members: Data Members: i. Name of the depositor ii. Account number iii. Type of account iv. Balance amount in the account Member Functions: 1. To Input initial values 2. To deposit an amount 3. To withdraw an amount after checking the balance 4. To display name and balance Also write constructor for this class that takes four arguments. It should also handle type of account as savings by default