C Programme:

N.B.:Following C Codes suitable for Compiler Dev C++ ,  Download Dev C++

Assignment

Matrix Multiplication:Download code

                                           20/07/2017

 /*C code for calculate square and quebe*/


#include<stdio.h>
#include<math.h>
main()
{
int x,r;
printf("enter the number for calculate square and quebe=");
scanf("%d",&x);
r=pow(x,2);
printf("square of %d is %d",x,r);
r=pow(x,3);
printf("\n quebe of %d is %d",x,r);
}


                                           25/07/2017

 /*C code for calculate  0!+1!+2!+.........+n!   */    



#include<stdio.h>
main()
{
int i,f=1,n,s=1;
printf("enter a +ve number=");
scanf("%d",&n);
for(i=1;i<=n;i++)
 {
 f=f*i;
 s=s+f;
 }
printf("\n0!+1!+....+%d!=%d",n,s);
}


  /*C code for calculate for 0!+1!+2!+.........+n! with method  */  

#include<stdio.h>
main()
{
long int f=1,sum=1;
int i,n,k;
printf("\nEnter the value of n between (1 to 12)=");
scanf("%d",&n);
if(n>12)
 {
 error:
 printf("You have entered wrong input !!!!!!!!\nPlease try again.....");
 }
else
  if(n<0)
  goto error;
else
{

 for(i=1;i<=n;i++)
 {
 printf("\n f=%ld*%d",f,i);
f=f*i;
 printf("=%ld",f);
 printf("\n sum=%ld+%ld",sum,f);
sum=sum+f;
 printf("=%ld\n",sum);
  }
printf("\nResult:\n");
for(k=0;k<n;k++)
 printf("%d!+",k);
 printf("%d!=%ld",n,sum);
  }
 }



  /*C code for simple calculator (+,-,*,/) with switch method  */

#include<stdio.h>
main()
{
 int a,b,c;
 float d;
 char s;
 printf("What you want to do ? (+,-,*,/) ");
 start:
 s=getchar();
 switch (s)
 {
 case '+':
   printf("Enter two number=");
   scanf("%d%d",&a,&b);
   c=a+b;
   printf("\n%d+%d=%d",a,b,c);
   break;
 
    case '-':
   printf("Enter two number=");
   scanf("%d%d",&a,&b);
   c=a-b;
   printf("\n%d-%d=%d",a,b,c);
   break;
 
    case '*':
   printf("Enter two number=");
   scanf("%d%d",&a,&b);
   c=a*b;
   printf("\n%d*%d=%d",a,b,c);
   break;
    case '/':
   printf("Enter two number=");
   scanf("%d%d",&a,&b);
   d=(float)a/b;
   printf("\n%d/%d=%.2f",a,b,d);
   break;
    default :
   printf("You have entered wrong input\nPlease enter(+,-,*,/)\n");
  fflush(stdin);
 goto start;
               
 }


}

  /*C code for find a element from array  with if for method  */

#include<stdio.h>
 void main()
{
int n,i,e,f,a[100];
printf("Enter the value of n=");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nenter the element of %d position= ",i);
scanf("%d",&a[i]);
}
printf("\nwhat number you find out ");
scanf("%d",&e);
f=0;
for(i=0;i<n;i++)
{
if(a[i]==e)
f=1;
}
if(f==1)
printf("The number %d is find out",e);
else
printf("The nmber %d is not find out",e);
}


                                           10/08/2017

  /*C code for swapping two element's value between each other*/

#include<stdio.h>
main()
{
int a,b;
printf("Enter the value of a & b \n");
scanf("%d%d",&a,&b);
printf("\n You have entered a=%d b=%d",a,b);
a=a*b;    
b=a/b; /* a=a+b;b=a-b;a=a-b */
a=a/b;
printf("\n       After swap a=%d b=%d",a,b);
}


 /*C code for count no. of Note and Coin between the given amount*/

