Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to write the following code. Confused Below is an example of a completed pro

ID: 3856403 • Letter: H

Question

How to write the following code. Confused Below is an example of a completed program where the user inputted 1 and 2, and your program's I/O should match shown below. Choose 1-4 to initialize an array all numbers from 1-20 the first 20 even numbers beginning with 2 the 20 odd numbers, beginning with 1 the first 20 fibonacci numbers, beginning with 0 and 1 Choose 1-4 to initialize an array all numbers from 1-20 the first 20 even numbers beginning with 2 the 20 odd numbers, beginning with 1 the first 20 fibonacci numbers, beginning with 0 and 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 The inner product of the arrays are 5740 Before turning in your assignment, make sure you have followed all of the instructions state and any additional instructions given by your lab instructor(s). Always test, test, and retest compiles and runs successfully on our Unix machines before submitting it. Show your TA that you completed the assignment. Then submit and upload your code to the CPSC 1011 Labs website on Canvas under the correct lab assignment. After you submit file(s) Canvas for this program and other programs that you write this semester, always double check that you submit the correct file(s) (to do this, download your submission from Canvas, view it, and make sure compiles and runs correctly on our Unix machines). Style, Formatting, and Commenting Requirements Commenting your source code The top of your file should have a header comment, which should contain: Your name (first and last) Lab Section Date Assignment name A brief description about what the program does Any other helpful information that you think would be good to have. All functions should be commented about what they do, and significant blocks of source code should be commented to describe its functionality in plain English (Which means someone who has no

Explanation / Answer

#include<stdio.h>

int main()
{
printf("choose 1-4 to initialize an array 1.all numbers from 1-20 2.the first 20 even numbers beginning with 2 3.the 20 odd numbers,beginning with 1 4.the first 20 fibonacci numbers beginning with 0 and 1 ");
int c1;
scanf("%d",&c1);
printf("choose 1-4 to initialize an array 1.all numbers from 1-20 2.the first 20 even numbers beginning with 2 3.the 20 odd numbers,beginning with 1 4.the first 20 fibonacci numbers beginning with 0 and 1 ");
int c2;
scanf("%d",&c2);
int arr1[20];
int arr2[20];
if(c1==1)
{
int i=0;
for(i=1;i<21;i++)
{
printf("%d ",i);
arr1[i-1]=i;
}
}
else if(c1==2)
{
int i=2;
int k=0;
for(i=2;i<41;i=i+2)
{
printf("%d ",i);
arr1[k]=i;
k++;
}
}
else if(c1==3)
{
int i=1;
int k=0;
for(i=1;i<40;i=i+2)
{
printf("%d ",i);
arr1[k]=i;
k++;
}
}
else
{
int f1=0;
int f2=1;
int i=0;
int nxt;
printf("%d ",f1);
printf("%d ",f2);
arr1[0]=f1;
arr1[1]=f2;
int k=2;
for(i=0;i<18;i++)
{
nxt=f1+f2;
printf("%d ",nxt);
arr1[k]=nxt;
f1=f2;
f2=nxt;
k++;
}
}
printf(" ");

if(c2==1)
{
int i=0;
for(i=1;i<21;i++)
{
printf("%d ",i);
arr2[i-1]=i;
}
}
else if(c2==2)
{
int i=2;
int k=0;
for(i=2;i<41;i=i+2)
{
printf("%d ",i);
arr2[k]=i;
k++;
}
}
else if(c2==3)
{
int i=1;
int k=0;
for(i=1;i<40;i=i+2)
{
printf("%d ",i);
arr2[k]=i;
k++;
}
}
else
{
int f1=0;
int f2=1;
int i=0;
int nxt;
printf("%d ",f1);
printf("%d ",f2);
arr2[0]=f1;
arr2[1]=f2;
int k=2;
for(i=0;i<18;i++)
{
nxt=f1+f2;
printf("%d ",nxt);
arr2[k]=nxt;
f1=f2;
f2=nxt;
k++;
}
}
printf(" ");
int q=0;
int prod=1;
int innr=0;
for(q=0;q<20;q++)
{
prod=arr1[q]*arr2[q];
innr=innr+prod;
}
printf("the inner product of the arrays are %d",innr);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote