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
Post a Comment