Friday, January 25, 2008

find armstrong numbr

/* pgr t o find armstrong numbr
written by sekhar
written on 28/08/07
*/
#include
#include
main()
{
int x,value,z,y=0;
scanf("%d",&value);
z=value;
while(z!=0)
{

x=z%10;
y=(x*x*x)+y;
z=z/10;
}
if(y==value)
printf("given no is amstrong number");
}

linked lists in data structures

/*pgr to use to linked lists in data structures
written by sekhar
written on 22/07/08 */

#include
typedef struct linkedlist
{
int rollno;
char name[20];
int marks;
char remarks[20];
struct linkedlist *next;
}stu_t;
stu_t *insert(stu_t *);
void *display(stu_t *);
main()
{
int option,status;
stu_t *head;
head=(stu_t *)malloc(sizeof(stu_t));

while(1)
{
puts("enter the option 1: insert 2:delete 3:update 4:sort 5:display 6:search 7:exit");
scanf("%d",&option);
switch(option)
{
case 1:
head=insert(head);
/* if(status==0)
printf("operation is success");
else
printf("operation is denied");*/
break;

case 5:
display(head);
break;

case 6:
exit();
}
}
}
stu_t *insert(stu_t *head)
{
int option,b4number;
char value='y';
stu_t *new,*temp,*list;
list=head;
temp=head;
puts("enter the option 1:bottom 2:middle 3:top");
scanf("%d",&option);
switch(option)
{
case 1:
while(value=='y')
{
printf("enter the details");
scanf("%d%s%d%s",&list->rollno,list->name,&list->marks,list->remarks); new=(stu_t *)malloc(sizeof(stu_t));
list->next=new;
list=new;
puts("enter the option you want to add another record y:yes n:no");
__fpurge(stdin);
scanf("%c",&value);
}
if(value!='y')
list->next=0;
return head;

case 2:
while(value=='y')
{
puts("enter the position where u want to enter");
scanf("%d",&b4number);
puts("enter the new fields");
new=(stu_t *)malloc(sizeof(stu_t));
scanf("%d%s%d%s",&new->rollno,new->name,&new->marks,new->remarks);
while(temp->next)
{
if(temp->rollno==b4number)
{
new->next=temp->next;
temp->next=new;
}
temp=temp->next;
}
puts("if you want ot add another option please press 'y'");
__fpurge(stdin);
scanf("%c",&value);
}

case 3:
while(value=='y')
{
puts("enter the fields");
new=(stu_t *)malloc(sizeof(stu_t));
scanf("%d%s%d%s",&new->rollno,new->name,&new->marks,new->remarks);
new->next=head;
head=new;
puts("if you want ot add another option please press 'y'");
__fpurge(stdin);
scanf("%c",&value);
}
return head;

}
}


void *display(stu_t *head)
{
while(head->next!=0)
{
printf("%d\t%s\t%d\t%s\n",head->rollno,head->name,head->marks,head->remarks);
head=head->next;
}
}

linked list operation basic program

/* pgr to write linked list operation in the linked list
written by sekhar
written on 21/08/07
modified on 21/08/07 */

#include
//#include
typedef struct linkedlist
{
int number;
struct linkedlist *next;
}num_t;

void create(num_t *);
void print(num_t *);
num_t *insert(num_t *);
num_t *find(num_t *,int);
main()
{
num_t *head;
head=(num_t *)malloc(sizeof(num_t));
create(head);
//print(head);
head=insert(head);
print(head);
}

void create(num_t *list)
{
printf("input a number\n");
printf("type -999 at a end ");
scanf("%d",&list->number);
if(list -> number==-999)
{
list->next=0;
}
else
{
list->next=(num_t *)malloc(sizeof(num_t));
create(list ->next);
}
return;
}

void print(num_t *list)
{
if(list->next!=0)
{
printf("%d -->",list->number);
print(list->next);
}
return;
}

num_t *insert(num_t *head)
{
num_t *n1;
int x;
int key;
num_t *new;
num_t *temp;

temp = head;
printf("enter the new value");
scanf("%d",&x);
printf("enter the key value");
scanf("%d",&key);

if(head->number==key)
{
new=(num_t *)malloc(sizeof(num_t));
new->number=x;
new->next=head;
head=new;
return(head);
}

while(temp->next)
{
if(temp-> number == key)
{
new=(num_t *)malloc(sizeof(num_t));
new->number=x;
new->next=temp->next;
temp->next=new;
return head;
}
temp = temp->next;
}
}
/*else
{
n1=find(head,key);
if(n1==0)
printf("key is not found");
else
{
new=(num_t *)malloc(sizeof(num_t));
new->number=x;
new->next=n1->next;
n1->next=new;
}
}
return(head);
}


num_t *find(num_t *list,int key)
{
if(list->number==key)
return list;
else
if(list->next==0)
return 0;
else
find(list->next,key);
}*/

single Linked list operations

/* pgr to write linked list operation in the linked list
written by sekhar
written on 21/08/07
modified on 21/08/07 */

#include
//#include
typedef struct linkedlist
{
int number;
struct linkedlist *next;
}num_t;

void create(num_t *);
void print(num_t *);
num_t *insert(num_t *);
num_t *find(num_t *,int);
main()
{
num_t *head;
head=(num_t *)malloc(sizeof(num_t));
create(head);
//print(head);
head=insert(head);
print(head);
}

void create(num_t *list)
{
printf("input a number\n");
printf("type -999 at a end ");
scanf("%d",&list->number);
if(list -> number==-999)
{
list->next=0;
}
else
{
list->next=(num_t *)malloc(sizeof(num_t));
create(list ->next);
}
return;
}

void print(num_t *list)
{
if(list->next!=0)
{
printf("%d -->",list->number);
print(list->next);
}
return;
}

num_t *insert(num_t *head)
{
num_t *n1;
int x;
int key;
num_t *new;

printf("enter the new value");
scanf("%d",&x);
printf("enter the key value");
scanf("%d",&key);

if(head->number==key)
{
new=(num_t *)malloc(sizeof(num_t));
new->number=x;
new->next=head;
head=new;
}
else
{
n1=find(head,key);
if(n1==0)
printf("key is not found");
else
{
new=(num_t *)malloc(sizeof(num_t));
new->number=x;
new->next=n1->next;
n1->next=new;
}
}
return(head);
}
num_t *find(num_t *list,int key)
{
if(list->next->number==key)
return list;
else
if(list->next->next==0)
return 0;
else
find(list->next,key);
}

analysing data structures by using structures

/*analysing data structures by using structures
written by sekhar
written on 17/08/07
modified on 17/08/07 */
#include
#define no 20
typedef struct
{
int rollno;
char name[20];
int marks;
char remarks[20];
} stu_t;

int insert(stu_t *);
void display(stu_t *);
int delete(stu_t *);
int update(stu_t *);
// int search(stu_t *);
static index=0;

