Question:

How to print the foll. in C?

by  |  earlier

0 LIKES UnLike

*

* *

* * *

* * * *.....as many times we want?

 Tags:

   Report

4 ANSWERS


  1. include<stdio.h>

    #include<conio.h>

    void main()

    {

    int i,j,n;

    clrscr();

    printf("how many lines do u want");

    scanf("%d",&n)

    for(i=0;i<n;i++)

    {

      for(j=0;j<=i;j++)

      {

       printf("*");

      }

    printf("\n");

    }

    getch();

    }


  2. Even though these questions are fun to do, I hate actually giving out the answer because I always feel like I'm doing someone else's homework for them. This code is mine, and I only grant you permission to use it under the condition that you sincerely attempt to understand it, because otherwise I don't want to have you as my coworker 10 years from now.

    #include <stdio.h>

    #define STOP_VAL 25

    /*

    * This is a recursive function. Think about why I implemented it this way.

    * Each level of your "asterisk tree" can be defined by the previous level.

    * e.g. the number of stars in level 5 is the number of stars in level 4 + 1,

    * and so on until you arbitrarily decide to stop. If I didn't have the

    * line marked below in there, this would be an infinite loop.

    */

    void printfunc(int num_times) {

            int i;

            if (num_times == STOP_VAL) return; /* this one */

            for(i=0; i< num_times; i++) {

                    printf("*");

            }

            printf("\n");

            printfunc(num_times + 1);

    }

    /* ..and of course all good C programs have a function of this signature */

    int main(int argc, char *argv[]) {

            printfunc(1);

    }


  3. coding for project-

    http://codingforum.info/    

  4. main()

    {

    int i=0;

    int n=0,t=0,k=0,s=0,j=0;

    clrscr();

    printf("Enter N ");

    scanf("%d",&n);

    t=n;

    for(i=1;i<=n;i++)

    { s++;

    for(j=1;j<=t;j++)

    printf(" ");

    for(k=1;k<=s;k++)

        printf(" *");

        printf("\n");

        t--;

    }

    }

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.