Popular Posts

Showing posts with label Utpal Kanti Dash Assingnments. Show all posts
Showing posts with label Utpal Kanti Dash Assingnments. Show all posts

Saturday, November 28, 2015

Matrix Multiplication By Using Pointer and Array

#include<stdio.h>
#include<windows.h>

void input(int *ptr);
void outpt(void);
void cal(void);

/*Declaring Global variable*/
int a[2][2],b[2][2],c[2][2],sum,i,j,k;


void main()
{
    int *p;
    p=a;
    printf("Enter First Matrix Elements :\n");
    input(p);/*Calling input() function for input*/
    printf("\n\n");
    p=b;
    printf("Enter Second Matrix Elements :\n");
    input(p);/*Calling input() function for input*/
    cal();/*Calling cal() for multiplication*/
    printf("\n\n");/*printing two new line*/
    printf("Multiplication of two matrix:\n\n\n");
    outpt();/*printing output*/

}


void input(int *ptr)/*input user define function*/
{
    for(i=0;i<2;i++)
    {
        for(j=0;j<=1;j++)
        {
            scanf("%d",&*ptr);
            ptr++;
        }
    }
}

void cal(void)/*cal user define function*/
{
    for(i=0;i<2;i++)
    {
        for(j=0;j<=1;j++)
        {
            sum=0;
            for(k=0;k<2;k++)
            {
               sum+=a[i][k]*b[k][j];
            }
            c[i][j]=sum;
        }
    }
}

void outpt(void)/*output user define function*/
{
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            printf("%6d ", c[i][j]);
            Sleep(1000);
        }
        printf("\n\n");
    }

}

Pyramid by number in C language

#include <stdio.h>

void main()
{
    int p, q, m, n;

    printf("\n How many line do you want: ");
    scanf("%d", &n);

    printf("\n\n");
    for ( p = 1; p <= n; p++)
    {
        for (q = 1; q <= (n-p); q++)
        {
          printf("     ");
        }
        m = p;
        for(q = 1; q <= p; q++)
        {
            printf("%5d", m++);
        }
        m -= 2;
        for( q = 1; q < p; q++)
        {
           printf("%5d", m--);
        }
    printf("\n");
    }
    return 0;
}

Calculating Ratio In C language

#include <stdio.h>

void main()
{
    int p, q, r, s;
    float ratio;

    printf("\n Enter four integers ( seperates by space): ");
    scanf("%d %d %d %d", &p, &q, &r, &s);

    if ( (r-s) == 0 )
        {
        printf("\n Ratio is infinity, because (r-s) is 0.");
        exit(0);
        }

    else
        {
        ratio = (float)(p+q) / (float) (r-s);
        printf("\n Ratio is %.2f", ratio);
        }

   return 0;
}

Convert gallon to litter in C language

#include <stdio.h>


void main()
{
    float gallon,litter;

    printf("\n\n");
    printf("\t\tGallon       Litre");
    printf("\n\t\t......       ......");


    for(gallon=1; gallon<=10; gallon++)
    {
       litter = gallon*3.785;
       printf("\n\t\t%5.2f        %5.2f", gallon, litter);
    }
    printf("\n\n");
    return 0;
}

Decimal to Binary in C language

#include <stdio.h>
#include <math.h>

void main()
{
    long int d_n, rem, b_n = 0, base=1;
    printf("Enter a decimal number : ");
    scanf("%ld",&d_n);
    printf("\n\n\nYour entered decimal number is : %ld",d_n);
    while(d_n!=0)
    {
        rem=d_n%2;
        b_n+=rem*base;
        base*=10;
        d_n/=2;
    }

    printf("\nYahoo Your entered decimal number is converted into binary");
    printf("\nAnd the number is : %ld",b_n);

    return 0;
}

Area triangle in C language

#include <stdio.h>

void main()
{
    float a,b,c;
    float p,area,s;

    a=5;
    b=5;
    c=6;

    s =((a+b+c)/2);
    p = (s*(s-a)*(s-b)*(s-c));
    area = pow(p,.5);
    printf("area is %f", area);

}

Addition Subtraction Multiplication Division in C Language

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char latter;
    printf("What operation you want to do?\n\t A)Addition\n\t B)Subtraction\n\t C)Multiplication\n\t D)Division\n\n\nEnter Your Choice: ");
    scanf("%c", &latter);
    float num1, num2;
    printf("\n\tplease enter the first number: ");
    scanf("%f", &num1);
    printf("\n\tplease enter the second number: ");
    scanf("%f", &num2);
    if(latter == 'A' || latter == 'a')
        printf("\n\tthe sum is %.2f", num1+num2);
    else if(latter == 'B' || latter == 'b')
        printf("\n\tthe difference is %.2f", num1-num2);
    else if(latter == 'C' || latter == 'c')
        printf("\n\tthe multiplication is %.2f", num1*num2);
    else if(latter == 'D' || latter == 'd')
        printf("\n\tthe division is %.2f", num1/num2);
    else
        printf("\n\tyou entered a invalid character");

    return 0;
}

Prepaid Monthly Calling System

/*Here is a program for a post paid customer .where every call cost is 1.25 tk.its a fully postpaid calling system where customer have a monthly limit but he can use how much he want to use. */

#include<stdio.h>

void main()
{
    float rbill=0,blnc,time,tmp_time=0;
    char ch;
    printf("Enter your monthly postpaid limit in taka: ");
    scanf("%f", &blnc);
    loop:
        {
            do
    {
        printf("\n\n");
        printf("Press for a call...");
        getch();
        printf("\nEnter your call time: ");
        scanf("%f", &tmp_time);
        time+=tmp_time;
        rbill+=(tmp_time*1.25);
        printf("Your total call time: %.2f minute.\nYour total bill: %.2f taka.",time,rbill);
    }while(rbill<blnc);
    printf("\n\nSorry You Have Crossed Your Monthly Limit.\nYou have used %.2f extra balance from your limit\n\n", (rbill-blnc));
    printf("If you still want to call press 'c' or 'C' key or Any key to end : ");
    scanf("%s", &ch);
    if(ch=='c'||ch=='C')
    {
        goto loop;
    }
    else
    {
        printf("Program end.");
    }

        }
}

Matrix Multiplication In C

#include<stdio.h>

void main()
{
    int c[2][2],i,j,k,sum=0;
    int a[2][2] = { {5,4},
                    {4,4} };
    int b[2][2] = { {6,7},
                    {4,8} };
    printf("The matrix A is :\n\n\t\t");
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            printf("%d\t",a[i][j]);
        }
        printf("\n\t\t");
    }
    printf("\nThe matrix B is :\n\n\t\t");
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            printf("%d\t",b[i][j]);
        }
        printf("\n\t\t");
    }
    printf("\nMultiplication of A and B matrix is: \n\n\t\t");
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            for(k=0;k<2;k++)
            {
                sum+=(a[i][k]*b[k][j]);
            }
            c[i][j]=sum;
            printf("%d\t",c[i][j]);
        }
        printf("\n\t\t");
    }
}