#include<stdio.h>
main()
{
long int amount,ttn,thn,fhn,hn,fn,tw,tn,five,two,one,r1,r2,r3,r4,r5;
printf("Enter amount\n");
scanf("%ld",&amount);
ttn=amount/2000;
   r1=amount%2000;
thn=r1/1000;
r2=r1%1000;
fhn=r2/500;
r3=r2%500;
hn=r3/100;
r1=r3%100;
fn=r1/50;
r2=r1%50;
tw=r2/20;
r3=r2%20;
tn=r3/10;
r4=r3%10;
five=r4/5;
r5=r4%5;
two=r5/2;
one=r5%2;
printf("\n%ld Two-Thousand \n%ld Thousand \n%ld Five-Hundred \n%ld Hundred \n%ld Fifty \n%ld Twenty \n%ld Ten",ttn,thn,fhn,hn,fn,tw,tn);
printf("\n%ld five \n%ld Two \n%ld One \n",five,two,one);
printf("\nTotal No of Note %ld \nTotal No of Coin %ld",ttn+thn+fhn+hn+fn+tw+tn,five+two+one);
}


                                           14/08/2017



  /*C code for find biggest marks and total,percentage of given marks */

#include<stdio.h>
main()
{
int mark[5],i,big,total_no,sub_det;
float per;
printf("\nEnter Bengali marks= ");
scanf("%d",&mark[0]);
printf("\nEnter English marks= ");
scanf("%d",&mark[1]);
printf("\nEnter Math marks= ");
scanf("%d",&mark[2]);
printf("\nEnter Physics marks= ");
scanf("%d",&mark[3]);
printf("\nEnter Biology marks= ");
scanf("%d",&mark[4]);
//biggest test
big=mark[0];
for(i=0;i<5;i++)
{
if(big<mark[i])
{
big=mark[i];
sub_det=i;
}
total_no=total_no+mark[i];
}
per=(float)total_no/5;
printf("\n\tTotal Marks: %d \n\tPersentage: %f %d",total_no,per,sub_det);

switch(sub_det)
{
case 0:
printf("\n\tThe biggest mark %d in Bengali",big);
break;
case 1:
printf("\n\tThe biggest mark %d in English",big);
break;
case 2:
printf("\n\tThe biggest mark %d in Math",big);
break;
case 3:
printf("\n\tThe biggest mark %d in Physics",big);
break;
case 4:
printf("\n\tThe biggest mark %d in Biology",big);
break;
default:
printf("Code error");
break;
}


}




  /*C code for find grade of marks */

#include<stdio.h>
main()
{
int key,tmark;
float per;
printf("\n Enter total marks of five subject:\n");
scanf("%d",&tmark);
per=(float)tmark/5;
printf("\nYour marks persentage %.2f",per);
key=per/10;
switch(key)
{
case 10:
printf("\n Full marks...");
break;
case 9:
printf("\n\tGrade A+ ");
break;
case 8:
printf("\n\tGrade A ");
break;
case 7:
printf("\n\tGrade B+ ");
break;
case 6:
printf("\n\tGrade B ");
break;
case 5:
printf("\n\tGrade C+ ");
break;
case 4:
printf("\n\tGrade C ");
break;
case 3:
printf("\n\tGrade D ");
break;
case 2:
case 1:
case 0:
printf("\n\tYou are fail !!!");

}
}


                                           20/09/2017



  /*C code for Find smallest number in a list */


#include<stdio.h>
main()
{
int a[100],n,i,small;
printf("Enter the number of terms=");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the number=");
scanf("%d",&a[i]);
}
small=a[0];
for(i=0;i<n;i++)
{
if(small>a[i])
small=a[i];
}
printf("\nSmallest number=%d",small);
}



/*C code for Shutdown restart computer*/

#include<stdio.h>
#include<stdlib.h>
main()
{
char s,l,r,m;
printf("What you want to do ?\nFor Shutdown type 's'\nFor Logout type 'l'\nFor Restart type 'r'\n ");
m=getchar();
switch(m)
{
case 's':
system("C:\\Windows\\System32\\shutdown /s");
break;
case 'l':
system("C:\\Windows\\System32\\shutdown /l");
break;
case 'r':
system("C:\\Windows\\System32\\shutdown /r");
break;
default :printf("\nYou have enter wrong input");
break;
}

}


/*Multiplication Table for given Number*/

