Beruflich Dokumente
Kultur Dokumente
PROGRAM :1
# include<stdio.h>
#include<conio.h>
main()
{ clrscr();
int m1[2][2],m2[2][2],m3[2][2],i,j,k,sum;
printf("Enter element of FIRST 2X2 Matrix :");
for(i=0;i<2;i++)
{ for(j=0;j<2;j++)
{ printf("%d,%d Element:-",i,j);
scanf("%d",&m1[i][j]);
}
}
printf("Enter element of SECOND 2X2 Matrix :");
for(i=0;i<2;i++)
{ for(j=0;j<2;j++)
{ printf("%d,%d Element:-",i,j);
scanf("%d",&m2[i][j]);
}
}
for(i=0;i<2;i++)
{ for(j=0;j<2;j++)
{ sum=0;
for(k=0; k<2; k++)
{sum=sum+m1[i][k]*m2[k][j];
}
m3[i][j]=sum;
}
}
printf("\n\nPRINTING OF THIRD MATRIX\n\n");
for(i=0;i<2;i++)
{ for(j=0;j<2;j++)
{
printf("\t%d",m3[i][j]);
}
printf("\n");
getch();
}
PROGRAM :2
#include<stdio.h>
#include<conio.h>
main()
{ clrscr();
int a[5],i,j,pos,ele;
for(i=0;i<4;i++)
{ printf("Enter %d Element :-",i+1);
scanf("%d",&a[i]);
}
printf("\n\nEnter position where to insert element :-");
scanf("%d",&pos);
printf("Enter the value of element :- ");
scanf("%d",&ele);
for(i=5; i>pos-1;i--)
{a[i]=a[i-1];
}
a[pos-1]=ele;
printf("\n\n PRINTING OF RESULT ARRAY");
for(i=0;i<5;i++)
{ printf("\n %d",a[i]);
getch();
}
PROGRAM :3
#include<stdio.h>
#include<conio.h>
main()
{ clrscr();
int a[5],i,j,pos;
for(i=0;i<5;i++)
{
printf("Enter %d Element :-",i+1);
scanf("%d",&a[i]);
}
printf("\n\nEnter position where to delete element :-");
scanf("%d",&pos);
for(i=pos-1; i<5;i++)
{a[i]=a[i+1];
}
printf("\n\n PRINTING OF RESULT ARRAY");
for(i=0;i<5;i++)
{ printf("\n %d",a[i]);
getch();
}
PROGRAM :4
/* ARRAY SORTING */
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a[5],i,j,temp;
for(i=0;i<5;i++)
{ printf("Enter %d Element :-",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<5;i++)
{ for(j=i+1;j<5;j++)
{ if(a[j]<a[i])
{ temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
getch();
}
PROGRAM :5
PROGRAM :7
getch();
}
IMPORTANT PROGRAMS OF STRING
PROGRAM :1
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
clrscr();
char str1[50],str2[50],str3[50],i,j;
printf("Enter First String :-");
gets(str1);
printf("Enter Second String :-");
gets(str2);
for(i=0;str1[i]!=NULL;i++)
{
str3[i]=str1[i];
}
str3[i]=' ';
j=i+1;
for(i=0;str2[i]!=NULL;i++)
{
str3[j]=str2[i];
j++;
}
str3[j]=NULL;
printf("\n\nRESULT STRING\n\n");
puts(str3);
getch();
}
PROGRAM :2
PROGRAM :3
/* String Comparision */
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
clrscr();
char a[50],b[50];
int i,count1,count2,f=0;
printf("Enter First String:-");
gets(a);
printf("Enter Second String:-");
gets(b);
count1=strlen(a);
count2=strlen(b);
for(i=0;i<count1;i++)
{ if((count1!=count2)||(a[i]!=b[i]))
{ f=1;
break;
}
}
if(f==0)
{ printf("String are Same.");
}
else
{ printf("String are not Same.");
}
getch();
}