GoogelAddUnit1

Monday 16 April 2012

WRITE A C-PROGRAM TO FIND THE BIGGEST&SMALLEST NUMBER OF THE GIVEN MATRIX.

WRITE A C-PROGRAM TO FIND THE BIGGEST&SMALLEST NUMBER OF THE GIVEN MATRIX.
AIM:A program to find the biggest and smallest number of a given matrix.
PROGRAM:
#include<stdio.h>
main()
{
int a[10][10],i,j,m,n,big,small;
printf("enter the values of m,n");
scanf("%d%d",&m,&n);
printf("enter the elemnts of matrix a");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
big=a[0][0];
small=a[0][0];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(a[i][j]>big)
big=a[i][j];
if(a[i][j]<small)
small=a[i][j];
printf("biggest element =%d",big);
printf("smallest element =%d",small);
}
OUTPUT:
enter the values of m,n
3,3
enter the elements of matrix a
1 2 3
3 4 5
5 6 7
biggest element 7
smallest element 1
WRITE A C-PROGRAM TO DEFINE A STRUCTURE WITH THE STUDENT NUMBER,NAME,M1,M2,M3 FIND THE RESULT OF DIFFERENT STUDENTS.

AIM:A program to find the result of different students using structures.
PROGRAM:
#include<stdio.h>
struct stu
{
int no,m1,m2,m3;
char name[20];
float ave;
}s[50];
main()
{
int i,n;
printf("enter the no.of students");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
printf("enter the values of number,name,m1,m2,m3");
scanf("%d%s%d%d%d",s[i].no,s[i].name,s[i].m1,s[i].m2,s[i].m3);
s[i].avg=(s[i].m1+s[i].m2+s[i].m3)/3;
for(i=0;i<=n;i++)
{
if((s[i].m1>=35)&&(s[i].m2>=35)&&(s[i].m3>=35))
{
if((s[i].avg>=75)&&(s[i].avg<=100))
printf("distinction");
else
if((s[i].avg>=60)&&(s[i].avg<75))
printf("first class");
else
if((s[i].avg>=50)&&(s[i].avg<60))
printf("second class");
else
printf("third class");
}
else
printf("fail");
}
}
OUTPUT:
enter the values of no,name,m1,m2,m3
2,sneha,78,67,45
distinction

WRITE A C-PROGRAM TO FIND THE SUM OF ANY TWO NUMBERS USING RECURRSION.

WRITE A  C-PROGRAM TO FIND THE SUM OF ANY TWO NUMBERS USING RECURRSION.
AIM:A program to find the sum of any two number using recurrsion.
PROGRAM:
#include<stdio.h>
main()
{
int a,b,k;
printf("enter the values of a,b");
scanf("%d%d",&a,&b);
k=sum(a,b);
printf("sum=%d",k);
}
sum(a,b)
int a,b;
{
if(a==0)
return(b);
else
sum(--a,++b);
}
OUTPUT:
enter the values of a,b
30,20
sum=50

WRITE A C-PROGRAM TO FIND THE FACTORIAL VALUE USING RECURRSION

WRITE A C-PROGRAM TO FIND THE FACTORIAL VALUE USING RECURRSION
AIM:A program to find the factorial value using recurrsion
PROGRAM:
#include<stdio.h>
main()
{
int n,k;
printf("enter the value of n");
scanf("%d",&n);
k=fact(n);
printf("factorial value of a given number :%d",k);
}
fact(int m)
{
if(m==1)
return(1);
else
return(m*fact(m-1));
}
OUTPUT:
enter a number
4
factorial value of a given number: 24
enter a number
3
factorial value of a given number: 6

WRITE A C-PROGRAM TO FIND THE MULTIPLICATION OF TWO MATRICES OF SIZE M*P&P*N.

WRITE A C-PROGRAM TO FIND THE MULTIPLICATION OF TWO MATRICES OF SIZE M*P&P*N.
AIM:A program tofind the multiplication of the two matrices of size m*p,p*n.
PROGRAM:
#include<stdio.h>
main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,m,n,p;
printf("enter the values of m,n,p");
scanf("%d%d%d",&m,&n,&p);
printf("enter the elements of matrix a");
for(i=0;i<m;i++)
for(j=0;j<p;j++)
scanf("%d",&a[i][j]);
printf("enter the elements of matrix b");
for(i=0;i<p;i++)
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
c[i][j]=0;
for(k=0;k<p;k++)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
printf("the multiplication matrix is =%d",c[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
printf("%d",c[i][j]);
printf("\n");
}
}
OUTPUT:
enter the values of m,n,p
 2,2,2