#include<stdio.h>
main()
{
int i,mul,j;
printf("Enter a number: ");
scanf("%d",&j);
for(i=1;i<11;i++)
{
mul=j*i;
printf(" %d*%d=%d\n",j,i,mul);
}
}


/*Matrix multiplication*/

#include<stdio.h>
main()
{
int A[4][4],B[4][4],C[4][4],r1,c1,r2,c2,i,j,k;
printf("enter row and column of first matrix: ");
scanf("%d%d",&r1,&c1);
printf("enter row and column of second matrix: ");
scanf("%d%d",&r2,&c2);
if(c1==r2)
{
printf("Enter A Matrix element\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&A[i][j]);
}
printf("Enter B Matrix element\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&B[i][j]);
}
/*MULTIMLICATION PART*/  
for(i=0;i<r1;i++)                //r1 row of first matrix, i row of new matrix
{
for(k=0;k<c2;k++) //c2 column of second matrix, k column of new matrix
{
C[i][k]=0; // zero value of every cell of new matrix
for(j=0;j<c1;j++) //c1=c2 , calculate the S-O-P
{
C[i][k]+=A[i][j]*B[j][k];  //i,k not change
}
}
}
printf("After mutliplication:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
printf("%-4d",C[i][j]);
printf("\n"); 
}
   }
   else printf("Wrong row and column");
}


/*Matrix Addition*/

#include<stdio.h>
main()
{
int i,j,r,c;
long int a[3][3],b[3][3],m[3][3];
printf("Enter the number of row and column :\n");
scanf("%d%d",&r,&c);
printf("\n Create 'A' matrix.....\n");
for(i=0;i<r;i++)
{
 for(j=0;j<c;j++)
{
printf("\nEnter the value of [%d,%d] position: ",i,j);
scanf("%ld",&a[i][j]);
}
    }
printf("\n Create 'B' matrix.....\n");
for(i=0;i<r;i++)
{
 for(j=0;j<c;j++)
{
printf("\n Enter the value of [%d,%d] position: ",i,j);
scanf("%ld",&b[i][j]);
}
    }

for(i=0;i<r;i++)
{
 for(j=0;j<c;j++)
{
m[i][j]=a[i][j]+b[i][j];
}
    }
printf("\nSum of 'A' & 'B' matrix is:\n\n");
for(i=0;i<r;i++)
{
 for(j=0;j<c;j++)
{
printf("\t%ld",m[i][j]);
}
printf("\n\n");
    }    

}


/* This programme find a number among the array */

#include<stdio.h>
 void main()
{
int n,i,e,f,a[100],p;
printf("Enter the value of n=");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nenter the element of %d position= ",i);
scanf("%d",&a[i]);
}
printf("\n\n What number you want to find out ");
scanf("%d",&e);
f=0;
for(i=0;i<n;i++)
{
if(a[i]==e)
{
f=1;
printf("\nThe number %d is find out in the %d position. \n ",e,i);

    }
}
       if(f==0)
printf("\nThe number %d is not find out. \n\n",e);

}


/*INVESMENT PROBLEM*/
/*Find Interest*/

#include<stdio.h>

main()
{
int year,i;
float p,a,ir;

printf("Enter The Principle-->");
scanf("%f",&p);
printf("\nEnter Year-->");
scanf("%d",&year);
printf("\nEnter Interest Rate-->");
scanf("%f",&ir);
printf("\nYEAR\tAMOUNT");
for(i=0;i<=year;i++)
 {
  a=p+(p*i*ir)/100;
  printf("\n  %d\t%.2f",i,a);
  }


}


/*Convert number in words range(1 to 9999)*/
#include<stdio.h>

