Popular Posts

Showing posts with label C Language. Show all posts
Showing posts with label C Language. Show all posts

Friday, December 4, 2015

Mp3 tag Finding ID3v1 code in c language

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

int main()
{
    FILE* mrid;
    long int i;

    char* tag = (char*)malloc(4);
    char* title = (char*)malloc(31);
    char* album = (char*)malloc(31);
    char* year = (char*)malloc(5);
    char* artist = (char*)malloc(31);
    char* comments = (char*)malloc(31);

    mrid = fopen("d:\\romance.mp3","r");

    if(NULL == mrid)
    {
        printf("\n File open error.");
        return 0;
    }

    fseek(mrid,-128L,2);
    fgets(tag,4,mrid);

    if(0 != strcmp(tag,"TAG"))
    {
        printf("\n Not an ID3v1 standard MP3.");
        fclose(mrid);
        return 0;
    }

    fgets(title,31,mrid);
    fgets(artist,31,mrid);
    fgets(album,31,mrid);
    fgets(year,5,mrid);
    fgets(comments,31,mrid);

    printf("\n TAG         : %s",tag);
    printf("\n TITLE       : %s",title);
    printf("\n ARTIST      : %s",artist);
    printf("\n ALBUM       : %s",album);
    printf("\n YEAR        : %s",year);
    printf("\n COMMENTS    : %s",comments);

    fclose(mrid);
    getch();
    return 0;
}

Wednesday, December 2, 2015

Pyramid Using Two For Loops

Pyramid Using 2 For Loops


#include<stdio.h>

void main()
{
    int i,j,k,row;
    printf("Enter Row: ");
    scanf("%d",&row);
    for(i=0;i<row;i++)
    {
        for(j=row;j>=i;j--)
        {
            printf("  ");
        }
        for(k=0;k<=i;k++)
        {
            printf("*   ");
        }
        printf("\n");
    }
}

Pyramid By Only For LOOP

#include<stdio.h>

void main()
{
    int i,j,k,row;
    printf("Enter Row: ");
    scanf("%d",&row);
    for(i=0;i<row;i++)
    {
        for(j=row;j>=i;j--)
        {
            printf("  ");
        }
        for(k=0;k<=i;k++)
        {
            printf("* ");
        }
        for(k=1;k<=i;k++)
        {
            printf("* ");
        }
        printf("\n");
    }
}

Printing an integer number with delay

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

void pr(int id,int prr[]);
void prin(int prrr[]);
int i;

void main()
{
    int id,prrr[100];
    scanf("%d",&id);
    system("cls");
    pr(id,prrr);
    printf("\n\n\t\t\t");
    prin(prrr);
}

void pr(int id,int prr[])
{
    int p;
    while(id!=0)
    {
        p=(id%10);

        prr[i]=p;
        id/=10;
        i++;
    }
}
void prin(int prrr[])
{
    while(i!=0)
    {
        printf("%d",prrr[--i]);
        Sleep(200);
    }
}

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;
}

Odd Even Number Printing Between Given Range In C language

#include<stdio.h>
#include<conio.h>

void main()
{
    char ch;
    int ran_s,ran_e;
    printf("What do you want to do.......\n\nIf you want to print odd number then type 'o'.....\nElse you want to print even number then type 'e'...\n\nWaiting for your wish: ");
    scanf("%c",&ch);


    printf("\nEnter the start range: ");
    scanf("%d", &ran_s);
    printf("\nEnter the end range: ");
    scanf("%d", &ran_e);


    if(ch=='o' || ch=='O')
    {
        printf("\nThe odd number between your given range : \n---------------------------------------------------\n\n");
        for(;ran_s<=ran_e;ran_s++)
        {
            if(ran_s%2==1)
            {
                printf("\n\t\t%d", ran_s);
            }
        }
    }


        else if(ch=='e' || ch=='E')
    {

        printf("\nThe even number between your given range : \n---------------------------------------------------\n\n");
        for(;ran_s<=ran_e;ran_s++)
        {
            if(ran_s%2==0)
            {
                printf("\n\t\t%d", ran_s);
            }
        }
    }



getch();
}

Matrix Information

#include<stdio.h>
#include<conio.h>

void main()
{
    int row, col,row_t,col_t,sumAvb=0,sumBlw=0;
    printf("Enter Row And Collum :");
    scanf("%d%d", &row, &col);
    col_t=col;
    row_t=row;
    int matrix[row_t][col_t];
    for(row=1;row<=row_t;++row)
    {
        for(col=1;col<=col_t;++col)
        {
            printf("element[%d][%d]",row,col);
            scanf("%d",&matrix[row-1][col-1]);
        }
        printf("\n");
    }
    printf("Your matrix is :\n\n\t\t");
    for(row=0;row<row_t;row++)
    {
        for(col=0;col<col_t;col++)
        {
            printf("%d\t",matrix[row][col]);
        }
        printf("\n\t\t");
    }
    printf("\nDiagonal is: \n\t\t");
    for(row=0;row<row_t;row++)
    {
        for(col=0;col<col_t;col++)
        {
            if(row==col)
            {
                printf("%d\t",matrix[row][col]);
            }
        }
    }
    printf("\nAvove is: \n\t\t");
    for(row=0;row<row_t;row++)
    {
        for(col=0;col<col_t;col++)
        {
            if(row<col)
            {
                printf("%d\t",matrix[row][col]);
                sumAvb+=matrix[row][col];
            }
        }
    }
    printf("\nBelow is : \n\t\t");
    for(row=0;row<row_t;row++)
    {
        for(col=0;col<col_t;col++)
        {
            if(row>col)
            {
                printf("%d\t",matrix[row][col]);
                sumBlw+=matrix[row][col];
            }
        }
    }
    printf("\nSum of avove is = %d\nSum of below is = %d \n\n", sumAvb, sumBlw);
    getch();
}

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");
    }
}