Assume a general nelement sequence for X x0 x1 x2xn1 Write a

Assume a general n-element sequence for X: x_0, x_1, x_2......x_n-1 Write an expression for each element of the Y sequence. Come up with a general rule for y_i that captures the pattern. Write a program to do the computations and print the results to the screen. Repeat the above steps for the following sequence pairs:

Solution

#include <stdio.h>

int main(void)
{
   int x[10] = {10,2,14,7,9,12,31,6,4,7};
   int i,j,y[30];
  
   j=9;
   i=0;
   while(i <= 9 && j >= 0)
   {
   y[i] = x[j];
j--;
   i++;
      
   }
  
   printf(\"\ Expression 1:\ x: \");
   for(i=0;i<10;i++)
   printf(\"%d \\t\",x[i]);
   printf(\"\ y: \");
   for(i=0;i<10;i++)
   printf(\"%d \\t\",y[i]);
  
   for(i=0;i<10;i++)
   y[i] = 0;
   j=0;
   i=0;
   while(i < 5 && j <10)
   {
   y[i] = x[j];
j=j+2;
   i++;
      
   }

   printf(\"\ Expression 2:\ x: \");
   for(i=0;i<10;i++)
   printf(\"%d \\t\",x[i]);
   printf(\"\ y: \");
   for(i=0;i<5;i++)
   printf(\"%d \\t\",y[i]);
  
  
   for(i=0;i<10;i++)
   y[i] = 0;
   j=0;
   i=0;
   while(i < 5 && j <10)
   {
   y[i] = x[j];
j=j+3;
   i++;
      
   }

   printf(\"\ Expression 3:\ x: \");
   for(i=0;i<10;i++)
   printf(\"%d \\t\",x[i]);
   printf(\"\ y: \");
   for(i=0;i<4;i++)
   printf(\"%d \\t\",y[i]);
  
  
   for(i=0;i<=10;i++)
   y[i] = 0;
   j=0;
   i=1;
   while(i <=10 && j <10)
   {
   y[i] = x[j];
j++;
   i++;
      
   }

   printf(\"\ Expression 4:\ x: \");
   for(i=0;i<10;i++)
   printf(\"%d \\t\",x[i]);
   printf(\"\ y: \");
   for(i=0;i<=10;i++)
   printf(\"%d \\t\",y[i]);
  
  
   for(i=0;i<=10;i++)
   y[i] = 0;
   j=0;
   i=2;
   while(i <=11 && j <10)
   {
   y[i] = x[j];
j++;
   i++;
      
   }

   printf(\"\ Expression 5:\ x: \");
   for(i=0;i<10;i++)
   printf(\"%d \\t\",x[i]);
   printf(\"\ y: \");
   for(i=0;i<=11;i++)
   printf(\"%d \\t\",y[i]);
  
  
      

x[0] = 5;
x[1] = 3;
x[2] = 7;
j=0;
i=0;
while(i <30 && j<3)
{
    y[i] = x[j];
    i++;
    j++;
    if(j > 2)
    j = 0;
}

printf(\"\ Expression 6:\ x: \");
for(i=0;i<3;i++)
printf(\"%d \\t\",x[i]);
printf(\"\ y: \");
for(i=0;i<30;i++)
printf(\"%d \\t\",y[i]);

x[0] = 10;
x[1] = 2;
x[2] = 14;
x[3] = 7;
x[4] = 9;
x[5] = 12;
x[6] = 31;

i=0;
j=0;


while(i< 7)
{
    y[i*2] = x[i];
    y[i*2+1] =x[i];
    i++;
    j++;
   
   
}

printf(\"\ Expression 7:\ x: \");
for(i=0;i<7;i++)
printf(\"%d \\t\",x[i]);
printf(\"\ y: \");
for(i=0;i<14;i++)
printf(\"%d \\t\",y[i]);
    

   x[0] = 10;
x[1] = 2;
x[2] = 14;
x[3] = 7;
x[4] = 5;

i=1;
j=0;
y[0] = x[0];
while( i< 6 && j <6)
{
    y[i] = x[i] +y[i-1];
    i++;
    j++;
}

printf(\"\ Expression 8:\ x: \");
for(i=0;i<6;i++)
printf(\"%d \\t\",x[i]);
printf(\"\ y: \");
for(i=0;i<6;i++)
printf(\"%d \\t\",y[i]);
  
   return 0;
}

output:

Success time: 0 memory: 2168 signal:0

 Assume a general n-element sequence for X: x_0, x_1, x_2......x_n-1 Write an expression for each element of the Y sequence. Come up with a general rule for y_i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site