Skip to main content

Star 🌟 Patterns in C Programming Language

 1. Print the Half Pyramid of *.




Ans:

#include <stdio.h>
int main()
{
    int i,j;
    for(i=1;i<=5; i++){
        for(j=1; j<=i; j++){
            printf("* ");
        }
        printf("\n");
    }
    return 0;
}

2. Print the inverted Half Pyramid of the *.






Ans:
#include <stdio.h>
int main()
{
    int i,j;
    for(i=5;i>=1; i--){
        for(j=1; j<=i; j++){
            printf("* ");
        }
        printf("\n");
    }
    return 0;
}

3. Print the Right Half Pyramid of the *.





Ans:
#include <stdio.h>

int main()
{
    int i,j;
    for(i=1;i<=5; i++){
        for(j=1; j<=5; j++){
            if(i+j<=5){
                printf(" ");
            }
            else {
                printf("*");
            }
        }
        printf("\n");
    }
    return 0;
}

4. Print the Full Pyramid of the *.




Ans:
#include <stdio.h>

int main()
{
    int i,j,space;
    
    for(i=1; i<=5; i++){
        for(space=1; space<=5-i; space++){
            printf("  ");
        }
        for(j=1; j<=(2*i)-1; j++){
            printf("* ");
        }
        printf("\n");
    }
    return 0;
}

5. Print the Inverted Full Pyramid  of the *.





Ans:
#include <stdio.h>

int main()
{
    int i,j,space;
    
    for(i=5; i>=1; i--){
        for(space=1; space<=5-i; space++){
            printf("  ");
        }
        for(j=1; j<=(2*i)-1; j++){
            printf("* ");
        }
        printf("\n");
    }
    return 0;
}

6. Print the Triangle of the *.





Ans:
#include <stdio.h>

int main()
{
    int i,j,space;
    
    for(i=1; i<=5; i++){
        for(space=1; space<=5-i; space++){
            printf(" ");
        }
        for(j=1; j<=i; j++){
            printf("* ");
        }
        printf("\n");
    }
    return 0;
}

Comments

Popular posts from this blog

Week 3 Programming Assignment : Programming in Modern C++ 2023

  What is Programming in Modern C++? This course introduces problem-solving and programming using the C++ programming language. The topics include: Basic programming notions. Control flow, variables, and assignments statements, conditional execution, looping, function calls including recursion. Arrays and structures. Elementary aspects of classes. Heap memory.  Program design. How human beings solve problems manually. Strategies for translating manual techniques to computer programs. Organizing large programs into units such as functions and classes. Introduction to assertions and invariants. Programming applications. Arithmetic on polynomials, and matrices. Root finding. Sorting and searching. Design of editors and simulators, including graphical editors. Elementary animation. A rudimentary graphics system will be discussed. Standard Library of C++. The string, vector, and map classes. W3_Programming_Qs-1 Due on 2023-02-16, 23:59 IST Consider the program below. Fill in the bl...

Week 11 Programming Assignment : Programming in JAVA 2023

  What is Programming in Java? Java is a popular object-oriented programming language that was first released in 1995. It is used for developing a wide range of applications, including desktop applications, mobile applications, web applications, and enterprise applications. Here are some key features and concepts of Java programming: Object-oriented programming: Java is an object-oriented language, which means that it focuses on the creation of objects that contain both data and methods that operate on that data. Platform independence: Java programs can run on any platform that supports a Java Virtual Machine (JVM), which makes it a popular choice for cross-platform development. Memory management: Java uses automatic memory management through a garbage collector, which helps to prevent memory leaks and makes it easier to write memory-safe code. Exception handling: Java has a built-in mechanism for handling runtime errors or exceptions, which helps to ensure that programs can re...

Week 4 Programming Assignment : The Joy of Computing using Python 2023

  What is The Joy of Computing using Python? Python is a popular programming language that is easy to learn and widely used for various applications such as web development, data science, and artificial intelligence. Learning Python can be a joyous experience as it allows you to create your own programs, automate tasks, and solve real-world problems. Here are some tips to help you experience the joy of computing using Python: Start with the basics: Before diving into advanced topics, it is essential to learn the basics of Python such as syntax, data types, and control structures. This will help you build a strong foundation and make it easier to learn more advanced topics. Practice coding: The more you practice coding, the better you will get at it. You can start by writing simple programs and gradually move on to more complex ones. There are also many online resources such as coding challenges and competitions that can help you improve your coding skills. Learn from others: There ...

Week 2 Programming Assignment : Programming in Modern C++ 2023

  What is Programming in Modern C++? This course introduces problem-solving and programming using the C++ programming language. The topics include: Basic programming notions. Control flow, variables, and assignments statements, conditional execution, looping, function calls including recursion. Arrays and structures. Elementary aspects of classes. Heap memory.  Program design. How human beings solve problems manually. Strategies for translating manual techniques to computer programs. Organizing large programs into units such as functions and classes. Introduction to assertions and invariants. Programming applications. Arithmetic on polynomials, and matrices. Root finding. Sorting and searching. Design of editors and simulators, including graphical editors. Elementary animation. A rudimentary graphics system will be discussed. Standard Library of C++. The string, vector, and map classes. W2_Programming_Qs-1 Due on 2023-02-09, 23:59 IST Consider the program below. • Fill in th...

Week 1 Programming Assignment : Programming in Modern C++ 2023

  What is Programming in Modern C++? This course introduces problem-solving and programming using the C++ programming language. The topics include: Basic programming notions. Control flow, variables, and assignments statements, conditional execution, looping, function calls including recursion. Arrays and structures. Elementary aspects of classes. Heap memory.  Program design. How human beings solve problems manually. Strategies for translating manual techniques to computer programs. Organizing large programs into units such as functions and classes. Introduction to assertions and invariants. Programming applications. Arithmetic on polynomials, and matrices. Root finding. Sorting and searching. Design of editors and simulators, including graphical editors. Elementary animation. A rudimentary graphics system will be discussed. Standard Library of C++. The string, vector, and map classes. W1_Programming_Qs_1 Due on 2023-02-09, 23:59 IST Consider the program below. • Fill in the ...

Week 2 Programming Assignment : Programming in JAVA 2023

  What is Programming in Java? Java is a popular object-oriented programming language that was first released in 1995. It is used for developing a wide range of applications, including desktop applications, mobile applications, web applications, and enterprise applications. Here are some key features and concepts of Java programming: Object-oriented programming: Java is an object-oriented language, which means that it focuses on the creation of objects that contain both data and methods that operate on that data. Platform independence: Java programs can run on any platform that supports a Java Virtual Machine (JVM), which makes it a popular choice for cross-platform development. Memory management: Java uses automatic memory management through a garbage collector, which helps to prevent memory leaks and makes it easier to write memory-safe code. Exception handling: Java has a built-in mechanism for handling runtime errors or exceptions, which helps to ensure that programs can re...

Week 9 Programming Assignment : Programming in JAVA 2023

  What is Programming in Java? Java is a popular object-oriented programming language that was first released in 1995. It is used for developing a wide range of applications, including desktop applications, mobile applications, web applications, and enterprise applications. Here are some key features and concepts of Java programming: Object-oriented programming: Java is an object-oriented language, which means that it focuses on the creation of objects that contain both data and methods that operate on that data. Platform independence: Java programs can run on any platform that supports a Java Virtual Machine (JVM), which makes it a popular choice for cross-platform development. Memory management: Java uses automatic memory management through a garbage collector, which helps to prevent memory leaks and makes it easier to write memory-safe code. Exception handling: Java has a built-in mechanism for handling runtime errors or exceptions, which helps to ensure that programs can re...