main()
{
int option,value;
stu_t student[no];
while(1)
{
puts("\nenter option for 1.insert data\n 2.delete the data \n3. update data\n4.sorting the data\n5.serching the data \n6. display the data \n7. exit");
puts("enter the option");
scanf("%d",&option);
switch(option)
{
case 1:
value=insert(student);
if(value==0)
puts("operation is success");
else
puts("operation denied");
break;
case 2:
value=delete(student);
if(value==0)
puts("operation is success");
else
puts("operartion problem");
break;
case 3:
value=update(student);
if(value==0)
puts("operation is success");
else
puts("operation denied");
break;
case 4:
value=sort(student);
if(value==0)
puts("operation is success");
else
puts("operation is denied");
break;
/* case 5:
value=search(data);
printf("the value you are searching in there in database %d times",value);
break;*/
case 6:
display(student);
break;
case 7:
exit();

}
}
}




int insert(stu_t *fstudent)
{
int option,i,middle,value;
char x='y';
while(1)
{
puts("\nwhere you want to insert \n 1.top 2.middle 3.bottom 4.exit");
puts("\nenter the option");
scanf("%d",&option);
switch(option)
{
case 1:
while(x=='y')
{
if(index==20)
return(1);
else
{

puts("enter the value");
for(i=index;i>0;i--)
*(fstudent+i)=*(fstudent+i-1);
scanf("%d%s%d%s",&fstudent[0].rollno,fstudent[0].name,&fstudent[0].marks,fstudent[0].remarks);
index++;
puts("do u want to add another entry on top \n y or n");
__fpurge(stdin);
scanf("%c",&x);
}
}

return(0);
case 2:
while(x=='y')
{
if(index==20)
return(1);
else
{
puts("enter the value");
puts("please enter the posion where u want to insert");
scanf("%d",&middle);
for(i=index;i>middle;i--)
*(fstudent+i)=*(fstudent+i-1);
scanf("%d%s%d%s",&fstudent[middle].rollno,fstudent[middle].name,&fstudent[middle].marks,fstudent[middle].remarks);
index++;
puts("do you want to add another entry at middle");
__fpurge(stdin);
scanf("%c",&x);
}
}
return(0);
case 3:
while(x=='y')
{
if(index==20)
return(1);
else
{
puts("enter the value");
scanf("%d%s%d%s",&fstudent[index].rollno,fstudent[index].name,&fstudent[index].marks,fstudent[index].remarks);
index++;
puts("doyou want to add another entry at bottom y:yesn:no"); __fpurge(stdin);
scanf("%c",&x);
}
}
return(0);

}
}
}


int delete(stu_t *fstudent)
{
int i,option,middle;
puts("where do you want to delete entry\n 1.top 2. middle 3. bottom");
puts("enter the option:");
scanf("%d",&option);
switch(option)
{
case 1:
for(i=1;i<(index);i++)
*(fstudent+i-1)=*(fstudent+i);
index--;
return(0);
case 2:
puts("enter the position where u want to delete");
scanf("%d",&middle);
for(i=middle+1;i<(index);i++)
*(fstudent+i-1)=*(fstudent+i);
index--;
return(0);

case 3:

index--;
return(0);
}
}


void display(stu_t *fstudent)
{
int i,value;
for(i=0;i<(index);i++)
{
printf("\n%d\t%s\t%d\t%s",fstudent[i].rollno,fstudent[i].name,fstudent[i].marks,fstudent[i].remarks);
}
}

int update(stu_t *fstudent)
{
int i,value;
puts("enter the position where u want to update");
scanf("%d",&i);
scanf("%d%s%d%s",&fstudent[i-1].rollno,fstudent[i-1].name,&fstudent[i-1].marks,fstudent[i-1].remarks);
return 0;
}

