Pages

Write a program in C language to find nCr and nPr

Sunday, 26 January 2014

#include <iostream>
#include <conio.h>
using namespace std;

int fict(int n)
{
    int i, sum=1;
    for(i=1; i<=n; i++)
    {
         sum = sum*i;
    }
    return sum;
}

main()
{
      char status, find;
      int n, r, ans;
   
      while(status != 'n')
      {
             cout << "\n1: nCr\n2: nPr\n";
             find = getch();
             cout << "Enter value of n: ";
             cin >> n;
             cout << "Enter value of r: ";
             cin >> r;
           
             if(find == '1')
             {
                     ans = fict(n) /( fict(r) * fict(n-r));
                     cout << "\nAnswer of "<<n<<"C"<<r<<" is: "<<ans<<endl;
             }
             else if(find == '2')
             {
                     ans = fict(n) / fict(n-r);
                     cout << "\nAnswer of "<<n<<"P"<<r<<" is: "<<ans<<endl;
             }
             else
             {
                     cout << "Enter valid input."<<endl;
             }
           
           
             cout << "You like to calculate again? n/y.";
             status = getch();
      }
       
      system("pause");  
}

Write a program to subtract general order matrixes in c language.

Wednesday, 24 July 2013

#include <iostream>
using namespace std;

int main()
{
    int a1[100][100], a2[100][100], sum[100][100], m, n, r, c;  
    cout<<"Enter number of rows: ";
    cin>>m;
    cout<<"Enter number of columns: ";
    cin>>n;
    cout<<"Enter elements of 1st metrix: ";
    for(r=0; r<m; r++)
    {
          for(c=0; c<n; c++)
          {
                   cin>>a1[r][c];
          }
    }
    cout<<"\nEnter elements of 2nd metrix: ";
    for(r=0; r<m; r++)
    {
          for(c=0; c<n; c++)
          {
                   cin>>a2[r][c];
          }
    }
    cout<<"\nElements of metrix 1: \n";
    for(r=0; r<m; r++)
    {
          for(c=0; c<n; c++)
          {
                   cout<<a1[r][c]<<"\t";
          }
          cout<<endl;
    }
    cout<<"\nElements of matrix 2: \n";
    for(r=0; r<m; r++)
    {
          for(c=0; c<n; c++)
          {
                   cout<<a2[r][c]<<"\t";
          }
          cout<<endl;
    }
    //Subtraction
    for(r=0; r<m; r++)
    {
          for(c=0; c<n; c++)
          {
                   sum[r][c]=a1[r][c]-a2[r][c];
          }
          cout<<endl;
    }
    cout<<"Subtraction of matrix is: \n";
    for(r=0; r<m; r++)
    {
          for(c=0; c<n; c++)
          {
                   cout<<sum[r][c]<<"\t";
          }
          cout<<endl;
    }
    system("pause");
}

Write a program to add general matrix in C language.

#include <iostream>
using namespace std;

int main()
{
    int a1[100][100], a2[100][100], sum[100][100], m, n, r, c;  
    cout<<"Enter number of rows: ";
    cin>>m;
    cout<<"Enter number of columns: ";
    cin>>n;
    cout<<"Enter elements of 1st metrix: ";
    for(r=0; r<m; r++)
    {
          for(c=0; c<n; c++)
          {
                   cin>>a1[r][c];
          }
    }
    cout<<"\nEnter elements of 2nd metrix: ";
    for(r=0; r<m; r++)
    {
          for(c=0; c<n; c++)
          {
                   cin>>a2[r][c];
          }
    }
    cout<<"\nElements of metrix 1: \n";
    for(r=0; r<m; r++)
    {
          for(c=0; c<n; c++)
          {
                   cout<<a1[r][c]<<"\t";
          }
          cout<<endl;
    }
    cout<<"\nElements of matrix 2: \n";
    for(r=0; r<m; r++)
    {
          for(c=0; c<n; c++)
          {
                   cout<<a2[r][c]<<"\t";
          }
          cout<<endl;
    }
    //addition
    for(r=0; r<m; r++)
    {
          for(c=0; c<n; c++)
          {
                   sum[r][c]=a1[r][c]+a2[r][c];
          }
          cout<<endl;
    }
    cout<<"Addition of matrix is: \n";
    for(r=0; r<m; r++)
    {
          for(c=0; c<n; c++)
          {
                   cout<<sum[r][c]<<"\t";
          }
          cout<<endl;
    }
    system("pause");
}

Write A Program To Find The Power Of Number

Wednesday, 17 July 2013

#include<stdio.h>
#include<conio.h>
 main()

{
  int p,n,l=1;
 int s=1;

  printf("\nEnter number = ");
  scanf("%d",&n);

  printf("\nEnter  power =");
  scanf("%d",&p);

  while(l<=p)
  {
      s=s*n;
      l++;
  }

  printf("\n%d  raise to power %d is= %ld",n,p,s);
  getche();
}

 

Search Box

Most Reading

Contact Form

Name

Email *

Message *