Hello all, pls guide me how to write a C-program to generate the following output: * ** *** **** *****
So what have you tried? Post the code that is causing you the problems. Also post any error messages you receive from compiling your code. Jim
@ Virxen Yes u have got dat diagram right. @Jim & @ Virxen I am not being able to write a program in C dat will give me the output (as Virxen's diagram).
hints ========= -your output must have 5 lines (maybe a for from 1 to 5?) -the first time you print 4 spaces and one star=5 characters (maybe a second or third for?) ..... the fifth time no spaces and 5 stars=5 characters start writing code and post your attempts here to help you.
Here's one that will do the trick: Code: void test29() { char *ch=" ****************"; for (int i=1; i<ch[0]; i++) { for (int j=ch[0]/2; j; j>>=1) { putchar(ch[i&j]); } i<<=putchar('\n')/'\n'; } } Hope you get a good mark!
#include<stdio.h> #include<conio.h> void main() { int i,j,k; clrscr(); for(i=1;i<=5;i++) { for(j=5-i;j>=1;j--) printf(" "); for(k=1;k<=i;k++) printf("*"); printf("\n"); } getch(); }
wat about the following diagram: ? pls give some hints to get the following output: * * * * * * * * * * *
another way is this Code: #include <stdio.h> int main(){ for (int i=1;i<=5;i++){ for (int j=1;j<=5;j++){ if (j<=(5-i)) printf(" "); else printf("*"); } printf("\n"); } getchar(); return 0; }