int sort(stu_t *fstudent)
{
int i,value,a,b,option;
stu_t x;
puts("select 1:name sorting 2: by marks 3: by roll nos 4:remarks ");
puts("enter the option");
scanf("%d",&value);
switch(value)
{
case 1:
puts("1:ascending,2:descending");
puts("enter the option");
scanf("%d",&option);
switch(option)
{
case 1:

for(a=0;a<=index-1;a++)
{
for(b=0;b {
i=0;
while(fstudent[b].name[i]==fstudent[a].name[i])
i++;
if(fstudent[b].name[i]>fstudent[a].name[i])
{
x=fstudent[a];
fstudent[a]=fstudent[b];
fstudent[b]=x;
}
}
}
return 0;
case 2:

for(a=0;a<=index-1;a++)
{
for(b=0;b<(a);b++)
{
i=0;
while(fstudent[b].name[i]==fstudent[a].name[i])
i++;
if(fstudent[b].name[i]<(fstudent[a].name[i]))
{
x=fstudent[a];
fstudent[a]=fstudent[b];
fstudent[b]=x;
}
}
}
return 0;
}
}
}

pgr to impliment data structures ie insert,delete,update,sorting,display,searching

/* pgr to impliment data structures ie insert,delete,update,sorting,display,serching written by sekhar written on 16/08/07 modified on 16/08/07
*/
#include
int insert(int *);
void display(int *);
int delete(int *);
int update(int *);
int search(int *);
static index=0;

main()
{
int data[20],option,value;
while(1)
{
puts("\nenter option for 1.insert data\n 2.delete the data \n3. update data\n4.sorting the data\n5.serching the data \n6. display the data \n7. exit");
puts("enter the option");
scanf("%d",&option);
switch(option)
{
case 1:
// puts("enter the value");
// scanf("%d",&value);
value=insert(data);
if(value==0)
puts("operation is success");
else
puts("operation problem");
break;
case 2:
value=delete(data);
if(value==0)
puts("operation is success");
else
puts("operartion problem");
break;
case 3:
value=update(data);
if(value==0)
puts("operation is success");
else
puts("operation denied");
break;
case 4:
value=sort(data);
if(value==0)
puts("operation is success");
else
puts("operation is denied");
break;
case 5:
value=search(data);
printf("the value you are searching in there in database %d times",value);
break;
case 6:
display(data);
break;
case 7:
exit();
}
}
}



int insert(int *fdata)
{
int option,i,middle,value;
char x='y';
while(1)
{
puts("\nwhere you want to insert \n 1.top 2.middle 3.bottom 4.exit");
puts("\nenter the option");
scanf("%d",&option);
switch(option)
{
case 1:
while(x=='y')
{
if(index==20)
return(1);
else
{

puts("enter the value");
scanf("%d",&value);
for(i=index;i>0;i--)
*(fdata+i)=*(fdata+i-1);
fdata[0]=value;
index++;
puts("do u want to add another entry on top \n y or n");
__fpurge(stdin);
scanf("%c",&x);
}
}
return(0);
case 2:
while(x=='y')
{
if(index==20)
return(1);
else
{
puts("enter the value");
scanf("%d",&value);
puts("please enter the posion where u want to insert");
scanf("%d",&middle);
for(i=index;i>middle;i--)
*(fdata+i)=*(fdata+i-1);
fdata[middle]=value;
index++;
puts("do you want to add another entry at middle");
__fpurge(stdin);
scanf("%c",&x);
}
}
return(0);
case 3:
while(x=='y')
{
if(index==20)
return(1);
else
{
puts("enter the value");
scanf("%d",&value);
fdata[index]=value;
index++;
puts("doyou want to add another entry at bottom y:yesn:no"); __fpurge(stdin);
scanf("%c",&x);
}
}
return(0);

}
}
}
int delete(int *fdata)
{
int i,option,middle;
puts("where do you want to delete entry\n 1.top 2. middle 3. bottom");
puts("enter the option:");
scanf("%d",&option);
switch(option)
{
case 1:
for(i=0;i<(index);i++)
*(fdata+i-1)=*(fdata+i);
index--;
return(0);
case 2:
puts("enter the position where u want to delete");
scanf("%d",&middle);
for(i=middle;i<(index);i++)
*(fdata+i-1)=*(fdata+i);
index--;
return(0);

case 3:

index--;
return(0);
}
}

int update(int *fdate)
{
int position,value;
puts("enter the position where you want to update");
scanf("%d",&position);
puts("enter the new value");
scanf("%d",&value);
fdate[position]=value;
return(0);
}


int sort(int *fdata)
{
int option,i,j,x;
puts("enter the option 1:ascending 2:descending");
scanf("%d",&option);
switch(option)
{
case 1:
for(i=0;i<(index);i++)
{
for(j=0;j<=i;j++)
{
if(fdata[i]<=fdata[j])
{
x=fdata[i];
fdata[i]=fdata[j];
fdata[j]=x;
}
}
}
return(0);
case 2:
for(i=0;i<(index);i++)
{
for(j=0;j<=i;j++)
{
if(fdata[i]>=fdata[j])
{
x=fdata[i];
fdata[i]=fdata[j];
fdata[j]=x;
}
}
}
return(0);
}
}

int search(int *fdata)
{
int value,incr=0,i;
puts("what for you are seaching \n enter value here");
scanf("%d",&value);
for(i=0;i<=index;i++)
{
if(fdata[i]==value)
incr++;
}
return incr;
}

void display(int *fdata)
{
int i,value;
for(i=0;i<(index);i++)
{
printf("\ndata[%d]=%d",i,fdata[i]);
}
}

Program on union

/* pgr to know about union
written by sekhar
written on 13/08/07
*/
#include
typedef struct
{
int empid;
char name[20];
int basic;
}emp_t;


typedef struct
{
int sturollno;
char stuname[20];
int marks;
}stu_t;

typedef union
{
emp_t e;
stu_t s;
}u_t;
void display(u_t ,int);
main()
{
u_t u;
printf("employee details");
scanf("%d%s%d",&u.e.empid,&u.e.name,&u.e.basic);
printf("student detais");
scanf("%d%s%d",&u.s.sturollno,&u.s.stuname,&u.s.marks);
display(u,2);
}



void display(u_t u,int option)
{
switch(option)
{
case 1:
printf("%d%s%d",u.e.empid,u.e.name,u.e.basic);
break;
case 2:
printf("%d%s%d",u.s.sturollno,u.s.stuname,u.s.marks);
break;
}
}

Update time aswellas date

#include
//global variable
typedef struct
{ int sec;
int min;
int hour;
int day;
int month;
int year;
}time_t;
//header files
int noofday(time_t d);
int leapyear(time_t d);
time_t update_time(time_t ,time_t );


int main()
{
time_t present,next;
printf("enter today's date&time(yyyy/mm/dd/hh/mm/ss");
scanf("%d%d%d%d%d%d",&present.year,&present.month,&present.day,&present.hour,&present.min,&present.sec);
while(1)
{
present=update_time(present,next);
sleep(1);
printf("\n%d:%d:%d:%d:%d:%d",present.year,present.month,present.day,present.hour,present.min,present.sec);
if(present.year==9999)
exit();
}
}


int noofday(time_t d)
{
int array[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int ans;
if((d.month==2)&&leapyear(d))
{
ans=29;
}
else
ans=array[d.month];
return(ans);
}
/* function used for leap year */


int leapyear(time_t d)
{
int flag;
if((d.year%4==0)&&((d.year%100!=0)||(d.year%400==0)))
flag=1;
else
flag=0;
return(flag);
}

time_t update_time(time_t time1,time_t time2)
{
if(time1.sec!=59)
{
time2.sec=time1.sec+1;
time2.min=time1.min;
time2.hour=time1.hour;
time2.day=time1.day;
time2.month=time1.month;
time2.year=time1.year;
}
else
{
if(time1.min!=59)
{
time2.sec=0;
time2.min=time1.min+1;
time2.hour=time1.hour;
time2.day=time1.day;
time2.month=time1.month;
time2.year=time1.year;
}
else
{
if(time1.hour!=23)
{
time2.sec=0;
time2.min=0;
time2.hour=time1.hour+1;
time2.day=time1.day;
time2.month=time1.month;
time2.year=time1.year;
}
else
{
if(time1.day!=noofday(time1))
{
time2.sec=0;
time2.min=0;
time2.hour=0;
time2.day=time1.day+1;
time2.month=time1.month;
time2.year=time1.year;
}
else
if(time1.month==12)
{ //end of the year
time2.sec=0;
time2.min=0;
time2.hour=0;
time2.day=1;
time2.month=1;
time2.year=time1.year+1;
}
else
{ // end of month
time2.sec=0;
time2.min=0;
time2.hour=0;
time2.day=1;
time2.month=time1.month+1;
time2.year=time1.year;
}
}
}
}
return time2;
}

display content of a file on screen

/*display content of a file on screen*/
#include
main()
{
FILE *fp;
char ch;

fp=fopen("sania.bit","r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;

printf("%d",ch);
}
fclose(fp);
}

Update the date

#include
//global variable
typedef struct
{
int day;
int month;
int year;
}date;
//header files
int noofday(date d);
int leapyear(date d);
int main()
{
date today,tomorrow;
printf("enter today's date(dd/mm/yyyy);");
scanf("%d%d%d",&today.day,&today.month,&today.year);
if(today.day!=noofday(today))
{ //cheking for middle of month
tomorrow.day=today.day+1;
tomorrow.month=today.month;
tomorrow.year=today.year;
}
else if(today.month==12)
{ //end of the year
tomorrow.day=1;
tomorrow.month=1;
tomorrow.year=today.year+1;
}
else
{ // end of month
tomorrow.day=1;
tomorrow.month=today.month+1;
tomorrow.year=today.year;
}
printf("%d day: %d month: %d yaer:",tomorrow.day,tomorrow.month,tomorrow.year);
} //end of main
/*calculating number of days per month */
int noofday(date d)
{
int array[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int ans;
if((d.month==2)&&leapyear(d))
{
ans=29;
}
else
ans=array[d.month];
return(ans);
}
/* function used for leap year */
int leapyear(date d)
{
int flag;
if((d.year%4==0)&&((d.year%100!=0)||(d.year%400==0)))
flag=1;
else
flag=0;
return(flag);
}

using structures in function

/* pgr use functions in structures
written by sekhar
written on 07/07/08
modified on 07/07/08*/
#include
typedef struct emp // secondary datatype stuct emp act like a varible int
{
int id;
char name[20];
int basic;
float hra;
float ta;
float net;
};
void get_details(struct emp*);
void display(struct emp*);
void net_sal(struct emp*);


main()
{
struct emp e[10]; // declaration here stuct emp act like primary e like a variable
get_details(e); //call the fuction address of intial memory location
net_sal(e);
}


void get_details(struct emp *a)
{
int i;
for(i=0;i<=2;i++)
scanf("%d%s%d%f%f",&a[i].id,a[i].name,&a[i].basic,&a[i].hra,&a[i].ta);
}


void net_sal(struct emp *b)
{
int i;
for(i=0;i<=2;i++)
{
b[i].net=b[i].basic+b[i].hra+b[i].ta;
printf("%d\t%s\t%d\t%f\t%f\t%f\n",b[i].id,b[i].name,b[i].basic,b[i].hra,b[i].ta,b[i].net);
}






}

Size of structres

/* Pgr to write structures find the size of the stuctures
written by sekhar
written on 08/07/08
*/
#include
main()
{
typedef struct emp
{
int x; //it will take 4 bytes
long double y; // it will take 12 bytes
char z; // it will take 1 byte in normal but here allocate 4 byte for this due to allign ment
};
struct emp e;
printf("%d",sizeof(e));
}

Programe to update time by 1 sec

/*pgr to update time by 1 sec
written by sekhar
written on 08/08/07
modified on 08/08/07 */

#include
typedef struct
{
int sec;
int min;
int hours;
}time_t;
void update_time(time_t *,time_t *);

main()
{
time_t present,updated;
puts("enter the present time in hh:mm:ss");
scanf("%d%d%d",&present.hours,&present.min,&present.sec);
printf("%d:%d:%d",present.hours,present.min,present.sec);
// while(1)
// {
update_time(&present,&updated);
printf("\n%d:%d:%d",updated.hours,updated.min,updated.sec);
// present=updated;
// if(present.hours==13)
// exit();
// }
}

void update_time(time_t *time1,time_t *time2)
{
if(time1->sec!=59)
{
time2->sec=time1->sec+1;
time2->min=time1->min;
time2->hours=time1->hours;
}
else
{
if(time1->min!=59)
{
time2->sec=0;
time2->min=time1->min+1;
time2->hours=time1->hours;
}
else
{
time2->sec=0;
time2->min=0;
time2->hours=time1->hours+1;
}
}
}

Sunday, January 20, 2008

use multi pointers

/*pg rto use multi pointers
written by sekhar
written on 06/07/08*/
#include
int product_p1(int *,int *);
int product_p2(int **,int **);


main()
{
int value1,value2,*p1,*p2,y;
p1=&value1;
p2=&value2;
scanf("%d%d",&value1,&value2);
y=product_p1(p1,p2);
printf("%d\n%d\n%d",*p1,*p2,y);
}
int product_p1(int *value3,int *value4)
{
int **p3,**p4,x;
p3=&value3;
p4=&value4;
x=product_p2(p3,p4);
return x;
}
int product_p2(int **value5,int **value6)
{
int z;
z=**value5***value6;
return z;
}

make file

/* pgr to make file using stings
main pgr
written by sekhar
written on 03/08/07 */
#include
#define size 40
int str_len(char *);
void str_cpy(char *,char *);
void str_cat(char *,char *);
void str_rev(char *);
int str_word_count(char *);
int str_cmp(char *,char *);
main()
{
int option,len,count,comp;
char str1[size],str2[size];
while(1)
{
puts("\n1:str_len 2:strcpy 3:strconcat 4:strrev 5:strwordcount 6:exit");
puts("\nenter the option:");
scanf("%d",&option);
switch(option)
{
case 1:
puts("enter the string:");
__fpurge(stdin);
gets(str1);
len=str_len(str1);
printf("%d",len);
break;
case 2:
puts("enter the source sting to copy");
__fpurge(stdin);
gets(str1);
str_cpy(str1,str2); //str1 is source str2 is destination
puts(str2);
break;
case 3:
puts("enter the first string:");
__fpurge(stdin);
gets(str1);
puts("enter the second string:");
__fpurge(stdin);
gets(str2);
str_cat(str1,str2); //str1 & str2 is concate nate result in str1
puts(str1);
break;
case 4:
puts("enter the string foe reversing");
__fpurge(stdin);
gets(str1);
str_rev(str1);
puts(str1);
break;
case 5:
puts("enter the string for word count");
__fpurge(stdin);
gets(str1);
count=str_word_count(str1);
printf("%d",count);
break;
case 6:
puts("enter the first string");
__fpurge(stdin);
gets(str1);
puts("enter the second string");
__fpurge(stdin);
gets(str2);
comp=str_cmp(str1,str2);
printf("%d",comp);
break;

case 7:
exit();
}
}
}

/* function for string concatination
two string concatenate and result will be stored first string
written by sekhar
written on 03/08/07
modified on 03/08/07 */
void str_cat(char *s1,char *s2) //concatenate and store is s1
{
int y;
y=str_len(s1);//copy function calling source and destination is same
str_cpy(s2,s1+y);//same as above
}

/* function to compare two strings
written by sekhar
written on 03/08/07
modified on 03/08/07 */

int str_cmp(char *s1,char *s2)
{
int value=0,i;
while(*++s1!='\0'&&*++s2!='\0')
{
value=*s1-*s2;
}
if(value>0)
i=1;
if(value<0)
i=-1;
if(value==0)
i=0;

return i;
}
/* pgr for function of string copy
first string is source string second is destination string
written by sekhar
written on 03/08/07 */
void str_cpy(char *source, char *desti)
{
while(*source!='\0')
*desti++=*source++;
*desti='\0';
}


/*function to find str length
written by sekhar
written on 03/08/07
modified on 03/08/07
*/
int str_len(char * s1)
{
int count=0;
while(*s1++!='\0')
{
count++;
}
return count;
}


/* function for reversing the sting
written by sekhar
written on 03/07/08
*/
void str_rev(char *s1)
{
char len,i=0;
char s2[40];
str_cpy(s1,s2);
len=str_len(s1);
for(;len>0;len,i)
{
s1[--len]=*(s2+i);
i++;
}
// s1[len]='\0';
}
/* pgr to count the no words in the sting
written by sekhar
written on 03/07/08
modified on 03/07/08*/
int str_word_count(char *s1)
{
int cou=1;
while(*s1++!='\0')
{
if(*s1==' ')
cou++;
}
return cou;
}



strout: main.o strlen.o strcpy.o strcat.o strrev.o strwordcount.o strcmp.o
$ gcc -o strout main.o strlen.o strcpy.o strcat.o strrev.o strwordcount.o strcmp.o
main.o: main.c
$ gcc -c main.c
strlen.o: strlen.c
$ gcc -c strlen.c
strcpy.o: strcpy.c
$ gcc -c strcpy.c
strcat.o: strcat.c
$ gcc -c strcat.c
strrev.o: strrev.c
$ gcc -c strrev.c
strwordcount: strwordcount.c
$ gcc -c strwordcount.c
strcmp: strcmp.c
$ gcc -c strcmp.c
clean:
$ rm -rf *.o

programe to use switch statement

/*tatement programe to use switch statement
written on 05/07/07
modified date 05/07/07
written by sekhar */
#include

#include
main()
{
char ch;
while(1)
{
printf("enter the charecter");
__fpurge(stdin);
// fflush(stdin);
scanf("%c",&ch);
switch(ch)
{
case 'a':
printf(" execution of first programe ");
break;
case 'b':
printf(" execution of second programe");
break;
default:
exit();

} // switch statement ends
}
}

sum of even and odd number in the given range

/* programe to find sum of even and odd number in the given range
created date 30/06/07
modified date 30/06/07
created by: sekhar */
#include
main()
{
int i=0,num=0,sum=0;
scanf("%d",num);
while(i<=num)
{
num=num+2;
sum=sum+num;
i++;
}
printf("%d",sum);
}

introduction to structures

/* prg to use stuctures
written on 05/07/07
modified on 05/07/07
written by sekhar*/
#include
main()
{
int i;
struct book
{
char name;
float price;
int pages;
};
struct book b[3];

printf("\nEnter names,prices&no of pages of 3 books\n");
for(i=0;i<=2;i++)
scanf("%c %f %d ",&b[i].name,&b[i].price,&b[i].pages);
// scanf("%c %f %d ",&b2.name,&b2.price,&b2.pages);
// scanf("%c %f %d ",&b3.name,&b3.price,&b3.pages);
printf(" This is what you entered");
for(i=0;i<=2;i++)
printf("%c %f %d ",b[i].name,b[i].price,b[i].pages);
// printf("%c %f %d ",b2.name,b2.price,b2.pages);
// printf("%c %f %d ",b3.name,b3.price,b3.pages);
}

string length

/* pgr to find string length
written by sekhar
written on 23/07/07
modified on 23/07/07 */
#include
#define size 10
void strlength(char *);
main()
{
char str1[size];
int i;
strlength(str1); //fn call
}

void strlength(char * str11)
{
int i=0,count=0;
// for(i=0;i<(size);i++)
scanf("%s",&str11[i]);

while(str11[i++]!='\0')
++count;
printf("length=%d",count);
}

string concatnation

/* pgr to copy two stings
written by sekhar
written on 23/07/07
modified on 23/07/07 */
#include
#define size 10
void strconcate(char *,char *,char *);
main()
{
char str1[size],str2[size],str3[size];
int i;
strconcate(str1,str2,str3); //fn call
for(i=0;i<=(size+size);i++)
printf("%c",str3[i]);
}

void strconcate(char * str11,char *str22,char *str33)
{
int i;
for(i=0;i<(size);i++)
{
scanf("%c",&str11[i]);
str33[i]=str11[i];
// printf("\n");
}
for(i=0;i<(size);i++)
{
scanf("%c",&str22[i]);
str33[size+i]=str22[i];
}
}

Saturday, January 19, 2008

copy stings

/*pgr to copy stings
written by sekhar
written on 25/07/07
modified on 25/07/07*/
#include
#define size 10
void sestrcpy(char *, char *); //prototype for copy the stings
main()
{
char str1[size],str2[size],i;
//scanf("%s",str1);
gets(str1);
sestrcpy(str2,str1); //first is destination second in source passing into th copy functio
// for(i=0;i<=50;i++)
// printf("%s",(str2));
puts(str2);
}

//function defnition
void sestrcpy(char *s2,char *s1) //first is destination second is source
{
char i;
for (i=0;*s1++!='\0';i++)
{
*++s2=*s1;
//printf("%u----%c",s2,*s2);
}
*(s2+i)='\0';

}

strcpy

/*prgrame to know about strcpy
written by sekhar
written on 25/07/07
modified on 25/07/07*/

#include
#include
#define size 6
main()
{
char s1[size],s2[size];
scanf("%s",s1);
strcpy(s2,s1); //s2 is destination & s1 is source
printf("%s",s2);//for printing the strings we have to point out the fist mem ory location
}

string compare

/* program to know about string compare
written by sekhar
written on 25/07/07
modified on 25/07/07 */
#include
#include
#define size 7

main()
{
char s1[size],s2[size],s3[size+size];
int x;
scanf("%s",s1);
scanf("%s",s2);
x=strcmp(s1,s2);
printf("%d",x);
}

strconcatnation

/*pgr to know about strconcatnation
written by sekhar
written on 25/07/07
modified on 25/07/07*/
#include
#define size 8
main()
{
char s1[size],s2[size];
int i;
scanf("%s%s",s1,s2);
strcat(s1,s2);
for(i=0;i<=20;i++)
printf("\ns1%u---%c s2%u-----%c",&s1[i],s1[i],&s2[i],s2[i]);
}

fibnocci series using recursion

/* pgr to write fibnocci series using recursion
written by sekhar
written on 12/07/07
modified on 12/07/07 */
#include
int fib(int);
main()
{
int num, i;
printf("how long you want the series enter number:");
scanf("%d",&num);

for(i=0; i<(num); i++)
printf("%d ", fib(i));

}
int fib(int a)
{
int x;
if(a==0)
return(0);
if(a==1)
return(1);
x = fib(a-1)+fib(a-2);
return(x);
}

find factorial by using recursion

/*prg to find factorial by using recursion
written by sekhar
written on 12/07/07
modified on 12/07/07*/
//program starts
#include
int factorial(int);
main()
{
int num,res;
printf("enter the number to find factorial:");
scanf("%d",&num);
res=factorial(num);
printf("%d",res);
}
int factorial(int fact)
{
if(fact==1)
return(1);
fact=fact*factorial(fact-1);
printf("\n%d",fact);
return(fact);
}

string operations in infinite loop

/* pgr to find string operations in infinite loop
written by sekhar
written on 30/07/07*/
#include
void string_copy(char *,char *);
void string_concat(char *,char *);
void string_word_count(char *,int *);
int string_length(char *);
int string_cmp(char *,char *);
main()
{
int option,count=0,x,y;
char str1[40],str2[40],strs1[40],strs2[40];
puts("enter the string:");
gets(str1);
while(1)
{
printf("1:for string copy, 2;string concatenate3:count string word count,4:strig length");
scanf("%d",&option);
switch(option)
{
case 1:
string_copy(str1,str2);
puts(str2);
break;
case 2:
string_concat(str1,str2);
puts(str1);
break;
case 3:
string_word_count(str1,&count);
printf("%d",count);
break;
case 4:
x=string_length(str1);
printf("%d",x);
break;
case 5:
puts("enter first string for compare:");
gets(strs1);
puts("enter second string for compare:");
gets(strs2);
y=string_cmp(strs1,strs2);
printf("%d",y);
break;
/* case 6:
string_char_str();
break;*/
case 7:
exit();
}
}
}
void string_copy(char *s1,char *s2)

{
while(*s1!='\0')
*s2++=*s1++;
*s2='\0';
}

void string_concat(char *s1,char *s2)
{
while(*++s1!='\0')
*s1=*s1;
puts(s2);
while(*s2!='\0')
{
puts(s2);
*s1++=*s2++;
}
*s1='\0';
}
//function for word length
void string_word_count(char *s1, int *cou)
{
while(*s1++!='\0')
{
if(*s1==32||*s1=='\0') // 32 in ascii equelent of ' '
{
*cou=*cou+1;
}
}
}
//function for calculate string length
int string_length(char *s1)
{
int cou=0;
while(*s1++!='\0')
{
cou++;
}
return cou;
}
//function for compare two strings
int string_cmp(char *s1,char *s2)
{
int co=0;
while(*s1++!='\0'&&*s2++!='\0')
{
co=*s1-*s2;
}
return co;
}

find areas using menu bar

/* pgr to find areas using menu bar
written by sekhar
written on 13/07/07
modified on 13/07/07 */
#include
void triangle(int,int,float *,float *);
void rectangle(int,int,float *,float*);
void circle(int,float *,float *);
void square(int,float *,float *);
main()
{
int base,height,length,breath,radius,side,i;
float area,perimeter;
while(1)
{
printf("select from menu:\n1 for triangle \n 2 for rectangle\n 3 for circle\n 4 for sqare\n 5 for exit\n");
scanf("%d",&i);
switch(i)
{
case 1:
printf("enter the base&height for a triangle");
scanf("%d%d",&base,&height);
triangle(base,height,&area,&perimeter);
printf("\narea is %f\nperimeter is %f\n",area,perimeter);
break;

case 2:
printf("enter the length &breath for a rectangle");
scanf("%d%d",&length,&breath);
rectangle(length,breath,&area,&perimeter);
printf("\narea is %f\nperimeter is %f\n",area,perimeter);
break;

case 3:
printf("enter the radiud of a circle");
scanf("%d",&radius);
circle(radius,&area,&perimeter);
printf("\narea is %f\nperimeter is %f\n",area,perimeter);
break;

case 4:
printf("enter the side of a square");
scanf("%d",&side);
square(side,&area,&perimeter);
printf("\narea is %f\nperimeter is %f\n",area,perimeter);
break;
case 5:
exit();
}
}
}
void triangle(int b,int h,float *a,float *p)
{
*a=(0.5)*b*h;
*p=3*b;
}
void rectangle(int l,int b,float *a,float *p)
{
*a=l*b;
*p=2*(l+b);
}
void circle(int r,float *a,float *p)
{
*a=(3.141)*r*r;
*p=2*3.141*r;
}
void square(int s,float *a,float *p)
{
*a=s*s;
*p=4*s;
}

indentity matrix without arrays with functins

/* program to write indentity matrix without arrays with functins
written by sekhar
written on 10/07/07
modified on 10/07/07 */
#include
void idisplay();
main()
{
idisplay();
}
void idisplay()
{
int i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
if(i==j)
printf("\t1");
else
printf("\t%d",i+j);
}
printf("\n");
}
}

write indentity matrix without arrays with functins

/* program to write indentity matrix without arrays with functins
written by sekhar
written on 10/07/07
modified on 10/07/07 */
#include
void idisplay();
main()
{
idisplay();
}
void idisplay()
{
int i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
if(i==j)
printf("\t1");
else
printf("\t0");
}
printf("\n");
}
}

