0% found this document useful (0 votes)
35 views14 pages

Sameer Sir Classes, Jabalpur Auth Exam Center Oracle, Microsoft 9407077858

The document discusses C code to print triangular patterns using nested for loops. It contains 8 examples of code snippets that print triangles of numbers or characters with varying patterns, by manipulating the counter variables in the nested for loops. The document is about using loops to print triangular patterns in C programming.

Uploaded by

Divyansh Rai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views14 pages

Sameer Sir Classes, Jabalpur Auth Exam Center Oracle, Microsoft 9407077858

The document discusses C code to print triangular patterns using nested for loops. It contains 8 examples of code snippets that print triangles of numbers or characters with varying patterns, by manipulating the counter variables in the nested for loops. The document is about using loops to print triangular patterns in C programming.

Uploaded by

Divyansh Rai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Sameer Sir Classes, Jabalpur

Auth Exam Center Oracle, Microsoft


9407077858
/*
-----------------------------------------------------------------
NESTED FOR
------------
2 --> 3

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


{
for( j = 1 ; j <= 3 ; j++)
{
----------
----------
} // j
}

trace :-

i = 1 j = 1 to 3

j = 1 ---> 1 1

j = 2 ---> 1 2

j = 3 ---> 1 3

-----------------------------

Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858
i=2 j = 1 to 3

j = 1 ---> 2 1

j = 2 ---> 2 2

j = 3 ---> 2 3

------------------------------------------------------------------------
n=3

i=1 1

i=2 1 2

i=3 1 2 3
for( i = 1 ;i < = n; i++)
{

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


{
-------
-------
}
}

------------------------------------------------------------------------
Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858
WAP TO PRINT TRIAGLE n = 3
1
1 2
1 2 3
*/
#include<stdio.h>
int main()
{
int n , i , j ;

printf(" ENTER NO OF ROWS \n ");

scanf("%d" , &n);

for( i = 1 ; i <= n ; i++ ) // NO. OF ROWS


{
for( j = 1 ; j <= i ; j++)
{
printf("%4d",j);

} // j

printf("\n");

} // i
}

Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858
1. n=3

i=1 1

i=2 1 2

i=3 1 2 3

printf( "%4d " , j );


-------------------------------------------------------------
2. N=3

2 2

3 3 3

printf("%4d" , i);
---------------------------------------------------------------
3. 3
3 3
3 3 3

printf("%4d" , n);

---------------------------------------------------------------

Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858
4. 1

2 3

4 5 6

int t = 1 ;

printf("%4d" , t);

t++;
------------------------------------------------------------------
5.
A
B C %4c
D E F
or

65

66 67 %4d

68 69 70
int t = 65 ; // char t = 'A' ;

printf("%4c" , t);
t++;
----------------------------------------------------------------------
Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858
6.
A
A B %4c

A B C

or

65

65 66 %4d

65 66 67

int t = 64 ;
printf("%4d" , t + j ) ;

---------------------------------------------------------------------
7.
A
B B
C C C

int t = 64 ;

printf("%4c",t+i);

-----------------------------------------------------------------------
Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858

8. n = 4

0 1

1 0 1

0 1 0 1

-----------------------------------------------------------------------
*/

Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858
/*
------------------------------------------------------------------------
WAP TO PRINT TRIAGLE n = 3
1
2 2
3 3 3
------------------------------------------------------------------------
*/

#include<stdio.h>
int main()
{
int n , i , j ;
printf(" ENTER NO OF ROWS \n ");
scanf("%d" , &n);
for( i = 1 ; i <= n ; i++ ) // NO. OF ROWS
{
for( j = 1 ; j <= i ; j++)
{
printf("%4d",i);

} // j

printf("\n");

} // i
}

Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858
/*
------------------------------------------------------------------------
WAP TO PRINT TRIAGLE n = 3

1
23
45 6
------------------------------------------------------------------------
*/
#include<stdio.h>
int main()
{
int n , i , j ,t = 1 ;
printf(" ENTER NO OF ROWS \n ");
scanf("%d" , &n);

for( i = 1 ; i <= n ; i++ ) // NO. OF ROWS


{
for( j = 1 ; j <= i ; j++)
{
printf("%4d",t);
t++;
} // j

printf("\n");

} // i
}
Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858
/*
------------------------------------------------------------------------
WAP TO PRINT TRIAGLE n = 3
A
B C
D E F
------------------------------------------------------------------------
*/

#include<stdio.h>
int main()
{
int n , i , j ,t = 65 ;
printf(" ENTER NO OF ROWS \n ");
scanf("%d" , &n);

for( i = 1 ; i <= n ; i++ ) // NO. OF ROWS


{
for( j = 1 ; j <= i ; j++)
{
printf("%4C",t);
t++;
} // j

printf("\n");

} // i
}
Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858

/*
------------------------------------------------------------------------
WAP TO PRINT TRIAGLE n = 3

A
A B
A B C
------------------------------------------------------------------------
*/
#include<stdio.h>
int main()
{
int n , i , j ,t ;
printf(" ENTER NO OF ROWS \n ");
scanf("%d" , &n);

for( i = 1 ; i <= n ; i++ ) // NO. OF ROWS


{
t = 64 ;
for( j = 1 ; j <= i ; j++)
{
printf("%4C",(t+j));
} // j
printf("\n");
} // i
}

Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858
/*
------------------------------------------------------------------------
WAP TO PRINT TRIAGLE n = 3

A
B B
C C C
------------------------------------------------------------------------
*/
#include<stdio.h>
int main()
{
int n , i , j ,t ;
printf(" ENTER NO OF ROWS \n ");
scanf("%d" , &n);

for( i = 1 ; i <= n ; i++ ) // NO. OF ROWS


{
t = 64 ;
for( j = 1 ; j <= i ; j++)
{
printf("%4C",(t+i));
} // j
printf("\n");
} // i
}

Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858
WAP TO PRINT TRIAGLE n = 3
1
0 1
1 0 1
#include<stdio.h>
int main()
{
int i , j , n ;
printf(" ENTER NO. OF ROWS \n ");
scanf("%d", &n);

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


{
for( j = 1 ; j <= i ; j++)
{
printf("%4d", (i+j+1) % 2);
}
printf("\n");
}
}
printf(" %4d " , (i+j+1) % 2 );

i=3 j = 1 to 3
j = 1 (3+1+1)%2 = 1
j = 2 (3+2+1)%2 = 0
j = 3 (3+3+1)%2 = 1

Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com
Sameer Sir Classes, Jabalpur
Auth Exam Center Oracle, Microsoft
9407077858

Training for – Programming in C, Cpp, DSA, Java, Python,Linux,Oracle SQL ,CAMPUS and GATE
Internship, Industrial Training, Project Development
https://www.imgjbp.com

You might also like