Programming Fundamentals Lab 5-4

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

PROGRAMMING FUNDAMENTALS LAB

ADNAN HAIDER
REG NO: SP20-BSE-037
ASSIGNMENT # 5-4
SECTION: BSE 2B
DATE: 17-11-2020
1. Print following sequence for n row

#include<stdio.h>
int main()
{
int i,row;
printf("enter te number of row:");
scanf("%d",&row);
while(i<=row)
{
i++;
printf("%d\t%d\t%d\t%d\n",i,i*10,i*100,i*1000);
}
}
2. Wrtie a program to print pascal’s trangle using formula
n! / k! (n – k )!

#include <stdio.h>
main()
{
int rows, coef = 1, space, i, j;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 0; i < rows; i++)
{
for (space = 1; space <= rows - i; space++)
printf(" ");
for (j = 0; j <= i; j++)
{
if (j == 0 || i == 0)
coef = 1;
else
coef = coef * (i - j + 1) / j;
printf("%4d", coef);
}
printf("\n");
}
}
3.Write a program to enter a number and show how many times a digit
appeared in number
e.g., n = 23531
1 =1 times
2 = 1 times
3= 2 times
5 = 1 times
#include<stdio.h>
main()
{
int a[10];
int number,num,i,temp=0;
printf("Enter the number");
scanf("%d",&number);
for(i=0;i<10;i++)
{
a[i]=0;
}
num=number;
while (num>0)
{temp=num%10;
num=num/10;
a[temp]++;
}
for(i=0;i<10;i++)
{
if (a[i]>0)
printf("%d present %d times\n",i,a[i]);
}

Q.5
#include <stdio.h>

void main()
{
int i, j;
char alph = 'A';
int n,blk;
int ctr = 1;

printf("Input the number of Letters (less than 26) in the Pyramid : ");
scanf("%d", &n);

for (i = 1; i <= n; i++)


{
for(blk=1;blk<=n-i;blk++)
printf(" ");
for (j = 0; j <= (ctr / 2); j++) {
printf("%c ", alph++);
}

alph = alph - 2;

for (j = 0; j < (ctr / 2); j++) {


printf("%c ", alph--);
}
ctr = ctr + 2;
alph = 'A';
printf("\n");
}
}

You might also like