Interview Programming Questions and Answers in C — Part 4

Interview Programming Questions and Answers in C

Q. W.A.P to print a given pattern.
A.

Pattern
#include <stdio.h>int main()
{
int row, rowCount, i, tempRowCount;

printf("Enter the Number of Rows in Pyramid of Stars You Wish to See \n");
scanf("%d", &rowCount);

tempRowCount = rowCount;

for (row = 1; row <= rowCount; row++)
{
for (i = 1; i < tempRowCount; i++ )
{
printf(" ");
}

tempRowCount--;

for (i = 1; i <= 2*row-1; i++)
{
printf("*");
}

printf("\n");
}

return 0;
}

Q. W.A.P to print a given pattern.
A.

Pattern
#include <stdio.h>int main()
{
int row, rowCount, i, j;

printf("Enter the Number of Rows in Pyramid of Stars You Wish to See \n");
scanf("%d", &rowCount);

for (row = rowCount; row >= 1; row--)
{
for (i = rowCount; i > row; i--)
{
printf(" ");
}

for (j = 1; j < 2*row; j++)
{
printf("*");
}

printf("\n");
}

return 0;
}

Q. W.A.P to print a given pattern.
A.

Pattern
#include <stdio.h>int main()
{
int rowCount, i, j;

printf("Enter the Number of Rows \n");
scanf("%d", &rowCount);

for (i = 1; i <= rowCount; i++)
{
for (j = 1; j <= i; j++)
{
printf("*");
}
printf("\n");
}

return 0;
}

Q. W.A.P to print a given pattern.
A.

Pattern
#include <stdio.h>int main()
{
int rowCount, i, j;

printf("Enter the Number of Rows \n");
scanf("%d", &rowCount);

for (i = rowCount; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
printf("*");
}
printf("\n");
}

return 0;
}

Q. W.A.P to print a given pattern.
A.

Pattern
#include <stdio.h>int main()
{
int row, rowCount, i, space = 1;

printf("Enter the Number of Rows \n");
scanf("%d", &rowCount);

space = rowCount - 1;

for(row = 1; row <= rowCount; row++)
{
for (i = 1; i <= space; i++)
{
printf(" ");
}

space--;

for(i = 1; i <= 2*row-1; i++)
{
printf("*");
}

printf("\n");
}

space = 1;
for (row = 1; row <= rowCount - 1; row++)
{
for (i = 1; i <= space; i++)
{
printf(" ");
}

space++;

for (i = 1 ; i <= 2*(rowCount-row)-1; i++)
{
printf("*");
}

printf("\n");
}

return 0;
}

Q. W.A.P to print a given pattern.
A.

Pattern
#include <stdio.h>int main()
{
int rowCount, row, i, j;

printf("Enter the Number of Rows \n");
scanf("%d", &rowCount);

for(row = rowCount; row >= 1; row--)
{
for(i = 1; i < row; i++)
{
printf(" ");
}

for(j = rowCount; j >= row; j--)
{
printf("*");
}

printf("\n");
}

return 0;
}

Q. W.A.P to print a given pattern.
A.

Pattern
#include <stdio.h>int main()
{
int rowCount, row, i, j;

printf("Enter the Number of Rows \n");
scanf("%d", &rowCount);

for(row = rowCount; row >= 1; row--)
{
for(i = rowCount; i > row; i--)
{
printf(" ");
}

for(j = 1; j <= row; j++)
{
printf("*");
}

printf("\n");
}

return 0;
}

Q. W.A.P to print a given pattern.
A.

Pattern
#include <stdio.h>int main()
{
int rowCount, row, i;

printf("Enter the Number of Rows \n");
scanf("%d", &rowCount);

for(row = 1; row <= rowCount; row++)
{
for(i = rowCount; i > row; i--)
{
printf(" ");
}

printf("*");

for(i = 1; i < (row-1)*2; i++)
{
printf(" ");
}

if(row == 1)
{
printf("\n");
}
else
{
printf("*\n");
}
}

for(row = rowCount-1; row >= 1; row--)
{
for(i = rowCount; i > row; i--)
{
printf(" ");
}

printf("*");

for(i = 1; i < (row-1)*2; i++)
{
printf(" ");
}

if(row == 1)
{
printf("\n");
}
else
{
printf("*\n");
}
}
return 0;
}

.

Note: To compile these programs please use Online Compiler.

“The best way to learn a new programming language is by writing programs in it.” — Dennis Ritchie

Thank you for reading! If you liked this article, please clap to get this article seen by more people.
Please follow me on Medium by clicking Follow.
I’m also active on LinkedIn, Twitter, and GitHub.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store