Easy learn c program in c language
[There are some types of pattern based program]
Q.1. Print the output
*
* *
* * *
* * * *
* * * * *
Ans
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf(" *");
}
printf("\n");
}
getch();
}
Q.2. Print the output
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Ans
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
getch();
}
Q.3. Print the output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Ans
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
Q.4. Print the output
* * * * *
* * * *
* * *
* *
*
Ans
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=i;j<=5;j++)
{
printf(" *");
}
printf("\n");
}
getch();
}
[There are some types of pattern based program]
Q.1. Print the output
*
* *
* * *
* * * *
* * * * *
Ans
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf(" *");
}
printf("\n");
}
getch();
}
Q.2. Print the output
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Ans
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
getch();
}
Q.3. Print the output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Ans
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
Q.4. Print the output
* * * * *
* * * *
* * *
* *
*
Ans
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=i;j<=5;j++)
{
printf(" *");
}
printf("\n");
}
getch();
}
Q.5. Print the output
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
Ans
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
{
printf(" %d",j);
}
printf("\n");
}
getch();
}
If you have any query then you ask in comment section.
THANK YOU
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
{
printf(" %d",j);
}
printf("\n");
}
getch();
}
If you have any query then you ask in comment section.
THANK YOU
Thanks
ReplyDelete