enter the elements of matrix a
1 2 3 4
enter the elements of matrix b
1 0 0 1
the multiplication matrix is
1 2 3 4

WRITE A C-PROGRAM TO TEST THE GIVEN MATRIX IS SYMMETRIC (OR) NOT.

WRITE A C-PROGRAM TO TEST THE GIVEN MATRIX IS SYMMETRIC (OR) NOT.
AIM:A program to test the given matrix is symmetric (or) not
PROGRAM:
#include<stdio.h>
main()
{
int a[10][10],b[10][10],i,j,m,n;
printf("enter the values of m,n");
scanf("%d%d",&m,&n);
printf("enter the elements of matrix a");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i]][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
b[i][j]=a[j][i];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(a[i][j]==b[i][j])
printf("it is a symmetric matrix");
else
printf("it is not a symmetric matrix");
}
OUTPUT:
enter the values of m,n
2,2
enter the elements of matrix a
1 3 2 5
it is a symmetric matrix

WRITE A C-PROGRAM TO PRINT THE UPPER TRIANGLE,LOWER TRIANGLE&DIAGONAL SUMS.

WRITE A C-PROGRAM TO PRINT THE UPPER TRIANGLE,LOWER TRIANGLE&DIAGONAL SUMS.
AIM:A program to find the upper triangle,lower triangle,diagonal sums.
PROGRAM:
#include<stdio.h>
main()
{
int a[10][10],i,j,m,n,usum=0,lsum=0,dsum=0;
printf("enter the values of m,n");
scanf("%d%d",&m,&n);
printf("enter the elements of matrix a");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(i<j)
usum=usum+a[i][j];
else
if(i>j)
lsum=lsum+a[i][j];
else
if(i==j)
dsum=dsum+a[i][j];
printf("upper triangle sum=%d",usum);
printf("lower triangle sum=%d",lsum);
printf("diagonal sum=%d",dsum);
}
OUTPUT:
enter the values of m,n
3,3
enter the elements of matrix a
3 4 5
1 2 3
4 3 2
uppre triangle sum=
lower triangle sum=
diagonal sum=

WRITE A C-PROGRAM TO FIND THE BIGGEST&SMALLEST NUMBER OF THE GIVEN MATRIX.

WRITE A C-PROGRAM TO FIND THE BIGGEST&SMALLEST NUMBER OF THE GIVEN MATRIX.
AIM:A program to find the biggest and smallest number of a given matrix.
PROGRAM:
#include<stdio.h>
main()
{
int a[10][10],i,j,m,n,big,small;
printf("enter the values of m,n");
scanf("%d%d",&m,&n);
printf("enter the elemnts of matrix a");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
big=a[0][0];
small=a[0][0];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(a[i][j]>big)
big=a[i][j];
if(a[i][j]<small)
small=a[i][j];
printf("biggest element =%d",big);
printf("smallest element =%d",small);
}
OUTPUT:
enter the values of m,n
3,3
enter the elements of matrix a
1 2 3
3 4 5
5 6 7
biggest element 7
smallest element 1

WRITE A C-PROGRAM TO FIND THE TRACE OF A MATRIX OF SIZE M*N.

WRITE A C-PROGRAM TO FIND THE TRACE OF A MATRIX OF SIZE M*N.
AIM:A program to find the trace of a matrix of size m*n.
PROGRAM:
#include<stdio.h>
main()
{
int a[10][10],i,j,sum=0;
printf("enter the values of m,n");
scanf("%d%d",&m,&n);
printf("enter the elements of matrix a");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(i==j)
sum=sum+a[i][j];
printf("trace of a matrix=%d",sum);
}

OUTPUT:
enter the value of m,n
2,2
enter the elements of matrix a
1 2 3 4
trace of a matrix is

WRITE A C-PROGRAM TO FIND THE LOCATION OF THE REQUIRED ELEMENT.

 AIM:A program to find the location of the required element


PROGRAM:
#include<stdio.h>
main()
{
int i,n,a[100],m,x,f=0;
printf("enter the value of n");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the required element");
scanf("%d",&x);
for(i=0;i<n;i++)
{
if(a[i]==x)
{
m=i;
f++;
}
}
if(f==0)
printf("the required element is not found");
else
printf("the required element is found in the list and the position is%d",m);
}

OUTPUT:
enter the value of n
5
the required element is found in the list

WRITE A C-PROGRAM TO FIND THE STANDARD DEVIATION USING FUNCTIONS.