main()
{
int amt,d,n,w,k,i=0,j=0,arr[10],flag=0;
char one[10][6]={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
char ten[10][11]={"Ten","Eliven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
char mten[10][11]={"","","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninenty"};
    
printf("Enter amount: ");
scanf("%d",&amt);
for(;amt>0;amt/=10)
{
d=amt%10;
  if(i==1)
  {
  d=d*10+arr[0];
  }
arr[j++]=d;
    i++;
}
    i--;
    j--;
 for(;j>=0;j--)
   {
      if(i==3)
      {
      printf("%s Thousand ",one[arr[j]]);
  }
  if(i==2)
  {
  if(arr[j]!=0)
  printf("%s Hundred ",one[arr[j]]);  //one[]
  }
  if(i==1&&arr[j]>=20)
  {
  printf("%s ",mten[arr[j]/10]);
  }
  if(i==1&&arr[j]>=10&&arr[j]<20)
  {
  printf("%s ",ten[arr[j]%10]);
  flag=1;
  }
  if(i==0&&flag==0)
  {
  printf("%s ",one[arr[j]]);
  }
  i--;

    }
    getch();

}



/*Convert number TO words range(1 to 99999)*/

#include<stdio.h>

main()
{
int amt,d,n,w,k,num=0,i=0,j=0,arr[10],flag=0,flag1=0;
char one[10][6]={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
char ten[10][11]={"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
char mten[10][11]={"","","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninenty"};
    
printf("Enter amount: ");
scanf("%d",&amt);
for(;amt>0;amt/=10)
{
d=amt%10;
  if(i==1)
  {
  d=d*10+arr[0];
  }
arr[j++]=d;
    i++;
}
    i--;
    j--;
 for(;j>=0;j--)
   {
    if(i==4)
{
num=arr[j]*10+arr[j-1];
if(num>=20)
  {
  printf("%s ",mten[num/10]);
  num=num%10;
  }
  if(num>=10)
  {
  printf("%s ",ten[num%10]);
  num=0;
  }
  if(num>0)
  {
  printf("%s ",one[num]);
  }
  printf("Thousand ");
  flag=1;
}
  
 
      if(i==3&&flag==0)
      {
      printf("%s Thousand ",one[arr[j]]);
  }
  if(i==2)
  {
  if(arr[j]!=0)
  printf("%s Hundred ",one[arr[j]]);  //one[]
  }
  if(i==1&&arr[j]>=20)
  {
  printf("%s ",mten[arr[j]/10]);
  }
  if(i==1&&arr[j]>=10&&arr[j]<20)
  {
  printf("%s",ten[arr[j]%10]);
  flag1=1;
  }
  if(i==0&&flag1==0)
  {
  printf("%s",one[arr[j]]);
  }
  i--;

    }

}



/*Hexadecimal to dacimal conversion*/

#include<stdio.h>
#include<string.h>
#include<math.h>
int e_conv(char);
main()
{
char h[20],e;
int num,i,ai,i1,d;
top:
printf("Enter a Hexadecimal number: ");
gets(h);  //Input as a String 
i1=i=strlen(h)-1;
for(ai=0;ai<=i1;ai++)
{
e=h[ai];
  d=e_conv(e);
if(d>15)
{
printf("you have enter wrong input\n");
num=0;
i=0;
goto top;
}
num+=d*pow(16,i);
i--;
}
printf("\nDecimal number %d",num);

}

int e_conv(char e)
{
if(e>=48&&e<=57)
  return(e-48);
if(e>=65&&e<=90)
  return(e-55);

}




/*ANY BASE TO ANY BASE CONVERSION*/
#include<stdio.h>
#include<string.h>
#include<math.h>
int e_conv(char);
main()
{
char input[20],e;
char bd[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
int num,i,ai,AL,d,basef,baset,a[40];
printf("ENTER BASE(From): ");
scanf("%d",&basef);
printf("ENTER BASE(to): ");
scanf("%d",&baset);
top:
printf("Enter a base %d number: ",basef);
fflush(stdin);
gets(input);
AL=i=strlen(input)-1; //i=index
for(ai=0;ai<=AL;ai++)
{
e=input[ai];
d=e_conv(e);
if(d>basef-1)
{
printf("you have enter wrong input\n");
num=0; i=0; goto top;
}
num+=d*pow(basef,i); //Decimal a convert
i--;
}
i=0;
while(num>0)
{
a[i++]=num%baset; num=num/baset;
}
i--;
printf(" Base %d number: ",baset);
while(i>=0)
{
printf("%c",bd[a[i]]); i--;
}
}

int e_conv(char e)
{
if(e>=48&&e<=57)
return(e-48);
if(e>=65&&e<=90)
return(e-55);
}




                                      By: Masidur Rahaman 

                                         NEED YOUR HELP