matrix display with function without arrays

/*program for matrix display with function without arrays
written by sekhar
written on 10/07/2007
modified on 10/07/07 */

#include
void display();
main()
{
display();
}
void display()
{
int i;
for(i=1;i<=9;++i)
{
printf("\t%d",i);
if(i%3==0)
printf("\n");
}
}

to store data in memory locations

/*pgr to know about how to store data in memory locations
written by sekhar written on 28/07/07
modified on 18/07/07*/
#include
main()
{
int i,a;
char *x,*b;
x = (char *) &i;
b = (char *) &a;
scanf("%x",&i);
for(a=0;a<=3;a++)
{

// printf("%u %x\n",&i,i);
printf("%u %x\n",x+a,*(x+a));
//printf("%u %x\n",(b++),*b++);
}
}

finding the leaf year

/*finding the leaf year
creating date 30/06/07
modifying date 30/06/07
created by: sekhar*/

#include
main()
{
int year;
printf("Enter the year:");
scanf("%d",&year);
if(year%4==0)
printf("%d is a leaf year",year);
else
printf("%d is not a leaf year",year);
} // end of the programe

program to scan the numbers from keyboard and print corresponding number in the words in screen

/* program to scan the numbers from keyboard and print corresponding number in the words in screen
written on 06/07/07
modified on 17/07/07
written by sekhar*/
#include

