In a science research lab, combining two
nuclear chemicals produces a maximum
energy that is the product of the energy of the
two chemicals. The energy values of the
chemicals can be negative or positive. The
scientist wishes to calculate the sum of the
maximized energies of the two elements when
the reaction happens.
Write an algorithm to find the total energy
produced by the chemicals when the reaction
happens.
Input
The first line of the input consists of an
integer numOfChem, representing the number
of chemicals (N)
The second line consists of N space-separated
integers - ener, ener2....., enern representing
the energies of the chemicals.
Output
Print an integer representing the total energy produced by the chemicals when the reaction happens
Answers
Answered by
36
Answer:
#include <stdio.h>
int main()
{
int n,a,result=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a);
result=result+a;
}
printf("%d",result);
return 0;
}
Explanation:
Answered by
28
Algorithm to find the total energy
Explanation:
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int i,e[n];
for(i=0;i<n;i++)
scanf("%d",&e[i]);
int j,t;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(e[j]<e[j+1])
{
t=e[j];
e[j]=e[j+1];
e[j+1]=t;
}
}
}
printf("%d",e[0]+e[1]);
}
hence, this is the required algorithm
Similar questions