AIM:A program to find the standard deviation using functions.


PROGRAM:
#include<stdio.h>
main()
{
int n,x[100],s;
printf("enter the value of n");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&x[i]);
s=pas(x,n);
printf("standard deviation=%f",s);
}
pas(x,n)
{
int x[100],n;
int sum=0,vsum=0,i,k;
{
float mean,sd;
for(i=0;i<n;i++)
sum=sum+x[i];
mean=sum/n;
for(i=0;i<n;i++)
vsum=vsum+(x[i]-mean*x[i]-mean);
k=vsum/n;
sd=sqrt(k);
return(sd);
}
}

OUTPUT:
enter the value of n

WRITE A C-PROGRAM TO FIND THE VOWELS,CONSONANTS,DIGITS,OTHERS IA A LINE.

AIM:A program to find the vowels,constants,digits,others in a sentence.


PROGRAM:
#include<stdio.h>
main()
char line[80],c;
int i=v0w=cons=digit=wides=words=others=0;
printf("enter any string");
scanf("%s",line);
while((c==tolower(line[i++]!='\o'))
{
if((c=='a')||(c=='e')||(c=='i')||(c=='o')||(c=='u'))
++v=w;
else
if((c>='a')&&(c<='z'))
++cons;
else
if((c>='o')&&(c<='9'))
++digit;
else
if(c==' ')
{
++wides;
++words;
while((line[i++]==' ')||(line[i++]=='\+'))
{
++wides;
i++;
}
}
else
++others;
}
++words;
printf("vowels=%d\n");
printf("consonants=%d\n");
printf("digits=%d\n");
printf("wides=%d\n");
printf("words=%d\n");
printf("others=%d\n");
scanf("%d",vowels);
scanf("%d",consonants);
scanf("%d",digits);
scanf("%d",wides);
scanf("%d",words);
scanf("%d",others);
}

OUTPUT:
enter any string
pas college 123
vowels=a,e,o,e=4
consonants=6
digits=3
wides=2
words=2
others=1

WRITE A C-PROGRAM TO CONCATINATE ANY THREE STRINGS.

AIM:A program to concatinate any three strings.


PROGRAM:
#include<stdio.h>
main()
{
int i,j,k;
char a[20],b[20],c[20],d[20];
printf("enter the three strings");
scanf("%s%s%s",a,b,c);
for(i=0;a[i]!='\o';i++)
d[i]=a[i];
d[i]=' ';
for(j=0;b[j]!='\o';j++)
d[i+j+1]=b[j];
d[i+j+1]=' ';
for(k=0;c[k]!='\o';k++)
d[i+j+k+2]=c[k];
d[i+j+k+2]='\o';
printf("the new string is%d",d);
}

OUTPUT:
enter the three strings

the new string is

WRITE A C-PROGRAM TO TEST THE GIVEN STRING IS PALLIDROM (OR) NOT.

AIM:A program to test the given string is pallindrom (or) not.


PROGRAM:
#include<stdio.h>
main()
{
char a[30],c;
int i,j,l,f=0;
printf("enter any string");
scanf("%s",a);
for(l=0;a[l]!='\o';l++)
printf("%d",l);
for(i=0,j=l-1;i<l/2;i++,j--)
{
if(a[i]==a[j])
f=1;
}
if(f==1)
printf("it is a pallindrom");
else
printf("it is not a pallindrom");
}

OUTPUT:
enter any string
madam
it is a pallindrom
enter any string
sudha
it is not a pallindrom

WRITE A C-PROGRAM TO TEST THE GIVEN NUMBER IS PRIME NUMBER (OR) NOT USING FUNCTIONS.

AIM:Aprogram to test the given number is prime number (or) not using functions


PROGRAM:
#include<stdio.h>
main()
{
int n,k;
printf("enter the value of n");
scanf("%d",&n);
pas(n);
if(k==n)
printf("it is a prime number");
else
printf("it is not a prime number");
}
pas(n)
{
int n,k;
int i=1;
{
while(i<=n)
{
if(n%i==0)
i++;
k++;
}
}
}

OUTPUT:
enter the value of n
7
it is a prime number
enter the value of n
6
it is not a prime number

WRITE A C-PROGRAM TO TEST THE GIVEN NUMBER IS PALLINDROM (OR) NOT.

AIM:A program to test the given number is pallindrom (or) not.


