Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 21

/* sum of digits */

#include<stdio.h>
#include<conio.h>
main()
{
int n,r,s=0;
clrscr();
printf(“\n enter n value ”);
scanf(“%d”,&n);
while(n!=0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf(“\n sum of the digits is %d”,s);
getch();
}
/* prime or composite */

#include<stdio.h>
#include<conio.h>
main()
{
int n,c=0,i;
clrscr();
printf(“\n enter a Number ”);
scanf(“%d”,&n);
if(n>1)
{
for(i=0;i<=n;i++)
{
if(n%i==0)
{
c=c+1;
}
if(c==2)
{
printf(“\n given number is prime ”);
}
else
{
printf(“\n given number is composite ”);
}
}
}
else
{
printf(“\n given number is not a prime and composit”);
}
getch();
}
/* Armstrong or Not */

#include<stdio.h>
#include<conio.h>
main()
{
int n,r,s=0,k;
clrscr();
printf(“\n enter a Number ”);
scanf(“%d”,&n);
k=n;
while(n!=0)
{
r=n%10;
s=s+(r*r*r*);
n=n/10;
}
if(k= =s)
{
printf(“\n given Number is Armstrong ”);
}
else
{
printf(“\n given Number is Not Armstrong ”);
}
getch();
}
/* Factorial of Given Number */

#include<stdio.h>
#include<conio.h>
main()
{
int n,f=1;
clrscr();
printf(“\n enter a Number ”);
scanf(“%d”,&n);
for(i=0;i<=n;i++)
{
f=f*i;
}
printf(“\n factorial of given number is %d ”,f);
getch();
}
/* Fibonacci series */

#include<stdio.h>
#include<conio.h>
main()
{
int f1=0,f2=1,f3,c=2;
clrscr();
printf(“\t %d \t %d”,f1,f2);
while(c<=10)
{
f3=f1+f2;
printf(\t %d”,f3);
f1=f2;
f2=f3;
c++;
}
getch();
}
/* Function with arguments no return type */

#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr();
printf(“\n enter a Value ”);
scanf(“%d”,&a);
printf(“\n enter b value ”);
scanf(“%d”,&b);
sum(a,b);
getch();
}
sum(int x,int y)
{
int z;
z=x+y;
Printf(“\n the sum is %d”,z);
}
/* Function with arguments with return type */

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf(“\n enter a Value ”);
scanf(“%d”,&a);
printf(“\n enter b value ”);
scanf(“%d”,&b);
c=sum(a,b);
Printf(“\n the sum is %d”,c);

getch();
}
sum(int x,int y)
{
int z;
z=x+y;
return z;
}
/* Find biggest and smallest element using array */

#include<stdio.h>
#include<conio.h>
main()
{
int a[9],s,l,i;
clrscr();
printf(“\n enter elements to an array ”);
for(i=0;i<9;i++)
{
scanf(“%d”,&n);
}
s=a[0];
printf(“\n smallest element is \n”);
for(i=0;i<9;i++)
{
if(a[i]<s)
s=a[i];
}
printf(“%d”,s);
printf(“\n the biggest element is \n”);
l=a[0];
for(i=0;i<9;i++)
{
if(a[i]>l)
l=a[i];
}
printf(“%d”,l);
getch();
}
/* Matrix addition */

#include<stdio.h>
#include<conio.h>
main()
{
int a[10][10],b[10][10],c[10][10],r1,r2,c1,c2,i,j;
clrscr();
printf(“\n enter the row size of the first matrix ”);
scanf(“%d”,r1);
printf(“\n enter the column size of the first matrix ”);
scanf(“%d”,c1);
printf(“\n enter the elements into the first matrix ”);
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
Printf(“\n enter the A[%d][%d]:”,i,j);
Scanf(“%d”,&a[i][j]);
}
}
printf(“\n enter the row size of the second matrix ”);
scanf(“%d”,r2);
printf(“\n enter the column size of the second matrix ”);
scanf(“%d”,c2);
printf(“\n enter the elements into the second matrix ”);
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf(“\n enter the B[%d][%d]:”,i,j);
scanf(“%d”,&b[i][j]);
}
}
Printf(“\n the first matrix is \n”);
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf(“ %d”,a[i][j]);
}
printf(“\n”);
}

Printf(“\n the second matrix is \n”);


for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf(“ %d”,b[i][j]);
}
printf(“\n”);
}

printf(“\n the matrix addition is \n”);


for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf(“ %d”,a[i][j]+b[i][j]);
}
printf(“\n”);
}
getch();
}
/* Matrix Substraction */

