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

In this assignment, you are asked to code a program when you are given thepseudo

ID: 669230 • Letter: I

Question

In this assignment, you are asked to code a program when you are given thepseudo-code for it.Pseudo-code is very important (not least because you will be asked to writesome pseudo-code during exams, you are warned). It’s a detailed description ofthe mechanism of a program that specifies the main variables and structures(such as arrays) that are used, describes the program flow (tests, loops) but isn’tspecific of a programming language and doesn’t necessarily dwell on smalldetails. It’s a rough sketch, not specific of a particular programming language,but which should enable a programmer who knows a programming language toturn it into a real program.You are asked to turn the following into a C program that you will run (itdisplays a shape):

variables: user input (integer), n (integer), two loop indices called iand j here.

ask the user for a positive integer value.check that input is indeed a strictly positive integer.

compute n = 2 * read value + 1 to make sure that you have an oddnumber.

loop on i going from 0 included to n excluded

loop on j going from 0 included to n – 1 – i excluded            

print a space       

loop on j going from 0 included to 2 * i + 1 excluded

             print a star       

print a carriage returnloop on i going from n – 2 included down to 0 included   

    loop on j going from 0 included to n - 1 – i excluded

         print a space  

  loop on j going from 0 included to 2 * i + 1 excluded        

   print a star   

print a carriage return

Explanation / Answer

#include <stdio.h>
int j(int n);
int main(){
int n,i,j;
printf("Enter a number: ");
scanf("%d",&n);
i=j(n);
printf("j=%d",i);
}
int j(int n){
if(n==0)
return n;
else
return n+j(n-1);
}