Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

ASSIGNMENT-VII

Question-1: Write a program to check given number is palindrome or not.


Answer:
#include<stdio.h>
int main()
{
int n,r,temp,sum=0;
printf("Enter the number to be checked ");
scanf("%d",&n);
temp=n;
while (n!=0)
{
r=n%10;
sum=sum*10+r;
n/=10;
}
if (temp==sum)
printf("Number is palindrome\n");
else
printf("Number is not a palindrome\n");
return 0;
}

Question-2: Write a program to print triangles stars in C:


(a.) Full pyramid :
Answer:
#include<stdio.h>
int main()
{
int row,x;
printf("Enter the number of rows of the pyramid ");
scanf("%d",&row);
for(int i=1,x=0;i<=row;i++,x=0)
{
for(int space=1;space<=row-i;++space)
{
printf(" ");
}
while(x!=2*i-1)
{
printf("*");
++x;
}
printf("\n");
}
return 0;
}

(b.) Half Pyramid :


Answer:
#include<stdio.h>
int main()
{
int row;
printf("Enter the number of rows of the pyramid ");
scanf("%d",&row);
for(int i=0;i<row;i++)
{
for(int j=0;j<=i;j++)
{
printf("* ");
}
printf("\n");
}
return 0;
}

(c.) Inverted Full Pyramid :


Answer:
#include<stdio.h>
int main()
{
int row,j,i;
printf("Enter the number of rows of the pyramid ");
scanf("%d",&row);
for(i=row;i>=1;i--)
{
for(int space=0;space<row-i;space++)
{
printf(" ");
}
for(j=i;j<=2*i-1;j++)
{
printf("*");
}
for(j=0;j<i-1;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}

(d.) Inverted half pyramid :


Answer:
#include<stdio.h>
int main()
{
int row;
printf("Enter the number of rows of the pyramid ");
scanf("%d",&row);
for(int i=0;i<row;i++)
{
for(int j=row;j>i;j--)
{
printf("* ");
}
printf("\n");
}
return 0;
}

Question-3: Write a C program to print hollow mirrored inverted right


triangle star pattern series of n rows using for/while/do while loop.
Answer:
#include<stdio.h>
int main()
{
int row,j,i;
printf("Enter the number of rows of the pyramid ");
scanf("%d",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=row;j++)
{
printf(" ");
}
for(j=1;j<=row;j++){
if(j==i||j==row||i==1){
printf("*");
}
else {
printf(" ");
}
}
printf("\n");

}
return 0;
}

You might also like