adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C to sum of each two elements of given array insert into another array.

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:-











Post a Comment

0 Comments