Interview Programming Questions and Answers in C — Part 4
Interview Programming Questions and Answers in C
4 min readJun 14, 2020
Q. W.A.P to print a given pattern.
A.
#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.
#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.
#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.
#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.
#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.
#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.
#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.
#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