int pow (int , int);
main()
{
int j,i,k,m,x,q;
int z,p,n=10;
char words[10][5]={"zero","one","two","three","four","five","six","seven","eight","nine"};
printf("enter the number to print in the words");
scanf("%d",&i);
q=i;
p=printf("%d\n",i);
z=pow(n,p);
// printf("%d\n",z);
while(p>1)
{
z=z/10;
k=q/z;
q=q%z;
if(z==1)
{
m=i%10;
for(j=0;j<=4;j++)
printf("%c",words[m][j]);
exit();
}

for(j=0;j<=4;j++)
printf("%c",words[k][j]);
--p;
}
}
int pow(int a,int b)
{
int j,y=1;
for(j=1;j<(b);j++)
y=y*a;
return(y);
}

know the incements pre&post

/* pgr to know the incements pre&post
written by sekhar
written on 13/07/07
modified on 13/07/07 */
#include
main()
{
int i=10;
++i;
printf("%d%d",++i,i++);
i++;
printf("%d",i);
}

find highest and lowest integer among 3 numbers

/* programe for find highest and lowest integer among 3 numbers
written date :02/07/07
modified date : 02/07/07
written by sekhar*/

#include
void highest(int,int,int); // function definition for the highest number
void lowest(int,int,int); // function definition for the lowest number
main()
{
int a,b,c;
printf(" Enter the 3 numbers");
scanf("%d%d%d",&a,&b,&c);
highest(a,b,c); //function calling for the find highest number
lowest(a,b,c); //function calling for the find lowest number
}
// function definition for find highest numer among 3 numbers
// written on 02/07/07
//written by sekhar
void highest(int x,int y,int z)
{
if(x>y)
{
if(x>z)
printf("\n %d is a highest number",x);
else
printf("\n %d is a highest number",z);
} //if block ends
else
{
if(y>z)
printf("\n %d is a highest number",y);
else
printf("\n %d is a highest number",z);
}
}
// function definition for find lowest numer among 3 numbers
// written on 02/07/07
//written by sekhar

