Sunday 10 July 2016

PATTERN programming

1.  WAP in c to print 


*
**
***
****

#include<stdio.h>
#include<conio.h>
main()
{
int i,j;
clrscr();
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}


Output :
 

2.  WAP in c to print 


1
2  2
3  3   3
4  4   4   4


#include<stdio.h>
#include<conio.h>
main()
{
int i,j;
clrscr();
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
getch(); 

Output :

3. WAP in c to print 


1
1 2
1 2 3
1 2 3 4


#include<stdio.h>
#include<conio.h>
main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch(); 

Output :

4. WAP in c to print 


1
2 3
4 5 6 
7 8 9 10


#include<stdio.h>
#include<conio.h>
main()
{
int i,j,k=1;
clrscr();
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",k++);
}
printf("\n");
}
getch(); 

Output :

5. WAP in c to print 


@
+ +
@ @ @
+ + + +


#include<stdio.h>
#include<conio.h>
main()
{
int i,j;
clrscr();
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
if(i%2==0)
{
printf("+ ",i);
}
else
{
printf("@ ",i);
}
}
printf("\n");
}
getch();
}


Output :

6. WAP in c to print 


* * * * *
* * * * *
* * * * *
* * * * *
* * * * *


#include<stdio.h>
#include<conio.h>
main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
printf("* ");
}
printf("\n");
}
getch(); 

Output :

7. WAP in c to print 


1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25


#include<stdio.h>
#include<conio.h>
main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
printf("%d\t",i*j);
}
printf("\n");
}
getch(); 

Output :

No comments:

Post a Comment

index

MENU Sample Papers  (new sample paper added for computers) C Language Mathematics IX (NCERT solution)   Computer IX (CBSE) ...