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

Write a Scheme program that does: 1) Prompt the user to enter a list of ints 2)

ID: 3874510 • Letter: W

Question

Write a Scheme program that does:

1)      Prompt the user to enter a list of ints

2)      Display the entered list

3)      Display the size of the list

4)      Reverse the list and print it

5)      Compute the summation of the list and display it

6)      Compute the average of the list and display it

7)      Search the list a value, if exists, display “value in the list” otherwise display “value NOT in the list”.

8)      For each element in the list test and display if it is even or odd

9)      Each task (2-8) must be implemented as a separate function.

10)    write main program that accomplishes 1-8 above.

(make it simple and clear. nothing complicated)

Explanation / Answer

Please copy the code into file and compile using

gcc filename.c -o a.out

Run:

./a.out

C Code :

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

void display(int * list, int size)
{
int i;
for ( i =0; i < size; i++)
{
printf("%d ", list[i]);
}
}

void display_reverse(int * list, int size)
{
int i;
printf("Reverse list : ");
for (i = size; i > 0; i--)
{
printf("%d ", list[i-1]);
}
}

void sum_of_list(int * list, int size)
{
int i;
int sum = 0;
for ( i =0; i < size; i++)
{
sum += list[i];
}
printf("Sum is %d", sum);
}

void average_of_list(int * list, int size)
{
int i;
int sum;
for ( i =0; i < size; i++)
{
sum += list[i];
}
printf("Average is %d", sum/size);
}

void search(int * list, int size)
{
int i;
int num;
printf("Enter the number : ");
scanf("%d", &num);
for( i = 0; i < size; i++)
{
if(num == list[i])
{
printf("value in the list");
return;
}
}
printf("value NOT in the list");
}

void display_even_odd(int *list, int size)
{
int i;
for(i = 0; i < size; i++)
{
if (list[i] % 2 == 0)
{
printf("%d even ", list[i]);
}
else
{
printf("%d odd ", list[i]);
}
}

}

int main()
{
int *list;
int size;
int i;
int input;

/*Getting the list from the user*/
printf("Enter the size of the list ");
scanf("%d",&size);
list = (int *) malloc(size * sizeof(int));
for(i = 0; i < size; i++)
{
printf("Enter the Number:");
scanf("%d", &list[i]);
}
printf(" ");

while(1)
{
printf(" ");
printf("1. Display the entered list ");
printf("2. Display the size of the list ");
printf("3. Display the reverse list ");
printf("4. Display summation of the list ");
printf("5. Display average of the list ");
printf("6. Search in the list ");
printf("7. For each element in the list test and display if it is even or odd ");
printf("8. To Exit ");
printf("Please Chose your option : ");
scanf("%d", &input);
printf(" ");
switch(input)
{
case 1 :
display(list, size);
break;
case 2 :
printf("size is %d", size);
break;
case 3:
display_reverse(list, size);
break;
case 4:
sum_of_list(list, size);
break;
case 5:
average_of_list(list, size);
break;
case 6:
search(list, size);
break;
case 7:
display_even_odd(list, size);
break;
case 8:
printf("Bye Bye!!!");
return;
break;
default:
printf("Please enter the the valid option");
break;

}


}

}

Demo:

./a.out
Enter the size of the list
5
Enter the Number:1
Enter the Number:2
Enter the Number:3
Enter the Number:4
Enter the Number:5

1. Display the entered list
2. Display the size of the list
3. Display the reverse list
4. Display summation of the list
5. Display average of the list
6. Search in the list
7. For each element in the list test and display if it is even or odd
8. To Exit
Please Chose your option : 1

1 2 3 4 5

1. Display the entered list
2. Display the size of the list
3. Display the reverse list
4. Display summation of the list
5. Display average of the list
6. Search in the list
7. For each element in the list test and display if it is even or odd
8. To Exit
Please Chose your option : 2

size is 5

1. Display the entered list
2. Display the size of the list
3. Display the reverse list
4. Display summation of the list
5. Display average of the list
6. Search in the list
7. For each element in the list test and display if it is even or odd
8. To Exit
Please Chose your option : 4

Sum is 15

1. Display the entered list
2. Display the size of the list
3. Display the reverse list
4. Display summation of the list
5. Display average of the list
6. Search in the list
7. For each element in the list test and display if it is even or odd
8. To Exit
Please Chose your option : 8

Bye Bye!!!

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