Sunday, 8 January 2012

C Technical programs

Technical questions

In some interviews programs are asked like
Write a program to print fallowing format
*
* *
* * *
* * * *

solution:
#include
int main() {
char prnt = '*';
int i, j, nos = 4, s;
for (i = 1; i <= 5; i++) { for (s = nos; s >= 1; s--) { // Spacing factor
printf(" ");
}
for (j = 1; j <= i; j++) {
printf("%2c", prnt);
}
printf("\n");
--nos; // Controls the spacing factor
}
return 0;
}

No comments:

Post a Comment