C-- should have braces for blocks of code, an if statement, while statement, and
ID: 3555534 • Letter: C
Question
C-- should have braces for blocks of code, an if statement, while statement, and a double, int, and character. Each statement ends with a semi-colon and you must have a main routine (forget about defining methods). Needs to declare variables and have some sort of print and input statement.
Make the languages simple. You can use the extended BNF to describe the language. Then have a sample program as follows:
For C--, read in the number of values, then read in that many numbers, while summing and printing them, and print the sum
Explanation / Answer
void main()
{
int i,n,sum=0;
int *a;
clrscr();
printf("Enter the size of array A ");
scanf("%d", &n);
a=(int *) malloc(n*sizeof(int)); /*Dynamix Memory Allocation */
printf("Enter Elements of First List ");
for(i=0;i<n;i++)
{
scanf("%d",a+i);
}
/*Compute the sum of all elements in the given array*/
for(i=0;i<n;i++)
{
sum = sum + *(a+i);
}
printf("Sum of all elements in array = %d ", sum);
} /* End of main() */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.