#include<stdio.h>
#include<conio.h>
main()
{
int a[10][10],b[10][10],c[10][10],r1,r2,c1,c2,i,j;
clrscr();
printf(“\n enter the row size of the first matrix ”);
scanf(“%d”,r1);
printf(“\n enter the column size of the first matrix ”);
scanf(“%d”,c1);
printf(“\n enter the elements into the first matrix ”);
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
Printf(“\n enter the A[%d][%d]:”,i,j);
Scanf(“%d”,&a[i][j]);
}
}
printf(“\n enter the row size of the second matrix ”);
scanf(“%d”,r2);
printf(“\n enter the column size of the second matrix ”);
scanf(“%d”,c2);
printf(“\n enter the elements into the second matrix ”);
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf(“\n enter the B[%d][%d]:”,i,j);
scanf(“%d”,&b[i][j]);
}
}

Printf(“\n the first matrix is \n”);


for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf(“ %d”,a[i][j]);
}
printf(“\n”);
}

Printf(“\n the second matrix is \n”);


for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf(“ %d”,b[i][j]);
}
printf(“\n”);
}

printf(“\n the matrix substraction is \n”);


for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf(“ %d”,a[i][j]-b[i][j]);
}
printf(“\n”);
}
getch();
}
/* Matrix Multiplication */

#include<stdio.h>
#include<conio.h>
main()
{
int a[10][10],b[10][10],c[10][10],r1,r2,c1,c2,i,j;
clrscr();
printf(“\n enter the row size of the first matrix ”);
scanf(“%d”,r1);
printf(“\n enter the column size of the first matrix ”);
scanf(“%d”,c1);
printf(“\n enter the elements into the first matrix ”);
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
Printf(“\n enter the A[%d][%d]:”,i,j);
Scanf(“%d”,&a[i][j]);
}
}
printf(“\n enter the row size of the second matrix ”);
scanf(“%d”,r2);
printf(“\n enter the column size of the second matrix ”);
scanf(“%d”,c2);
printf(“\n enter the elements into the second matrix ”);
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf(“\n enter the B[%d][%d]:”,i,j);
scanf(“%d”,&b[i][j]);
}
}
Printf(“\n the first matrix is \n”);
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf(“ %d”,a[i][j]);
}
printf(“\n”);
}

Printf(“\n the second matrix is \n”);


for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf(“ %d”,b[i][j]);
}
printf(“\n”);
}
If(c1= =r2)
{
printf(“\n the matrix multification is \n”);
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
C[i][j]=0;
For(k=0;k<c2;k++);
{
C[i][j]=c[i][j]+a[i][k]*b[k][j];
}
printf(“ %d”,c [i][j]);
}
printf(“\n”);
}
getch();
}
/*Transpose of a Matrix */

#include<stdio.h>
#include<conio.h>
main()
{
int a[10][10],r,c,i,j;
clrscr();
printf(“\n enter the row size of the matrix ”);
scanf(“%d”,r);
printf(“\n enter the column size of the matrix ”);
scanf(“%d”,c);
printf(“\n enter the elements into the matrix ”);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
Printf(“\n enter the A[%d][%d]:”,i,j);
Scanf(“%d”,&a[i][j]);
}
}
Printf(“\n the matrix is \n”);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf(“ %d”,a[i][j]);
}
printf(“\n”);
}
Printf(“\n the transpose matrix is \n”);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf(“ %d”,a[j][i]);
}
printf(“\n”);
}
/*Reverse of a Number*/

#include<stdio.h>
#include<conio.h>
main()
{
int n,r,t=0;
clrscr();
printf(“\n enter a Number ”);
scanf(“%d”,&n);
while(n!=0)
{
r=n%10;
t=t*10+r;
n=n/10;
}
printf(“\n the reverse number is %d”,t);
gtch();
}
/*Duplication string*/

#include<stdio.h>

#include<conio.h>

main()

Char t1[20],*t2;

Clrscr();

Printf(“\n enter a string”);

Scanf(“%s”,&t1);

t2=strdup(t1);

printf(“\n dublicate string is %s”,t2);

getch();

}
/*Converting upper&lower string*/

#include<stdio.h>

#include<conio.h>

main()

Char t[20];

Clrscr();

Printf(“\n enter a string”);

Scanf(“%s”,&t);

printf(“\n after converting upper string is %s”,strupr(t));

printf(“\n after converting lower string is %s”,strlwr(t));

getch();

You might also like