Académique Documents
Professionnel Documents
Culture Documents
h>
int main()
{
int n,i,j,temp,a[20];
printf("Enter the number of items to sort: ");
scanf("%d",&n);
printf("Enter the items to sort\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(j=1;j<n;j++)
{
for(i=0;i<n-j;i++)
{
if(a[i]>=a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
}
#include<stdio.h>
#define QUEUE_SIZE 5
int insert_rear(int item, int q[], int *r, int *count)
{
if(*count==QUEUE_SIZE)
{
printf("OVERFLOW");
return;
}
*r=(*r+1)%QUEUE_SIZE;
q[*r]=item;
*count+=1;
}
int delete_front(int q[], int *f, int *count)
{
if(*count==0)
{
printf("Underflow of queue\n");
return;
}
printf("The deleted item is %d\n",q[*f]);
*f=(*f+1)%QUEUE_SIZE;
*count-=1;
}
int display(int q[], int f, int count)
{
int i;
if(count==0)
{
printf("Queue is Empty\n");
return;
}
printf("Contents of Queue is\n");
for(i=1;i<=count;i++)
{
printf("%d\n",q[f]);
f=(f+1)%QUEUE_SIZE;
}
}
int main()
{
int choice, item, f,r,count,q[20];
f=0;
r=-1;
count=0;
for(;;)
{
printf("1:Insert 2:Delete\n");
printf("3:Display 4:Exit\n");
printf("Enter the Choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
}
}
#include<stdio.h>
int main()
{
int i,c=0;
char line[50];
printf("enter any line:\n");
gets(line);
if(line[0]==' ')
c=0;
else
c=1;
for(i=0;line[i]!='\0';i++)
{
if(line[i]==' '&& line[i+1]!=' ' &&line[i]!='\t')
c++;
}
printf("no .of words in aline=%d",c);
}
#include<stdio.h>
int main()
{
int a[10][10],b[10][10],m,n,i,j;
clrscr();
printf("Enter the order of matrix\n");
scanf("%d%d",&m,&n);
printf("\n Enter the elements of matrix");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
clrsccr();
printf("Entered Matrix is: \n");
for(i=0;i<m;i++)
{
printf("\n\n");
for(j=0;j<n;j++)
{
printf("%d ",a[i][j]);
}
}
printf("\n The transpose of the matrix is :");
for(i=0;i<m;i++)
{
printf("\n\n");
for(j=0;j<n;j++)
{
printf("%d ",a[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=a[i][j];
}
}
printf("The double transpose of a matrix is: \n");
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
printf("%d ",b[i][j]);
}
}
}
#include<stdio.h>
#inclde<conio.h>
int main()
{
int n,ncr,i,j;
n=2:wq0;
printf("enter no of countries:");
scanf("%d",&n);
ncr=n*(n-1)/2;
printf("there are %d countries playing football:%c2=%d
combinations\n",n,n,ncr);
for(i=1;;i<=n;i++)
{
for(j=n;j>i;j--)
printf("\A%d vs A%d",i,j);
printf("|n-------\n");
getch();
}
#include<stdio.h>
int main()
{
int i,v,p,l[100],n,k,t,j;
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&n);
}
for(i=1;i<=n;i++)
{
scanf("%d",&l[i]);
}
printf("\n enter list as follows");
for(i=1;i<=n;i++)
{
printf("\t%d",l[i]);
}
for(k=2;k<=n;k++)
{
i=k;
t=l[k];
j=i/2;
while((i>1)&&(t>l[j]))
{
l[i]=l[j];
i=j;
j=i/2;
if(j<1)
j=1;
}
l[i]=t;
}
printf("\n HEAP");
for(i=1;i<=n;i++)
{
printf("\t%d",l[i]);
}
printf("\n");
for(k=n;k>=2;k++)
{
t=l[1];
l[1]=l[k];
l[k]=t;
i=1;
v=l[1];
j=2;
if((j+1)<(k))
if(l[j+1]>l[j])
j++;
while((j<=(k-1))&&(l[j]>v))
{
l[i]=l[j];
i=j;
j=2*i;
if((j+1)<k)
if(l[j+1]>l[j])
j++;
else
if(j>n)
j=n;
l[i]=v;
}
for(p=1;p<=n;p++)
{
printf("\t%d",l[p]);
}
printf("\n");
}
printf("\n sorted list");
for(i=1;i<=n;i++)
{
printf("\t%d",l[i]);
}
}
#include<stdio.h>
int main()
{
int a[20],n,temp,i,j;
printf("\n\n\t Enter the number of terms...:");
scanf("%d",&n);
printf("\n Enter the elements of the array");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=1;i<n;i++)
{
temp=a[i];
j=i-1;
while(temp<a[j]&&j>=0)
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=temp;
}
printf("\n The Sorted list is: ");
for(i=0;i<n;i++)
printf("\n%d",a[i]);
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *a,*r;
int n,i,rtop=-1;
printf("enter no.of elements:");
scanf("%d",&n);
a=(int *)calloc(n,sizeof(int));
r=(int *)calloc(n,sizeof(int));
if(a==NULL ||r==NULL)
{
printf("Insufficient Memory");
exit(0);
printf("please enter %d elements\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
for(i=n-1;i>=0;i--)
{
rtop++;r[top]=a[i];
printf("\n given elements are");
for(i=0;i<n;i++)
{
printf("%d",a[i]);
}
printf("\n Reversed Elements are:");
for(i=0;i<=rtop;i++)
{
printf("%d",r[i]);
}
#include<stdio.h>
int main()
{
int p1[50],p2[50],p3[50],n1,n2,i,t;
printf("\n enter highest powr/exponential in polynomial p1:");
scanf("%d",&n1);
printf("\n enter highest power/exponential in polynomial p2:");
scanf("%d",&n2);
if(n1>=n2)
t=n1;
else
t=n2;
for(i=n1;i>=0;i--)
{
printf("\nenter the co efficient of %d element for p1:",i);
scanf("%d",&p1[i]);
}
for(i=n2;i>=0;i--)
{
printf("\n enter the co efficient of %d element for p2:",i);
scanf("%d",&p2[i]);
}
for(i=t;i>=0;i--)
{
p3[i]=p1[i]+p2[i];
}
for(i=t;i>=0;i--)
{
printf("%dX^%d+",p1[i],i);
}
printf("\n");
for(i=t;i>=0;i--)
{
printf("%dX^%d+",p2[i],i);
}
printf("polynomial p1 is:\n");
for(i=t;i>=0;i--)
{
if(i>0)
printf("%dX^%d+",p1[i],i);
else
printf("%dX^%d+",p1[i],i);
}
printf("\n polynomial p2 is:\n");
for(i=t;i>=0;i--)
{
if(i>0)
printf("%dX^%d+",p2[i],i);
else
printf("%dX^%d+",p2[i],i);
}
printf("\n\n");
printf("sum of polynomial p1 & p2 is:\n");
for(i=t;i>=0;i--)
{
if(i>0)
printf("%dX^%d+",p3[i],i);
else
printf("%dX^%d+",p3[i],i);
}
#include<stdio.h>
#include<string.h>
float s[10],op1,op2;
int top=-1;
push(postfix[i]-'0');
else if(isalpha(postfix[i]))
{
printf("Enter value of %c",postfix[i]);
scanf("%f",&val);push(val);
}
else
{
op1=pop();op2=pop();sym=postfix[i];
res=compute(sym,op1,op2);push(res);
}
}
printf("value of the expression is :%f",POP());
}