PROGRAM:
#include<stdio.h>
main()
{
int n,rn=0,d,k;
printf("enter the value of n");
scanf("%d",&n);
k=rn;
while(n>0)
{
d=n%10;
rn=(rn*10)+d;
n=n/10;
}
if(k==rn)
printf("it is a pallindrom");
else
printf("it is not a pallindrom");
}

OUTPUT:
enter the value of n
121
it is a pallindrom
enter the value of n
456
it is not a pallindrom

WRITE A C-PROGRAM TO TEST THE GIVEN NUMBER IS ARMSTRONG NUMBER (OR) NOT.

AIM:a pragram to test the given number is an armstrong number(or) not.

PROGRAM:
#include<stdio.h>
main()
{
int i=1,n,sum=0,c,k;
printf("enter the value of n");
scanf("%d",&n);
k=n;
while(n>0)
{
d=n%10;
c=d*d*d;
sum=sum+c;
n=n/10;
}
if(sum==k)
printf("it is an armstrong number");
else
printf("it is not an armstrong number");
}

OUTPUT:
enter the value of n
153
it is an armstrong number
enter the value of n
23
it is not an armstrong number

WRITE A C-PROGRAM TO TEST THE GIVEN NUMBER IS PERFECT NUMBER (OR) NOT.

AIM:A program to test the given number is perfect number (or) not.
PROGRAM:
#include<stdio.h>
main()
{
int i,n,sum=0;
printf("enter the value of n");
scanf("%d",&n);
for(i=1;i<n-1;i++)
{
if(n%i==0)
sum=sum+i;
}
if(sum==n)
printf("it is a perfect number");
else
printf("it is not a perfect number");
}

OUTPUT:
enter the value of n
6
it is a perfect number
enter the value of n
1
it is not a perfect number

WRITE A C-PROGRAM TO PRINT THE FIBANOCCI SERIES.

AIM:A program to print the fibanocci series.
PROGRAM:
#include<stdio.h>
main()
{
int i,n,a=0,b=1,c;
printf("enter the value of n");
scanf("%d",&n);
while(i<=n)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
}
printf("%d",c);
printf("the fibanocci series is%d\n");
}
OUTPUT:
enter the value of n
4
the fibanocci series is 0,1,2,3

WRITE A PROGRAM TO ENTER ANY ARITHEMATIC OPERATOR TO PRINT THE CONCERN RESULT.

AIM:A program to enter any arithematic operator to print the concren result.
PROGRAM:
#include<stdio.h>
main()
{
int a,b;
char op;
printf("enter the values of a,b");
scanf("%d%d",&a,&b);
printf("enter arithematic operator");
scanf("%c",&op);
switch(op)
{
case '+':printf("a+b=%d",a+b);
               break;
case '-':printf("a-b+=%d",a-b);
             break;
case '*':printf("a*b=%d",a*b);
             break;
case '/':printf("a/b=%d",a/b);
             break;
default :printf("unknown arithematic operator");
}
OUTPUT:enter the values of a,b
1,2
enter arithematic operator
'+'
1+2=3.

WRITE A C-PROGRAM TO TEST THE STUDENT IS FIRST CLASS (OR) SECOND CLASS (OR) THIRD CLASS(OR) FAIL.

AIM:A program to test the student is passed with first class(or) second class(or) third class(or)the student is fail.
PROGRAM:
#include<stdio.h>
main()
{
int sno,m1,m2,m3,total;
printf("enter the values of sno,m1,m2,m3");
scanf("%d%d%d%d",&sno,&m1,&m2,&m3);
total=m1+m2+m3;
if((m1>=35)&&(m2>=35)&&(m3>=35)&&(total>=180))
printf("the student is passed with first class");
else
if((m1>35)&&(m2>35)&&(m3>=35)&&(total>=150)&&(total<=180))
printf("the student is passed with second class");
else
if((m1>=35)&&(m2>=35)&&(m3>=35)&&(total>=105)&&(total<=150))
printf("the student is passed with third class");
else
printf("the student is fail");
}
OUTPUT:
enter the values of sno,m1,m2,m3
408
78
60
50
the student is passed with first class

WRITE A C-PROGRAM TO FIND THE BIGGEST NUMBER AMONG THREE NUMBERS.

AIM:A program to find the biggest number among three numbers.
PROGRAM:
#include<stdio.h>
main()
{
int a,b,c,big;
printf("enter the values of a,b,c");
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(a>c))
big=a;
else
if((b>a)&&(b>c))
big=b;
else
big=c;
printf("biggest number=%d",big);
}
OUTPUT:
enter the values of a,b,c
2,3,4
biggest number =4.