Question

ECE 270 Computer Methods in ECE OnLine Quiz #5 June 4, 2019/Instructor: Paul Watta 1. Math Analysis. Given the following sequ
0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM :

1)

#include <stdio.h>
#include <stdlib.h>

int main() {
// Initial array x
int x[]= {1,2,3,4,5};
// Array p containing subsequence p= p0, p1, ..., pm-1
int p[]= {6,7,8};
// Resultant array containing all elements of x and subsequence p
int y[100];
// Index where insert occurs ; it can be user input also
int k =2;
//Size of subsequence p
int m = sizeof(p)/sizeof(int);
//Size of x
int n = sizeof(x)/sizeof(int);
//Resultant size of y after insert occurs i.e m+n
int o = m+n;
  
int i;
//Copy all elements of x into y
for(i=0;i<n;i++){
y[i]=x[i];
}
//Value of y = {1,2,3,4,5}
  
//Shift elements of y starting from index = k to index =(n -1) by m spaces to accomodate subsequence p of size m
for(i=k;i<n;i++){
y[i+m]=x[i];
}
//Value of y = {1,2,3,4,5,3,4,5}
  
//Copy subsequence p into y starting from index = k to index = (k+m-1)
for(i=0;i<m;i++){
y[k]=p[i];
k++;
}
//Value of y = {1,2,6,7,8,3,4,5}
  
//Print the resultant array y
//General representation of y = {x0, x1, ... ,xk-1, p0, p1, ... , pm-1, xk, xk+1, ... xk+m-1}
for(i=0;i<o;i++)
printf("%d ",y[i]);
  
return 0;
}

Add a comment
Know the answer?
Add Answer to:
ECE 270 Computer Methods in ECE OnLine Quiz #5 June 4, 2019/Instructor: Paul Watta 1. Math Analysis. Given the foll...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT