Académique Documents
Professionnel Documents
Culture Documents
INDEX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
*
*
*
**
35
1
12
1
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
123
1234
2
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
36
1
22
333
4444
37
1
23
345
4567
38
1
2
3 3
4 4
5 5
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
3
4 4
5 5 5
write a program
write a program
write a program
write a program
write a program
write a program
write a program
write a program
matrix
write a program
write a program
write a program
write a program
write a program
write a program
write a program
write a program
write a program
write a program
write a program
write a program
write a program
write a program
write a program
write a program
write a program
C $ DS MANUAL
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
4
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
5
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
C $ DS MANUAL
c=a*b;
printf("the multiplication of a,b is %d",c);
c=a/b;
printf(the result of a/b is %d",c);
c=a%b;
printf("thr result is %d",c);
}
C $ DS MANUAL
C $ DS MANUAL
C $ DS MANUAL
if(b>c)
printf("the largest no. is %d",b);
else
printf("the largest no. is %d",c);
}
}
C $ DS MANUAL
printf("Equation is possible\n\a");
disc=(b*b)-(4*a*c);
if(disc==0)
{
printf("Roots are real and equal\n\a");
root=-b/(2*a);
printf("Roots are %f and %f\n\a",root,root);
}
else if(disc>0)
{
printf("Roots are real\n\a");
root1=(-b+sqrt(disc))/(2*a);
root2=(-b-sqrt(disc))/(2*a);
printf("Roots are %f and%f\n\a",root1,root2);
}
else
{
printf("Roots are complex\n\a");
rp=-b/2*a;
ip=sqrt((fabs)(disc))/2*a;
11
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
C $ DS MANUAL
C $ DS MANUAL
case 'e:'
case 'i':
case 'o':
case 'u'printf"(it is vowel");
break;
default:printf(it is consonant");
}
}
C $ DS MANUAL
while(n!=0)
{
r=n%10;
rev=rev*10+r;
n=n/0;
}
printf("the reverse is %d",rev);
}
C $ DS MANUAL
C $ DS MANUAL
nr=a;
dr=b;
}
else
{
nr=b;
dr=a;
}
r=nr%dr;
while(r!=0)
{
nr=dr;
dr=r;
r=nr%dr;
}
lcm=(a*b)/dr;
printf("GCD of %d & %d = %d\n",a,b,dr);
printf("LCM of %d & %d = %d\n",a,b,lcm)
}
C $ DS MANUAL
C $ DS MANUAL
for(i=1;i<=n;i++)
{
for(j=1;j<=1;j++)
printf("%c",'*');
printf("\n");
}
}
22
333
4444
#include<stdio.h>
main()
{
int n,i,j;
printf("how many rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=1;j++)
printf("%d",i);
printf("\n");
19
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
}
}
print format
3
4
5 5
#include<stdio.h>
main()
{
int n,i,j;
printf("how many rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=i;k<n;k++)
printf(" ");
for(j=1;j<=i;j++)
printf("%d"i);
printf("\n");
}
}
20
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
C $ DS MANUAL
43. WAP TO READ & PRINT THE TWO DIM ARRAY VALUES
#include<stdio.h>
void main()_
{
int a[2][3],i,j;
printf(\n enter the elements );
for(i=0;i<2;i++)
for(j=0;j<3;j++)
{
scanf(%d,&a[i][j]);
}
printf(\n the elements in array );
for(i=0;i<2;i++)
for(j=0;j<3;j++)
22
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
{
printf(%d,a[i][j]);
}
printf(\n);
}
23
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
}
printf(\n);
}
}
C $ DS MANUAL
int a[3][3],b[3][3],c[3][3],k;
printf(\n enter elements in matrix a);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
scanf(%d,&a[i][j]);
}
printf(enter the elements in matrix b);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
scanf(%d,&b[i][j]);
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
c[i][j]=c[i][j]+(a[i][j]*b[i][j]);
}
printf(\n enter the resultant matrix is );
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
printf(%3d,c[i][j]);
}
printf(\n);
}
C $ DS MANUAL
C $ DS MANUAL
b[i][j]=a[i][j];
}
}
printf("transpose of a given matrix is :\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%5d",b[i][j]);
printf("\n");
}
}
for(i=0;i<n;i++)
{
for9j=0;j<n;j++)
if(a[i][j]!=b[i][])
flag=1;
}
if(flag)
printf("\n matrix is not symmetric\n");
else
printf("\n matrix is symmetric");
}
C $ DS MANUAL
}
printf("\n");
}
}
C $ DS MANUAL
}
if(f==0)
printf("strrngs are equal");
else
printf("strings are not equal");
}
C $ DS MANUAL
i++;
j--;
}
if(palin==1)
printf("%s is a palindrome\n\a",palin);
else
printf("%s is not a palindrome\n\a");
C $ DS MANUAL
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
}
printf("after sorting");
for(i=0;i<5;i++)
{
printf("%s\n",str[i]);
}
}
C $ DS MANUAL
main()
{
square();
}
suqare()
{
int n,m;
ptintf("enter n");
scanf("%d",&n);
m=n*n;
printf("%d",m);
}
b. arguments with no return values
#include<stdio.h>
main()
{
int n;
printf("enter n");
scanf("%d",&n);
square(n);
}
square(int x)
{
iny y;
y=x*x;
printf("%d",y);
}
C $ DS MANUAL
int y;
y=x*x;
return y;
}
C $ DS MANUAL
printf("%d\n",m);
}
C $ DS MANUAL
C $ DS MANUAL
int temp;
temp=*x;
*x=*y;
*y=temp;
}
C $ DS MANUAL
C $ DS MANUAL
for(i=0;i<r;i++)
for(j=0;j<c;j++)
t=*(*(b+i)+j);
*(*(b+i)+j)=*(*(b+j)+i);
*(*(b+j)+i)=t;
}
print(int (*y)[3],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
for(j=0;J,c;j++)
{
printf("%d",*(*(y+i)+j);
printf("\n");
}
}
C $ DS MANUAL
printf("a=%d,b=%d\n",a,b);
printf("x=%d,y=%d\n",x,y);
*p2=*p2+3;
*p1=*p2-5;
z=(*p2)/(*p1);
printf("a=%d,b=%d\n",a,b);
printf("z=%d",z);
}
C $ DS MANUAL
C $ DS MANUAL
{
char *name[20];
int number;
float price;
};
main()
{
struct invent product[3],*ptr;
printf("INPUT\n\n");
for(*ptr=product;ptr<product+3;ptr++)
scanf("%fs%d%f",ptr->name,&ptr->number,&ptr->price);
printf("\nOUTPUT");
ptr=product;
while(ptr<product+3)
{
printf(%-20s%5d%10.2f\n");
ptr->name;
ptr->number;
ptr->price;
ptr++;
}
}
C $ DS MANUAL
#include<stdio.h>
main()
{
FILE *fp;
charx[10],c[10];
int fee;
fp=fopen("student","w");
for(i=1;i<=3;i++)
{
printf("enter name course,fee");
scanf("%s%s%d",n,c,&f);
fprintf("fp,"%s%s%d\n",n,c,f);
}
fclose(fp);
}
C $ DS MANUAL
{
fputc(ch,fp);
}
fclose(fp);
}
C $ DS MANUAL
C $ DS MANUAL
fp=fopen("i1.c","r");
fseek(fp,40L,0);
while((ch=fgetc(fp))!=EOF)
{
printf("%c",ch);
delay(30);
}
printf("Total size : %ld\n",ftell(fp));
rewind(fp);
printf("Position : %ld\n",ftell(fp));
while((ch=fgetc(fp))!=EOF)
{
printf("%c",ch);
delay(30);
}
getch();
C $ DS MANUAL
{
printf("cannot open the file\n");
printf("type file name again\n\n");
goto oepn_file;
}
else
for(i=1;i<=20;i++)
{
number=getw(fp2);
if(feof(fp2))
{
printf("\n ran out of dat\n");
break;
}
else
printf("%d\n",number);
}
flcose(fp2);
}
C $ DS MANUAL
printf("\n\n");
for(i=0;i<agrc;i++)
printf("%s\n",i*5,argv[i]);
}
47
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
void main()
{
int *p,n,*temp;
clrscr();
printf("Enter no of elements to be allocated\n");
scanf("%d",&n);
p=(int*)malloc(n*sizeof(int));
temp=p;
for(i=0;i<n;i++)
{
printf("Element%d Address : %u",temp+i);
}
getch();
}
C $ DS MANUAL
int n,i;
clrscr();
printf("Enter No of Students : ");
scanf("%d",&n);
s1=(struct student*)calloc(n,sizeof(struct student));
temp=s1;
for(i=0;i<n;i++)
{
temp=s1;
printf("\t\tNumber\t\tName\t\tMarks1\n");
for(i=0;i<n;i++)
{
printf("Student %d : ",i+1);
printf(" %d ",(temp+i)->stno);
printf(" \t\t %s ",(temp+i)->name);
printf(" \t\t %d \n",(temp+i)->marks1);
}
temp=s1;
for(i=0;i<n;i++)
{
printf("Structure%d Address is %u \n",i+1,temp+i);
}
printf("enter the student num : ");
49
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
scanf("%d",&i);
temp=s1;
C $ DS MANUAL
}
}
void push()
{
int n;
if(top>=MAX)
printf("stack i already full,can't add more items\n");
else
{
printf("enter the item");
scanf("%d",&n);
stack[top]=n;
top++;
}
}
void pop()
{
if(top<0)
{
printf("stack is already empty");
}
else
top--;
}
void display()
{
int i;
for(i=0;i<top;i++)
{
printf("%d",stack[i]);
}
}
C $ DS MANUAL
return(s->top==-1);
C $ DS MANUAL
scanf("%d",&value);
push(value,&s);
break;
case 2:pop(&s);
break;
case 3:value=top(&s);
printf("the top element of stack i %d\n",value);
break;
case 4:if(!isempty(&s))
printf("stack is not empty\n");
else
printf("stack is empty\n");
break;
case 5:printf("the elements of stack are\n");
display(&s);
break;
case 6:exit(0);
}
menu();
printf("enter u r chioce\n");
scanf("%d",&chioce);
}
}
main()
{
int choice;
while(1)
{
printf("1.add new item\n");
printf("2.delete a item\n");
53
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
printf("3.dispaly\n");
printf("4.exit\n");
printf("enter u r choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1: add_q();
break;
case 2:delete_q();
break;
case 3:print_q();
break;
case 4:exit(0);
}
}
}
void add_q()
{
int item;
if(rear==MAXSIZE-1)
printf("queue is full,can't add new item\n");
else
{
printf("enter an item\n");
scanf("%d",&item);
if(front==-1)
front=0;
rear++;
queue[rear]=item;
}
}
int delete_q()
{
if(front==rear)
{
printf("queue is empty\n");
front=-1;
rear=-1;
}
else
front++;
}
void print_q()
54
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
{
int i;
if(front==rear)
printf("queue is empty\n");
else
{
for(i=front;i<=rear;i++)
printf("-->%d",queue[i]);
}
printf("\n");
}
void main()
{
int value,ch;
char choice;
clrscr();
do
{
55
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
printf("\n\t\t----1. add\n");
printf("\n\t\t----2. delete\n");
printf("\n\t\t----3. traverse\n");
printf("\n\t\t----4. exit\n");
printf("\n\t\tEnter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1: add();
break;
case 2: del();
break;
case 3: traverse();
break;
case 4: return;
default : printf("\nwrong choice\n");
};
}
while(choice!=4);
scanf("%c",&choice);
}
void add()
{
struct queue *p,*temp;
temp=start;
p=(struct queue*)malloc(sizeof(struct queue));
printf("Enter the data : ");
scanf("%d",&p->no);
p->next=NULL;
if(start==NULL)
{
start=p;
}
else
{
while(temp->next!=NULL)
{
temp=temp->next;
56
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
}
temp->next=p;
}
}
void del()
{
struct queue *temp;
int value;
if(start==NULL)
{
printf("\nqueue is empty\n");
getch();
//return(0);
}
else
{
temp=start;
value=temp->no;
start=start->next;
printf("\nthe deleted element is %d ",value);
free(temp);
}
//return(value);
}
void traverse()
{
struct queue *temp;
temp=start;
if(temp!=NULL)
{
while(temp->next!=NULL)
{
printf("\n no= %d",temp->no);
temp=temp->next;
}
printf("\n no= %d ",temp->no);
57
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
}
else
{
printf("QUE is empty"
);
}
getch();
}
C $ DS MANUAL
{
int j=0;
float opA,opB,res;
char ch;
while(postfix[j]!='\0')
{
ch=postfix[j];
if(isalpha(postfix[j]))
{
push(data[j]);
}
else
{
opB=pop();
opA=pop();
switch(ch)
{
case '+':push(opA+opB);
break;
case '-':push(opA-opB);
break;
case'*':push(opA*opB);
break;
case'/':push(opA/opB);
break;
case'^':push(pow(opA,opB));
break;
}
}
j++;
}
res=pop();
return(res);
}
void push(char c)
{
top=top+1;
stack[top]=c;
}
float pop()
{
float n;
59
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
n=stack[top];
top=top-1;
return(n);}
C $ DS MANUAL
for(i=0;infix[i]!='\0';i++)
{
if(infix[i]=='(')
push(infix[i]);
else if(infix[i]==')')
{
while(stack[top]!='(')
postfix[j++]=pop();
pop();
}
else if(infix[i]>=97&&infix[i]<=122)
postfix[j++]=infix[i];
else
{
if((priority(stack[top])<priority(infix[i])||top==-1))
push(infix[i]);
else
postfix[j++]=pop();
}
}
while(top>=0)
postfix[j++]=pop();
postfix[j]='\0';
printf("postfix expresion is %s",postfix);
}
C $ DS MANUAL
void out()
{
printf("\nADJECENCY MATRIX FOR THE GRAPH IS \n\n");
for(i=0;i<num;i++)
printf("%c",(char)179);
for(j=0;j<num;j++)
printf(" %d ",graph[i][j]);
printf("%c\n",(char)179);
}
62
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
for(i=0;i<num;i++)
for(j=i;j<num;j++)
{
span[i][j]=0;
if((c[i]!=c[j])&&(graph[i][j]!=0))
{
span[i][j]=graph[i][j];
if(c[i]<c[j])
c[j]=c[i];
else
c[i]=c[j];
}
span[j][i]=span[i][j];
C $ DS MANUAL
getch();
C $ DS MANUAL
int a[34],first,last,mid,n,key,i,pos=0;
clrscr();
printf("Enter no of digits:\n\a");
scanf("%d",&n);
printf("Enter the elements one by one\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("The key element to be searched\n");
scanf("%d",&key);
printf("\nArray after sorting\n");
for(i=0;i<n;i++)
printf("%4d",a[i]);
first=0;
last=n-1;
while(first<=last)
{
mid=(first+last)/2;
if(a[mid]<key)
last=mid-1;
else if(a[mid]>key)
first=mid+1;
else
{
pos=mid;
break;
}
}
if(a[mid]==key)
printf("\n Element found at location %d\n\a",pos);
else
printf("\nElement not found\n\a");
getch();
C $ DS MANUAL
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,a[30],temp;
clrscr();
printf("Enter how many digits?\n\a");
scanf("%d",&n);
printf("Enter the numbers one by one\n\a");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nThe array before sorting\n\a");
for(i=0;i<n;i++)
printf("%4d",a[i]);
/*bub now*/
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
printf("\nThe array after sorting\n\a");
for(i=0;i<n;i++)
printf("%4d",a[i]);
getch();
}
#include<stdio.h>
66
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
#include<stdlib.h>
#include<conio.h>
void main()
{
int i,n,a[45],pos;
clrscr();
printf("\nEnter how many elements\n");
scanf("%d",&n);
printf("\nEnter the numbers one by one\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nThe given array is\n");
for(i=0;i<n;i++)
printf("%4d",a[i]);
for(i=0;i<n-1;i++)
{
pos=min_ele(a,n,i);
exchange(a,i,pos);
}
printf("\nArray after sorting\n");
for(i=0;i<n;i++)
printf("%4d",a[i]);
getch();
}
min_ele(int a[ ],int n,int i)
{
int pos,j;
pos=i;
for(j=i+1;j<n;j++)
if(a[pos]>a[j])
pos=j;
return(pos);
}
C $ DS MANUAL
temp=a[i];
a[i]=a[pos];
a[pos]=temp;
return;
}
C $ DS MANUAL
{
elements[left]=elements[right];
left++;
}
while((elements[left]<=pivot)&&(left<right))
left++;
if(left!=right)
{
elements[right]=elements[left]);
right--;
}
}
elements[left]=pivot;
Pivot=left;
left=l;
right=r;
if(left<pivot)
sort(elements,left,pivot-1);
if(right>pivot)
sort(elements,pivot+1,right);
}
C $ DS MANUAL
printf([%i],elemnets[i]);
printf(\n\n);
insertionsort(elements,int maxsize);
printf(\n Array after sorting:\n);
for(i=0;i<maxsize;i++)
printf([%i],elements[i]);
}
Void insertionsort(int elements[],int maxsize)
{
int i,j,index;
for(i=1;i<maxsize;i++)
{
index=elements[i];
j=i;
while(j>0)&&(elemnts[j-1]>index))
{
elements[j]=elements[j-1];
j=j-1;
}
Elements[j]=index;
}
}
}
void heap_sort(int a[],int n)
70
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA
C $ DS MANUAL
{
int i,temp;
build_heap(a,n);
for(i=n;i>=2;i--)
{
temp=a[i];
a[i]=a[1];
a[1]=temp;
build_heap(a,n);
}
}
int main()
int a[6],i;
printf("enter values\n");
for(i=1;i<=5;i++)
scanf("%d",&a[i]);
heap_sort(a,5);
for(i=1;i<=5;i++)
printf("%d ",a[i]);
return 0;
}
71
SVS GROUP OF INSTITUTIONS
BHEEMARAM,HANAMKONDA