Important patterns for IPLC Practical exam with solution

1)Write a program to print following pyramid.
 *
 * *
 * * *
 * * * *

Ans :

#include<stdio.h>
#include<conio.h>
void main()
{
int num,row,col,space;
clrscr();
printf("Enter a num = ");
scanf("%d",&num);
for(row=1;row<num;row++)
{
for(space=num-1;space>row;space--)
{ printf(" "); }

for(col=1;col<=row;col++)
{
printf(" *");
}
printf("\n");
}
        gotoxy(60,20);     //this is optional part
printf("By Aaftab");//this is optional part
        getch();

}


2)Write a program that accepts an integer N, if the integer N = 4,then print the pyramid :
 1
 121
 12321
 1234321

Ans :
#include<stdio.h>
#include<conio.h>
void main()
{
int row,col,k,num,a,b,c;
clrscr();
printf("Enter a num = ");
scanf("%d",&num);
for(row=1;row<num;row++)
{
for(col=1;col<=row;col++)
{
printf("%d",col);
}
for(k=row-1;k!=0;k--)
{
printf("%d",k);
}
printf("\n");
}
        gotoxy(60,20);     //this is optional part
printf("By Aaftab");//this is optional part
        getch();

}

3) Write a program that accepts an integer N, if the integer N =4,then print the pyramid :
4 4 4 4
3 3 3
2 2
1

Ans :

#include<stdio.h>
#include<conio.h>
void main()
{
int row,col,no;
clrscr();
printf("Enter a num =");
scanf("%d",&no);
for(row=no;row>0;row--)
{
for(col=1;col<=row;col++)
{
printf("%d",row);
}
printf("\n");
}
        gotoxy(60,20);     //this is optional part
printf("By Aaftab");//this is optional part
        getch();

}
Click Here to Download c file

4) Write a program to Print following:
A
B C
D E F
G H I J

Ans :

#include<stdio.h>
#include<conio.h>
void main()
{
char ch='A';
int row,col,no;
clrscr();
printf("Enter a num =");
scanf("%d",&no);
for(row=1;row<=no;row++)
{
for(col=1;col<=row;col++)
{
printf("%c",ch);
ch++;
}
printf("\n");
}
        gotoxy(60,20);     //this is optional part
printf("By Aaftab");//this is optional part
        getch();

}
Click Here to Download c file

5) Write a program to Print following:
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1

Ans :
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j=1, rows,rem;
clrscr();
printf("Enter the number of rows = ");
scanf("%d", &rows);
for (i = 1; i <= rows; i++)
{
j=1;
for(; j <= i; j++)
{
rem=j%2;
printf("%d", rem);
}
printf("\n");
}
        gotoxy(60,20);     //this is optional part
printf("By Aaftab");//this is optional part
        getch();

}


6) Write a program to Print following:
A
ABA
ABCBA
ABCDCBA

Ans :

#include<stdio.h>
#include<conio.h>
int main()
{
    int i,j,k,m,rows,ch='A';
    clrscr();
    printf("Enter the number of rows =");
    scanf("%d",&rows);
    for(i=1; i<=rows; i++)
    {

    for(k=1; k<=i; k++)
    {
printf("%c",ch++);
    }
    ch--;
    for(m=1; m<i; m++)
    {
printf("%c",--ch);
    }
    printf("\n");
    }
        gotoxy(60,20);     //this is optional part
printf("By Aaftab");//this is optional part
        getch();

}

Click Here to Download c file

Links and some programs are coming soon 

Comments

Popular posts from this blog

Important Algorithm For CPRG Theory Exam

Software Testing Gujarat University Important Questions For Exam

HTML Frameset (i-frame)