Thursday, 24 October 2013

C-Program to Small letter and Capital letter Conversion using ASCII value

#include<stdio.h>
main ()
{
char i,c;
printf("Enter the character\t");
scanf("%c",&c);
i=c;
if((c>=65)&&(c<=90))
{  
c=c+32;
printf("Small letter of %c is %c",i,c);
}  
else
{
if((c>=97)&&(c<=122))
c=c-32;
printf("Capital letter of %c is %c",i,c);
}
}



sakoncepts.blogspot.in
output

C-Program to Small letter and Capital letter Conversion using Library Function

#include<stdio.h>
#include<ctype.h>
main ()
{
char i,c;
printf("Enter the character\t");
scanf("%c",&c);
i=c;
if((c>=65)&&(c<=90))
{  
c=tolower(c);
printf("Small letter of %c is %c",i,c);
}  
else
{
if((c>=97)&&(c<=122))
c=toupper(c);
printf("Capital letter of %c is %c",i,c);
}
}



sakoncepts.blogspot.in
output

Wednesday, 23 October 2013

C-Program to Multiplication of Two Matrices

#include<stdio.h>
#include<stdlib.h>
main ()
{
int p,q,m,n,i,j,k,s=0;
int a[20][20],b[20][20],c[20][20];
printf("Enter the Order of First Matrix\t\t");
scanf("%d%d",&m,&n);
printf("Enter the Order of Second Matrix\t");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("Matrices are not Compatible for Multiplication");
exit(0);
}
printf("Enter the First Matrix\t");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the Second Matrix\t");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}   
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
for(k=0;k<p;k++)
s=s=a[i][k]*b[k][j];
c[i][j]=s;
s=0;
}
}
printf("Product Of Given Matrices is \n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("%d\t",c[i][j]);
printf("\n");
}
}



sakoncepts.blogspot.com
output




LOGIC REFERENCE(WIKIPEDIA):Matrix Multiplication‎

C-Program to Taylor Series Evaluation of Cosine Function

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
float cosine(float,int);
main ()
{
int n;
float x,cos;
printf("Enter the Limit\t");
scanf("%d",&n);
printf("Enter the Value 'X'\t");
scanf("%f",&x);
x=x*(3.14/180);
cos=cosine(x,n);
printf("Cosine value is\t%f",cos);
}


float cosine(float x,int n)
{
int f=1,i;
float t=1,sum=1;
for(i=2;i<=n;i++)
{
t=(t*x*x)/(f*(f+1));
sum=sum+pow(-1,i+1)*t;
f=f+2;
}
return sum;\
}



sakoncepts.blogspot.com
output

C-Program to Taylor Series Evaluation of Sine Function

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
float sine(float,int);
main ()
{
int c,n;
float x,e,s,cos;
printf("Enter the Limit\t");
scanf("%d",&n);
printf("Enter the Value 'X'\t");
scanf("%f",&x);
x=x*(3.14/180);
s=sine(x,n);
printf("Sine value is\t%f",s);
}
float sine(float x,int n)
{
int f=2,i;
float t=x,sum=x;
for(i=2;i<=n;i++)
{
t=(t*x*x)/(f*(f+1));
sum=sum+pow(-1,i+1)*t;
f=f+2;
}
return sum;
}


sakoncepts.blogspot.com
output

C-Program to Taylor Series Evaluation of Exponential Function

#include<stdio.h>
#include<stdlib.h>
float expo(float,int);

main ()
{
int n;
float x,e;
printf("Enter the Limit\t");
scanf("%d",&n);
printf("Enter the Value 'X'\t");
scanf("%f",&x);
e=expo(x,n);
printf("Exponential Value is\t%f",e);
}


float expo(float x,int n)
{
int f=1,i;
float t=1,sum=1;
for(i=2;i<=n;i++)
{
t=(t*x)/f;
sum=sum+t;
f++;
}
return sum;
}



sakoncepts.blogspot.com
output

Tuesday, 22 October 2013

