POP Using C - VTU Lab Program-4
POP Using C - VTU Lab Program-4
4. Write a C Program to display the following by reading the number of rows as input.
Algorithm:
Step 1: START
Step 2 : Read the number of rows to be entered , say , ‘n’
Step 3: [For inputting the number of rows]
for i=1 to n
Step 4:[For printing spaces]
for j=1 to n-i
[Print the spaces]
printf(“ “)
print j
Step 6: [Display numbers in the reverse order after middle]
Step 7: STOP
Flowchart:
Program:
#include<stdio.h>
void main()
{
int i,j,n;
printf(“enter the number of rows\n”);
scanf("%d",&n);
/*for inputting the number of rows*/
for(i=1;i<=n; i++)
{
/*Printing blank spaces*/
for(j=1;j<=n-i; j++)
printf(" ");
/*Display number in ascending order upto middle*/
for(j=1;j<=i;j++)
printf("%d",j);
/*Display number in reverse order after middle*/
for(j=i-1;j>=1;j--)
printf("%d",j);
printf("\n");
}
}
Command to execute the Program:
$ gcc lab4.c -lm
$ ./a.out
Output:
enter the number of rows 4
1
121
12321
1234321