void lowest(int x,int y,int z)
{
if(x<(y))
{
if(x<(z))
printf("%d is a lowest number",x);
else
printf("%d is a lowest number",z);
} //if block ends
else
{
if(y<(z))
printf("%d is a lowest number",y);
else
printf("%d is a lowest number",z);
}
}

display the the letters in the arranged formate

/* prg to display the the letters in the arranged formate
wriiten by sekhar
written on 10/07/07
modified on 10/07/07 */

#include
main()
{
int i,j,n;
printf("enter the number:");
scanf("%d",&n);
for(i=n;i<=90;i++)
{
for(j=n;j<=i;j++)
printf(" %c",j);
printf("\n");
}
}

sizeof operator

main()
{
float x=5.5;
printf("%f%d",x,sizeof(5.5));
}

fibanocci series

/*pgr to find fibanocci series
written by sekhar
written on 14/07/07 */

#include
void fib(void);
main()
{
fib();
}
void fib()
{
int x=0,y=1;
int i,n,res;
scanf("%d",&n);
printf("%d\n",x);
for(i=0;i<=n;i++)
{
res=x+y;
x=y;
y=res;
printf("%d\n",x);
}
}

find factorial series

/*pgr to find factorial series
written by sekhar
written on 14/07/07 */

#include
void fact(void);
main()
{
fact();
}
void fact()
{
int i,n,res=1;
scanf("%d",&n);

for(i=1;i<=n;i++)
res=res*i;
printf("%d",res);

}

