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

Problem 1: write a C program that reads an integer n, generate cube of the integ

ID: 3929380 • Letter: P

Question

Problem 1: write a C program that reads an integer n, generate cube of the integer n read by calling the cube function. Continue the computation while n! = 0.

Output:

·        Enter a value 7

              The Cube of 7 is 343

·        Enter a value 0

                The Cube of 0 is 0

Problem 2: Write a C program to read 5 real numbers (Use an array of size 5 to store elements) and then print them in order and reverse order. Define functions ReadDepositArray, ShowDepositArrayInorder, and ShowDepositArrayReverse to perform this task.    

Output:

Enter 5 deposits values:

15.5 45.2   33.12   88.88 11.12   

Your deposits are:

Deposit [1]: 15.5

Deposit [2]: 45.2

Deposit [3]: 33.12

Deposit [4]: 88.88

Deposit [5]: 11.12

Your deposits <reversed> are:

Deposit [5]: 11.12

Deposit [4]: 88.88

Deposit [3]: 33.12

Deposit [2]: 45.2

Deposit [1]: 15.5

Explanation / Answer

1.

#include <stdio.h>
int cube(int);
int main()
{
    int n,c;
    printf("Enter the number: ");
    scanf("%d",&n);
    c=cube(n);
    printf(" %d",c);
}
int cube(int a)
{
          while(a!=0)
        return a*a*a;
     
}


2.

#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 5
int main()
{
     float a[MAXSIZE];
     int i,n;
     printf("Enter number of values :");
     scanf("%d",&n);
     printf("Enter real numbers :");
     for(i=0;i<n;i++)
     {
          scanf("%f",&a[i]);
     }
     inorder(n,a);
     printf(" ");
      reverseorder(n,a);
   
}
int inorder(int n,float a[5])
{
     int i;
     for(i=0;i<n;i++)
     {
          printf(" %f",a[i]);
     }
  
}
int reverseorder(int n,float a[5])
{
     int i,j,temp;
    j=n;
if(n%2==0)
{
   for(i=0;i<n;i++)
   {
      a[i]=a[j];
      j--;
   }
}
else
{
   for(i=0;i<n;i++)
   {
     if(j==((n/2)+1))
     {
       continue;
     }
     else
     {
       a[i]=a[j];
       j--;
     }
   }
}
     for(i=0;i<n;i++)
     {
          printf(" %f",a[i]);
     }
}