C-Program to Evaluations of Taylor Series Expansions of Exponential,Sine and Cosine Functions

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
float expo(float,int);
float sine(float,int);
float cosine(float,int);
main ()
{
int c,n;
float x,e,s,cos;
printf("Enter the Limit\t");
scanf("%d",&n);
printf("Enter the Value 'X'\t");
scanf("%f",&x);
printf("\n\nTAYLOR SERIES EXPANSION OF\n\t1.Exponential\n\t2.Sine\n\t3.Cosine\n\t4.Exit\n\n\nEnter your Choice\t");
scanf("%d",&c);
switch(c)
{
case 1:
e=expo(x,n);
printf("Exponential Value is\t%f",e);
break;
case 2:
x=x*(3.14/180);
s=sine(x,n);
printf("Sine value is\t%f",s);
break;
case 3:
x=x*(3.14/180);
cos=cosine(x,n);
printf("Cosine value is\t%f",cos);
break;
case 4:
exit(0);
break;
default:
printf("\nInvalid choice selection");
exit(0);
break;
}
}


float expo(float x,int n)
{
int f=1,i;
float t=1,sum=1;
for(i=2;i<=n;i++)
{
t=(t*x)/f;
sum=sum+t;
f++;
}
return sum;
}

float sine(float x,int n)
{
int f=2,i;
float t=x,sum=x;
for(i=2;i<=n;i++)
{
t=(t*x*x)/(f*(f+1));
sum=sum+pow(-1,i+1)*t;
f=f+2;
}
return sum;
}


float cosine(float x,int n)
{
int f=1,i;
float t=1,sum=1;
for(i=2;i<=n;i++)
{
t=(t*x*x)/(f*(f+1));
sum=sum+pow(-1,i+1)*t;
f=f+2;
}
return sum;
}




sakoncepts.blogspot.com
output



LOGIC REFERENCE(WIKIPEDIA):Taylor series‎

C-Program to String Permutation

#include<stdio.h>
#include<string.h>
void permute(int,int);
char str[50];
main ()
{
int l;
printf("Enter the String\t");
scanf("%s",str);
printf("\n\nPermutations of the Given String are:\n\t");
l=strlen(str);
permute(0,l-1);
}

void swap(int m,int j)
{
char t;
t=str[m];
str[m]=str[j];
str[j]=t;
}


void permute(int m,int len)
{
int j;
if(m==len)
printf("%s\n\t",str);
else
{
for(j=m;j<=len;j++)
{
swap(m,j);
permute(m+1,len);
swap(m,j);
}
}
}


sakoncepts.blogspot.com
output




LOGIC REFERENCE(WIKIPEDIA):String Permutation‎

C-Program to Sort Strings By Lexicographic Order

#include<stdio.h>
#include<string.h>
main ()
{
char str[50][50],temp[50];
int i,j,n;
printf("Enter the Number of strings\t");
scanf("%d",&n);
printf("Enter the Strings\n");
for(i=0;i<n;i++)
scanf("%s",str[i]);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(str[i],str[j])>0)
{
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
}
printf("\n\nSorted items(Lexicographic method) are\n\t");
for(i=0;i<n;i++)
printf("%s\n\t",str[i]);
}




sakoncepts.blogspot.com
output




LOGIC REFERENCE(WIKIPEDIA):Lexicographical order‎

C-program to Check Armstrong Number

#include<stdio.h>
main ()
{
int sum=0,d=1,p,n;
printf("Enter the Number to be Checked\t");
scanf("%d",&n);
p=n;
while(n>0)
{
d=n%10;
sum=sum+(d*d*d);
n=n/10;
}
if(p==sum)
printf("The Given Number is ARMSTRONG");
else
printf("The Given Number is NOT Armstrong");
}


sakoncepts.blogspot.com
output




LOGIC REFERENCE(WIKIPEDIA):Armstrong Number
        

C-Program to Find Mean Median Mode of The Elements of a Set

#include<stdio.h>
main ()
{
int n,i,a[50]={0},sum=0,j,t,k=0,b[50]={0},max=0,c=1,mode;
float median=0.0,mean=0.0;
printf("Enter the no.of elements in the set\t");
scanf("%d",&n);
printf("\nEnter the elements\t");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}