find even sum

/* programe to find even sum
written date 02/07/07
modified date 02/07/07
written by sekhar*/
#include

int i=0,num,sum=0;
main()
{
scanf("%d",&num);
while(i<=num)
{
sum=sum+(i+2);
i++;
}
printf("%d",sum);
printf("%u %u %u",&i,&num,&sum);
printf("%u",main);
}

find even,odd, prime and perfect number

/*programe for find even,odd, prime and perfect number
date of programe 30\06\07
modified date 30\06\07
programe written by: sekhar */

#include
main()
{
int a,b=2,c=0;
printf("Enter a:");
scanf("%d",&a);
if(a%2==0)
printf(" the given number is even number");
else
printf(" the given number is odd number");

while(b<(a))
{
if(a%b==0)
{
printf("\n%d", b);
c=c++;
} // if loop ends
b=b++;
}
//int a,b=2,c=0;
// while loop ends
if (c==0)
printf("\n%d is prime number", a);
else
printf("\n%d is not a prime number", a);
} // program ends

display charecters in the specified formate

/* prg to display charecters in the specified formate
writtn by sekhar
written on 10/07/07
modified on 10/07/07 */
#include
main()
{
int n,i,j;
printf("enter the number");
scanf("%d",&n);
for(i=n;i>=65;i--)
{
for(j=i;j>=65;j--)
printf("\2%c",j);
printf("\n");
}
}

Maniplation of arrays

/* prg to use arrays in descending order
writtenby sekhar
written on 09/07/07
modified on 09/07/07*/

#include
main()
{
int a[5],i,t,x,y;
for(i=0;i<=4;i++)
scanf("%d",&a[i]);
for(y=0;y<=4;y++)
{
i=0;
for(x=0;x<=4;x++)
{

if(a[i]<=a[++i])
{
//printf("\n%d",a[i]);
t=a[--i];
a[i]=a[++i];
a[i]=t;
// printf("\n%d",a[--i]);
} // if block ends

} //x for loop ends
} //y for loop ends
for(i=0;i<=4;i++)
printf("\n%d",a[i]);

}

decision control 4

/* prg4 to use decision control
written on 05/07/07
modified on 05/07/07
written by sekhar */
#include
main()
{
int x=10,y=20;
x==20&&y!=10?printf("true"):printf("false");

}

decision control 3

/* prg3 to use decision control
written on 05/07/07
modified on 05/07/07
written by sekhar */
#include
main()
{
int ji=65;
printf("\n ji>=65 ? %d : %c",ji);
}

decision controle 2

/* pgr to use decision contole
written on 05/07/07
modified on 05/07/07
written by sekhar */

#include
main()
{
int k, num=30;
k=(num>5 ? (num<=10?100:200):500);
printf("\n%d %d",num,k);
}

decision control

/* prg to for decision control
written on 05/07/07
modified date 05/07/07
written by sekhar */
#include
main()
{
int i=-4,j,num;
j=(num<0 ? 0: num*num);

printf("\n%d\n%d",j,num);

}

prg to convert decimal number in to given base

