Basic C Programs
Basic C Programs
Search
void main()
{
int a[10][10],b[10][10],c[10][10];
int i,j,k,r1,c1,r2,c2;
clrscr();
printf("\n how many rows n columns are in matrix a");
scanf("%d%d",&r1,&c1);
printf("\n Enter the elements of matrix a");
for(i=0;i <>
{
for(j=0;j<> { <>
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("\n how many rows n columns are in matrix b");
scanf("%d%d",&r2,&c2);
printf("\n Enter the elemnts of matrix b");
for(i=0;i {
for(j=0;j {
scanf("%d",&b[i][j]);
}
printf("\n");
}
if(c1!=r2)
{
printf("\n matrix mul is nt possible");
exit();
}
printf("\n result is :\n");
for(i=0;i<> {
for(j=0;j<> {
c[i][j]=0;
for(k=0;k <>
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}//for k
}
}
printf("\n result is \n");
for(i=0;i<>
{
for(j=0;j<>
{
printf("\t%d",c[i][j]);
}
printf("\n");
}
<>
<>
<><><>
<>
void main()
{
int a[10],front,rear,item,ch,i;
clrscr();
front=-1;
rear=-1;
while(1)
{
printf("\n\t\t****MENU****\n");
printf("\n 1.Insert\n 2.Delete\n 3.Display \n 4.Exit");
printf("\n\n Enter your Choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(rear==9)
{
printf("\nQueue is full\n");
}
else
{
rear=rear+1;
printf("\n Enter the item you want to insert:");
scanf("%d",&item);
a[rear]=item;
}
break;
case 2:
if(front==rear)
{
printf("\n queue is empty\n");
}
else
{
front++;
printf("\n Deleted:%d",a[front]);
break;
case 3:
for(i=front+1;i<=rear;i++)
{
printf("\n %d",a[i]);
}
break;
case 4:
exit();
}//switch
}//while
}//main
void main()
{
char str[40];
int i,flag=0,len;
clrscr();
printf("\n Enter A string : ");
gets(str);
len=strlen(str);
for(i=0;i<(len/2);i++)
{
if(str[i]!=str[len-1-i])
{
flag=1;
break;
}
}
if(flag==1)
{
printf(" \n The string is not palindrome");
}
if(flag==0)
printf("\n String is palindrome");
getch();
}
void main()
{
char main_str[40],str[40];
int i,j,len1,len2;
clrscr();
printf("\n Enter the main String :");
gets(main_str);
printf("\n enter the String you wanna search : ");
gets(str);
len1=strlen(main_str);
len2=strlen(str);
i=0;
j=0;
while(str[i]!='\0')
{
while(main_str[j]!='\0')
{
if(str[i]==main_str[j])
{
i++;
if(len2==i)
{
j=j-len2+2;
printf("\n found at %d location",j);
break;
}
}//if
else
j++;
}//inner while
if(j==len1)
{
printf("\n not Found");
break;
}//if
}//outer while
getch();
}
void main()
{
int a,b;
clrscr();
printf("\n enter First Number :");
scanf("%d",&a);
printf("\n enter Second Number :");
scanf("%d",&b);
swap(&a,&b);
printf("\n first Number is : %d",a);
printf("\n second Number is : %d",b);
getch();
}
0 comments
int a[10],top;
void main()
{
int ch;
clrscr();
top=-1;
while(1)
{
printf("\n\t\t****MENU****\n");
printf("\n 1.Push\n 2.Pop\n 3.Display \n 4.Exit");
printf("\n\n Enter your Choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
exit();
}//switch
}//while
}
push()
{
int item;
printf("\n enter The Number You want to push :");
scanf("%d",&item);
if(top==9)
{
printf("\n overflow-You can't push");
}
else
{
top=top+1;
a[top]=item;
}
}//push
pop()
{
int item;
if(top<0) item="a[top];" top="top-1;" i="top;i">=0;i--)
{
printf("\n %d",a[i]);
}
}//display
0 comments
Blog Archive
▼ 2009 (6)
o ▼ July (2)
Program to do Matrix Multiplication
Program to implement Operations of Queue
o ► June (4)
Program to check whether a string is palindrome or...
Program to search One String in Another String
Program to swap two numbers without using 3rd vari...
Program to implement stack operations
Labels
Array (2)
String (2)
Followers
About Me
Ishani Goel
Ambala City, Haryana, India
View my complete profile
Blogger Templates