/*SORTING(Bubble sort method)*/

for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("Ordered set is\t");
for(i=0;i<n;i++)
printf("%d\t",a[i]);



/*MEAN*/

mean=(float)sum/n;
printf("\n\n1.MEAN of the elements of the set:\t%f",mean);




/*MEDIAN*/

if(n%2==0)
median=(float)(a[(n/2)]+a[(n-1)/2])/2;
else
median=a[(n-1)/2];
printf("\n2.MEDIAN is\t%f",median);





/*MODE*/

for(i=0;i<n-1;i++)
{
mode=0;
for(j=i+1;j<n;j++)
{
if(a[i]==a[j])
mode++;
}
if((mode>max)&&(mode!=0))
{
k=0;
max=mode;
b[k]=a[i];
k++;
}
else if(mode==max)
{
b[k]=a[i];
k++;
}
}

for(i=0;i<n;i++)
{
if(a[i]==b[i])
c++;
}  
if(c==n)
printf("\n3.There is no MODE");
else
{
printf("\n3.MODE is \t");
for(i=0;i<k;i++)
printf("%d\t",b[i]);
}
}





sakoncepts.blogspot.com
output




LOGIC REFERENCE(WIKIPEDIA):
       1.Mode(Statistics)
              2.Median‎
              3.Mean‎



































Monday, 21 October 2013

C-Program to Conversion of Binary Code to Decimal,Octal,Hexadecimal

#include<stdio.h>
#include<stdlib.h>
main()
{
int b,d,z,r,t,y[50],i,j,dec,x[50];
printf("Enter the Binary Number\t");
scanf("%d",&b);
t=b;
z=1;
d=0;
if(b==0)
{
printf("Decimal Equivalant of %d is 0\n",b);
printf("Octal Equivalant of %d is 0\n",b);
printf("HexaDecimal Equivalant of %d is 0",b);
exit(0);
}
while(b>0)
{
r=b%10;
if(r>1)
{
printf("\n Invalid Entry");
exit(0);
}
d=d+(z*r);
z=z*2;
b=b/10;
}
dec=d;
j=0;
while(d>0)
{
r=d%8;
x[j]=r;
j++;
d=d/8;
}
d=dec;
j=0;
while(d>0)
{
r=d%16;
y[j]=r;
j++;
d=d/16;
}
printf("Decimal Equivalant of %d is \t%d\n",t,dec);
printf("Octal Equivalant of %d is \t",t);
for(i=j-1;i>=0;i--)
printf("%d",x[i]);
printf("\nHexaDecimal Equivalant of %d is\t",t);
for(i=j-1;i>=0;i--)
{  
switch(y[i])
{
case 10:
printf("A");
break;
case 11:
printf("B");
break;
case 12:
printf("C");
break;
case 13:
printf("D");
break;
case 14:
printf("E");
break;
case 15:
printf("F");
break;
default:
printf("%d",y[i]);
        break;
}
}
}






sakoncepts.blogspot.com
output

C-Program for Binary to HexaDecimal Conversion

#include<stdio.h>
#include<stdlib.h>
main()
{
int b,d,z,r,t,y[50],i,j;
printf("Enter the Binary Number\t");
scanf("%d",&b);
t=b;
z=1;
d=0;
if(b==0)
{
printf("HexaDecimal Equivalant of %d is 0",b);
exit(0);
}
while(b>0)
{
r=b%10;
if(r>1)
{
printf("\n Invalid Entry");
exit(0);
}
d=d+(z*r);
z=z*2;
b=b/10;
}
j=0;
while(d>0)
{
r=d%16;
y[j]=r;
j++;
d=d/16;
}
printf("HexaDecimal Equivalant of %d is\t",t);
for(i=j-1;i>=0;i--)
{  
switch(y[i])
{
case 10:
printf("A");
break;
case 11:
printf("B");
break;
case 12:
printf("C");
break;
case 13:
printf("D");
break;
case 14:
printf("E");
break;
case 15:
printf("F");
break;
default:
printf("%d",y[i]);
        break;
}
}
}







sakoncepts.blogspot.com
output