/* prg to convert decimal number in to given base
written by sekhar
written on 16/07/07
modified on 16/07/07
*/
#include
main()
{
char arr[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
int index,number,base,pointing[32];
while(1)
{
int i=0;
printf("\nenter the number \nif u want to exit press 0");
scanf("%d",&number);
if(number==0)
exit();
printf("\nenter the base");
scanf("%d",&base);
while(number>0)
{
pointing[i]=number%base;
number=number/base;
++i;
}
printf("converted value is");
for(--i;i>=0;--i)
{
index=pointing[i];
printf("%c",arr[index]);
}
}
}

Know about PUT and GET char

#include
main()
{
unsigned char ch[4];
gets(ch);
puts(ch);
printf("%u",ch);
}

Know about casting

/* pgr to know about casting
written by sekhar
written on 19/07/07
modified on 19/07/07 */
#include
main()
{
int *p;
short *pi;
char *pid;
int x=0x12345678;
p=&x;
pi=(short*)&x;
pid=(char*)&x;
printf("%x\n%x\n%x",*p,*pi,*pid);
}

Call by reference

/*pgr to understand call by reference
written by sekhar
written on 13/07/07
modified on 13/07/07*/
#include
void area(int, float *);

main()
{
int radius;
float area1,p;
scanf("%d",&radius);
area(radius,&area1);
printf("%f", area1);
}
void area(int a,float *b)
{
*b=(3.141*a*a);

}

Auto keyword

/*pgr to know about auto
written by sekhar
written on 18/07/07
modified on 18/07/07*/
#include

main()
{
int a;
a=sumdig(12345);
printf("\n%d",a);
}
int sumdig(int num)
{
static int sum;
int a,b;
a=num%10;
b=(num-a)/10;
sum=sum+a;
if(b!=0)
sumdig(b);
else
return(sum);
}

display ascii code corresponding with digits

/* programe to display ascii code corresponding with digits
written date 05/07/07
modified date 05/07/07
written by :sekhar*/

#include
main()
{
char ch=' '; //=128; to know the perticular number status
// for(ch=0;ch<127;ch++)
// do

printf("\t%d ",ch);
// ch=ch++;
// while(ch++<127);
}

sorting the Array

#include
main()
{
int a[5],x,t,j,n,i;
printf("Enter array size:");
scanf("%d", &n);
printf("Enter array values\n");
for(i=0;i<(n);i++)
scanf("%d",&a[i]);
for(x=0;x<=10;x++)
{
i=0;
for(j=0;j<(n-1);j++)
{

if(a[i]<=a[++i])
{
// printf("%d %d %d",i,a[i],t);
// printf("%d",i);
t=a[i];
a[i]=a[--i];
// printf("%d %d %d",i,a[i],t);
a[i]=t;
// ++i;
// printf("%d %d %d",i,a[i],t);
}
// printf("\n%d",a[--i]);
// for(i=0;i<(n);i++)
// printf(" %d ",a[i]);
} //if block ends
//printf("\n%d",a[i]);
}
printf("After sorting array values are\n"); // for loop ends
for(i=0;i<(n);i++)
printf("%d\n",a[i]);

}

sorting array

/* prg to use arrays
writtenby sekhar
written on 09/07/07
modified on 09/07/07*/
#include
main()
{
int a[5],i,t,j,n;
printf("Enter array size:");
scanf("%d", &n);
printf("Enter array values\n");
for(i=0;i<(n);i++)
scanf("%d",&a[i]);
for(i=0;i<(n-1);i++)
{
for(j=i;j<(n);j++)
{
if(a[i]<=a[j])
{
//printf("\n%d",a[i]);
t=a[i];
a[i]=a[j];
a[j]=t;
}
// printf("\n%d",a[--i]);
} //if block ends
//printf("\n%d",a[i]);
}
printf("After sorting array values are\n"); // for loop ends
for(i=0;i<(n);i++)
printf("%d\n",a[i]);
}

pointers in arrays

/*prg to know the array in pointers
written by sekhar
written on 20/07/07
modified on 20/07/07 */
#include
main()
{
int a[5]={5,1,15,45,47};
int i,j,k=1,m;
i=++a[1];
printf("\n%d",i);
j=a[1]++;
printf("\n%d",j);
m=a[i++];
printf("\n%d%d%d%d",i,j,m,a[1]);
}

Orogram for status of student

/*program for status of students
written by sekhar
written on 19/07/07
modified on 19/07/07 */
#include
void fillmarks(int a[]); //prototype for filling the marks of students
void printmarks(int *); //prototype for print the marks of students
int maxmark(int *); // prototype for calcul;ate max mark of the sudent
int minmark(int *); //prototype for calculate minimum marks
int average(int *); //prototype for know the status each and every student
void pass1(int *);
void fail1(int *);
main()
{
int array[10],max,min,aver,i,pass,fail ;
fillmarks(array); //function call for fill the marks
printmarks(array); // function call for print the marks
while(1)
{
printf("enter your option 1:max mark2:min mark 3:avg mark 4:pass count 5: fail count 6: exit");
printf("enter i value:");
scanf("%d",&i);
switch(i)
{
case 1:
max=maxmark(array); //function call for max mark
printf("\nhighest mark in the classis %d",max);
break;
case 2:
min=minmark(array); //function call for find min mark
printf("\n lowest mark in the class in %d",min);
break;
case 3:
aver=average(array);
printf("\n average marks of th class is %d",aver);
break;
case 4:
pass1(array);
break;
case 5:
fail1(array);
break;
case 6:
exit();
default:
printf("wronge ");
break;
}
}
}
void fillmarks(int a[])
{
int i;
printf("enter the marks");
for(i=0;i<=9;i++)
scanf("%d",&a[i]);
}
void printmarks(int *a)
{
int i;
printf("this is what you enter the marks");
for(i=0;i<=9;i++)
printf("\t%d",a[i]);
}
int maxmark(int *b)
{
int i,t;
for(i=0;i<=9;i++)
{
if(b[0]<=b[i])
{
t=b[0];
b[0]=b[i];
b[i]=t;
}
}
return(b[0]);
}
int minmark(int *b)
{
int i,t;
for(i=0;i<=9;i++)
{
if(b[0]>=b[i])
{
t=b[0];
b[0]=b[i];
b[i]=t;
}
}
return(b[0]);
}
int average(int *marks)
{
int i,t=0,ave;
for(i=0;i<=9;i++)
{
t=t+marks[i];
}
ave=t/i;
return(ave);
}
void pass1(int *b)
{
int i,x=0,y=0,z=0;
for(i=0;i<=9;i++)
{
if(b[i]>=75)
x=x+1;
if(b[i]>=60 && b[i]<75)
y=y+1;
if(b[i]>=35 && b[i]<60)
z=z+1;
}
printf("\n %d are got distiction",x);
printf("\n %d are got firstclass",y);
printf("\n %d are got second class",z);
}
void fail1(int *b)
{
int i,x=0,y=0,z=0;
for(i=0;i<=9;i++)
{
if(b[i]<=35)
x=x+1;
}
printf("\n%d failed in this subject" ,x);
}

Multiplication of matrices

/*prg to for multiflication of matrixes
written by sekhar
written on 16/07/07
modified on 18/07/07 */
#include
main()
{
int s,i,j,k,l,m,n,o,x,y,a[6][6],b[6][6],c[6][6],d[6];
printf("enter the order of matrix");
scanf("%d",&s);
printf("enter the elements of first matrix\n");
for(i=0;i{
for(j=0;j{
printf("\nenter(%d,%d)element:",i,j);
scanf("%d",&a[i][j]);
}
printf("\n");
} //scan of first matrix
printf("enter the elements of second matrix\n");
for(k=0;k{
for(l=0;l{
printf("\nenter(%d,%d)element:",k,l);
scanf("%d",&b[k][l]);
}
printf("\n");
} //scan of second matrix
for(m=0;m{
for(n=0;n{
y=0;
for(o=0;od[o]=a[m][o]*b[o][n];
for(x=0;xy=y+d[x];
c[m][n]=y;
printf("\t%d",c[m][n]);
}
printf("\n");
}
}

array display as matrix

/* pgr on array to display matrix
written by sekhar
written on 16/07/07
modified on 16/07/07 */
#include
main()
{
int matrix[3][3],i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("\t(%d,%d)\t",i,j);
scanf("%d",&matrix[i][j]);
printf("%u",&matrix[i][j]);
}
printf("\n");
}
printf("you have entered values\n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
// printf("\t(%d,%d)\t",i,j);
printf("\t%d",matrix[i][j]);
// printf("%u",&matrix[i][j]);
}
printf("\n");
}
printf("%d",sizeof(matrix));
}

Multiplication of charecter array

/*pgr for multiplication of charecter array
written by sekhar
written on 17/07/07
modified on 17/07/07 */
#include
main()
{
int i,j,k,l,m,n,o;
char a[3][3],b[3][3],c[3][3],d[3];
printf("enter the elements of first matrix\n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("\nenter(%d,%d)element:",i,j);
scanf("%c",&a[i][j]);
}
printf("\n");
} //scan of first matrix
printf("enter the elements of second matrix\n");
for(k=1;k<=3;k++)
{
for(l=1;l<=3;l++)
{
printf("\nenter(%d,%d)element:",k,l);
scanf("%c",&b[k][l]);
}
printf("\n");
} //scan of second matrix
for(m=1;m<=3;m++)
{
for(n=1;n<=3;n++)
{
for(o=1;o<=3;o++)
d[o]=a[m][o]*b[o][n];
c[m][n]=d[1]+d[2]+d[3];
printf("\t%c",c[m][n]);
}
printf("\n");
}
}

Largest number in 2 dim Array

/*pgr to find largest number in 2 dimensional array
written by sekhar
written on 20/07/07
modified on 20/07/07 */

#include
main()
{
int a[3][3],i,j,t;
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(a[0][0]<=a[i][j])
{
t=a[0][0];
a[0][0]=a[i][j];
a[i][j]=t;

}
// printf("\n%d",a[0][0]);
}
}
printf("greatest\n%d",a[0][0]);
}

arp request in LAN

/* pgr pass arp packet into function
print packet in the field wise in the function
written by sekhar
written on 26/07/07
modified on 26/07/07 */
#include
void arp_request_lan(char *,char *,char *);
// void arp_responce_lan(int *);


main()
{
int i;
struct arp
{
char name[10];
char length[4];
char value[28];
};
struct arp field[9];
for(i=0;i<=8;i++)
{
printf("enter values for field[%d]",i);
scanf("%s%s%s",field[i].name,field[i].length,field[i].value);
printf("\n %x %x %x",field[i].name,field[i].length,field[i].value);
}
arp_request_lan(field[0].name,field[0].length,field[0].value);
}
//function calling for print the arp packet
void arp_request_lan(char *name,char *lenth,char *value)
{
char i,a;
int x;
for(i=0;i<=8;i++)
{
x=41*i;
// a=10*i;
printf("%s %s %s\n",(name+i+x),(lenth+i+x),(value+x+i));
}
}