Write a program that includes two subprograms, one that takes a single parameter
ID: 655340 • Letter: W
Question
Write a program that includes two subprograms, one that takes a single parameter and performs some simple operation on that parameter and one that takes 20 parameters and uses all of the parameters, but only for one simple operation. The main program must call these two subprograms a large number of times. Include in the program timing code to output the run time of the calls to each of the two subprograms. Run the program on a RISC machine and on a CISC machine and compare the ratios of the time required by the two subprograms. Based on the results, what can you say about the speed of parameter passing on the two machines?
THIS ASSIGNMENT REQUIRES ONLY WRITE A PROGRAM (SOURCE CODE AND OUTPUT)
Explanation / Answer
#include<stdio.h>
#include<conio.h>
void sq(int a)
{
printf("Square of number is %d",a*a);
}
void sum(int ar[],n)
{
int i,s=0;
for(i=0;i<n;i++)
{
s=s+ar[i];
}
printf("Sum is %d",s);
getch();
}
void main()
{
int aa[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
int i;
for(i=0;i<50;i++)
{
sq(i);
sum(aa,20);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.