0% found this document useful (0 votes)
24 views

Patterns

The document contains examples of using for loops in C code to print different patterns. It shows how nested for loops can be used to print numbers, characters, or in descending order across multiple lines.

Uploaded by

Jan Agha Junior
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Patterns

The document contains examples of using for loops in C code to print different patterns. It shows how nested for loops can be used to print numbers, characters, or in descending order across multiple lines.

Uploaded by

Jan Agha Junior
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <stdio.

h>

int main()
{
        int i, j;
    
        for (i = 1; i <= 5 ; i++)
    {
                printf("%d", i);
    }
}

Output : 12345

int main()
{
        int i, j;
    
        for (i = 1; i <= 5 ; i++)
    {
                for (j = 1;j <= 5; j++)
        {
                printf("%d", j);
        }
                printf("\n");
    }
}

Output :
12345
12345
12345
12345
12345

int main()
{
        int i, j;
    
        for (i = 1; i <= 5 ; i++)
    {
                for (j = 1;j <= 5; j++)
        {
                printf("%d", i);
        }
                printf("\n");
    }
}
Output :
11111
22222
33333
44444
55555

int main()
{
        int i, j;
    
        for (i = 1; i <= 5 ; i++)
    {
                for (j = 1;j <= 5; j++)
        {
                printf(“*”);
        }
                printf("\n");
    }
}

Output :
*****
*****
*****
*****
*****

int main()
{
        int i, j;
    
        for (i = 1; i <= 5 ; i++)
    {
                for (j = 1;j <= 5; j++)
        {
                printf(“%c”, j+64); // here it prints the ASCII value of alphabets.
        }
                printf("\n");
    }
}

Output :
ABCDE
ABCDE
ABCDE
ABCDE
ABCDE

int main()
{
        int i, j;
    
        for (i = 1; i <= 5 ; i++)
    {
                for (j = 5;j >= 1; j--)
        {
                printf("%d", j);
        }
                printf("\n");
    }
}

Output :
54321
54321
54321
54321
54321

You might also like