Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! π
πΉLearn advanced coding techniques in C& C++
πΉMaster Linux internals & shell scripting
πΉDeep dive into Data Structures & Algorithms
πΉExplore Embedded Systems & Microcontrollers (8051,UART, RTOS)
πΉGet hands-on coding tutorials, project ideas,and interview preparation tips
Whether you're a beginner or an experienced programmer, this channel will help you
Longest Substring Without Repeating Characters in C++ LeetCode 3 · sliding window · last index array Table of Contents Problem Statement Approach Algorithm C++ Program Input Sample Output Output Explanation Dry Run Flow of Execution Time Complexity Space Complexity Applications Key Points Interview Questions Frequently Asked Questions Conclusion Problem Statement 3. Longest Substring Without Repeating Characters Given a string s , find the length of the longest substring that contains no repeating characters. A substring is a continuous part of the string, so "pwke" is a subsequence of "pwwkew" but not a substring. Approach We use a sliding window . The window is the part of the string between start and end , and we always keep it free of repeated characters. An array lastIndex of size 128 remembers the most recent position of every ASCII ...
C Triangle Pattern Programs 2: Star, Number, Alphabet & Binary Patterns with Output
π’ C Program to Print Continuous Number Triangle Pattern
#include <stdio.h>
int main()
{
int num, k = 0;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%d ",k++);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
0 1 2 3 4
5 6 7 8
9 10 11
12 13
14
π’ C Program to Print Repeated Binary Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%d ",i%2);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
1 1 1 1 1
0 0 0 0
1 1 1
0 0
1
π’ C Program to Print Binary Number Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%d ",j%2);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
1 0 1 0 1
0 1 0 1
1 0 1
0 1
1
⭐ C Program to Print Inverted Star Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("* ");
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
* * * * *
* * * *
* * *
* *
*
π€ C Program to Print Reverse Repeated Alphabet Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=num;i>=1;i--)
{
for(int j=i;j>=1;j--)
{
printf("%c ",i+64);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
E E E E E
D D D D
C C C
B B
A
π€ C Program to Print Reverse Alphabet Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=num;i>=1;i--)
{
for(int j=i;j>=1;j--)
{
printf("%c ",j+64);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
E D C B A
D C B A
C B A
B A
A
π€ C Program to Print Repeated Alphabet Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%c ",i+64);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
A A A A A
B B B B
C C C
D D
E
π€ C Program to Print Alphabet Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%c ",j+64);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
A B C D E
B C D E
C D E
D E
E
π’ C Program to Print Repeated Number Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%d ",i);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
1 1 1 1 1
2 2 2 2
3 3 3
4 4
5
π’ C Program to Print Descending Number Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%d ",j);
}
printf("\n");
}
return 0;
}
π Explanation:
This C program prints a descending number pattern using nested loops.
The outer loop controls the rows, while the inner loop prints numbers
starting from the current row number up to the entered number.
Comments
Post a Comment