Part One: Construct an algorithm that returns the sum of the squares of a given list of integers. Write your algorithm using pseudocode similar to the text or in the style of your language of choice.
Part Two: Evaluate your algorithm using the characteristics input output definiteness correctness effectiveness generality finiteness . For each characteristic, briefly state why your algorithms satisfy the characteristic.
part 1 :
#include<stdio.h>
#include<math.h>
main()
{
int a[1000],i,j,k,n,sum=0;
printf("given size of the list of integer n :
");
scanf("%d",&n);
printf("give all integers a[i]");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i]*a[i];
}
printf("sum is =%d",sum);
}
part 2;
above problem is minimized becuase we used only one loop. That is run time = O(n) . Now
we use a input output see the ans
ans of the input 5 , 3 , 6 , 7 , 8 is =183
Get Answers For Free
Most questions answered within 1 hours.