Program in C to sum of two elements of given array insert into another array.
Diagram
#include<stdio.h> #include<conio.h> #define size 25 int main() { int i,a[size],b[size/2+1]; int sum=0,j=0,n; printf("Enter number of elements you want to insert:-"); scanf("%d",&n); if(n>size) { printf("Invalid array size."); return 0; } printf("Enter %d numbers:-",n); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if((i+1)%2==0||i+1==n) { sum+=a[i]; b[j]=sum; sum=0; j++; } else sum+=a[i]; } printf("Elements of second array is "); for(i=0;i<j;i++) printf("\t%3d",b[i]); getch(); }
Output:-
0 Comments