Bulid your logic and algorithm | C Program

Build a program in c Language :



Logic:

1.Take an array
2.Insert elements of 4 elements.
3.Select one element and sum the rest
4.Check weather it is larger than sum or not.

Output:

 

Code:


#include<stdio.h>
#define max 4
int a[max];
void input();
void greater();
int sum,i,j;
void main()
{
 input();
 greater();
}
void input()
{
 printf("Enter the four element: \n");
 for(i=0;i<max;i++)
  scanf("%d",&a[i]);
}
void greater()
{
 for(i=0;i<max;i++)
 {
  sum=0;
  for(j=0;j<max;j++)
  {
   if(a[j]!=a[i])
   {
    sum=sum+a[j];
   }
  }
  if(sum<a[i])
  {
   printf("\n %d is greater than sum of rest= %d\n",a[i],sum);
  }
 }
}

Comments

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :