Showing posts with label ASSIGNMENT 10. Show all posts
Showing posts with label ASSIGNMENT 10. Show all posts

Thursday, 21 July 2016

PASCALS'S TRIANGLE IS A GEOMETRIC ARRANGEMENT OF THE BINOMIAL COEFFICIENT'S IN A TRIANGLE. IT IS NAMED AFTER BLAISE PASCAL. WAP TO DISPAY N LINES OF THE TRIANGLE

              1
            1  1
          1  2  1
        1  3  3  1
      1  4  6  4  1
    1 5 10 10  5 1
  1 6 15 20 15 6 1

#include<stdio.h>
int fact(int);
main()
{
int k, c,n1,n2,n3,n,j;
printf("Enter the value of n");
scanf("%d",&n);
for(k=1;k<=n;k++)
{
for(j=1;j<=k;j++)
{
int i=0;
n1=fact(j);
n2=fact(j-1);
n3=fact(i);
c=n1/(n2*n3);
printf("%d",c);
i++;
}
printf("\n");
}
}
int fact(int a)
{
int fact=1,j;
if(a>0)
{
for(j=1;j<=a;j++)
{
fact=fact*j;
}
}
else
fact=1;
return fact;
}


WAP TO ADD AND MULTIPLY TWO MATRICES. WRITE A SEPARATE FUNCTIONS TO ACCEPT, DISPLAY AND MULTIPLY THE MATRICES. PERFORM NECESSARY CHECKS BEFORE ADDING AND MULTIPLYING THE MATRICES.

#include<stdio.h>
void accept(int [10][10],int,int);
void add(int [10][10],int [10][10],int,int);
void mul(int [10][10],int [10][10],int,int,int);
void display(int [10][10],int,int);
main()
{
int a[10][10],b[10][10];
int r1,c1,r2,c2;
printf("For 1st Matrix:");
printf("Enter no of rows:");
scanf("%d",&r1);
printf("Enter no of columns:");
scanf("%d",&c1);
printf("For 2nd Matrix:");
printf("Enter no of rows:");
scanf("%d",&r2);
printf("Enter no of columns:");
scanf("%d",&c2);
printf("Enter elements of 1st matrix");
accept(a,r1,c1);
printf("Enter elements of 2nd matrix");
accept(b,r2,c2);
if((r1==r2)&&(c1==c2))
add(a,b,r1,c1);
else
printf("Addition not possible");
if(c1==r2)
mul(a,b,r1,c1,c2);
else
printf("Multiplication not possible");
}
void accept(int a[10][10],int r,int c)
{int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
}
void add(int a[10][10],int b[10][10],int r1,int c1)
{
int i,j;
int d[10][10];
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
d[i][j]=a[i][j]+b[i][j];
}
}
printf("Addition:\n");
display(d,r1,c1);
}
void mul(int a[10][10],int b[10][10],int r1,int c1,int c2)
{
int i,j,v[10][10],k;
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
v[i][j]=0;
for(k=0;k<c1;k++)
{
v[i][j]=v[i][j]+(a[i][k]*b[k][j]);
}
}
}
printf("Multiplication:\n");
display(v,r1,c2);
}
void display(int a[10][10],int r,int c)
{int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
}

WAP TO ACCEPT A MATRIX A OF SIZE m*n AND STORE ITS TRANSPOSE IN MATRIX B. DISPLAY MATRIX B. WRITE SEPARATE FUNCTIONS.

#include<stdio.h>
main()
{
int num,j,i,prime[50],n,p=0,c=0,d=0;
printf("Enter value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&num);
for(j=1;j<=num;j++)
{
if(num%j==0)
p=p+1;
}
if(p==2)
{
prime[c]=num;
c++;
d++;
}
p=0;
}
printf("prime numbers from the numbers are\n");
for(i=0;i<d;i++)
{
printf("%d ",prime[i]);
}
}