230k views
0 votes
Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print:Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print:

1 Answer

0 votes

C program for printing elements in a format

#include <stdio.h>

int main() //driver function

{

int courseGrades[100];

int n,i;

printf("How much grades points were there");

scanf("%d",&n);

printf("Enter grade elements\\"); //Taking input from user

for(i=0;i<n;i++)

{

scanf("%d",&courseGrades[i]);

}

printf("Elements are \\"); //printing the elements that user entered

for(i=0;i<n;i++)

{

printf("%d",courseGrades[i]);

}

printf("\\Printing elements in the format\\");

for(i=0;i<n;i++) /*loop for the first line,\t is used for horizontal spacing*/

{

printf(" %d\t",courseGrades[i]);

}

printf("\\"); /*\\ is used to get the new line*/

for(i=n-1;i>=0;i--) /*loop for printing the input in reverse order*/

{

printf("%d \t",courseGrades[i]);

}

return 0;

}

Output

How much grades points were there 4 Enter grade elements {7,9,11,10}

Elements are

791110

Printing elements in the format

7 9 11 10

10 11 9 7

User Darden
by
5.3k points