Triangle using While Loop in C

Printing Triangle using While Loop in C programming. While Loop allows code to be executed and repeat a specific block of code until the boolean condition is met.

Program While Loop Passwords Program

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int a = 0;
while(a != 12345 && a != 54321) //loop stops when 'a' value Equal to
{                               //12345 And 54321.
printf("Please Enter Password: ");
scanf("%d", &a); //user Enter value saving in 'a'.
}
printf("Password Correct!");
getch();
}
Output
Please Enter Password: 23231212
Please Enter Password: 54321
Password Correct!

Program While Loop using Break Statement

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int a = 0;
while(a <= 10) //loop looping from 0 to 10.
{
if(a == 5) //if 'a' value equal to 5 then
{
printf("The Statement is Break on 5");
break; //break the process.
}
printf("%d\n", a);
a++; //adding 1 to 'a' value.
}
getch();
}
Output
0
1
2
3
4
The Statement is Break on 5

Program Printing Triangle using While Loop

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int a = 0;
while(a <= 10) //loop looping from 0 to 10.
{
int b = 0;
while(b <= a) //loop looping from 0 to 'a' value.
{
printf("*");
b++; //adding 1 to 'b' value.
}
printf("\n"); //used for New Line.
a++; //adding 1 to 'a' value.
}
getch();
}
Output
*
**
***
****
*****
******
*******
********
*********
**********
***********