Friday, February 5, 2010

Union in C Language

#include
#include
#include
void main()
{struct student
{
int name;
struct student *next;
}*std,*r,*q;
q='\0';
int m,i,a;
printf("How many students:-\n");
scanf("%d",& m);
printf("Enter %d Elements:\n",m);
for(i=1;i<=m;i++)
{scanf("%d",&a);
std=(struct student*)malloc(sizeof(struct student));
std->name=a;
std->next='\0';
if(q=='\0')
{q=std;
}
else
{r=q;
while(r->next!='\0')
r=r->next;
r->next=std;
}
}
r=q;
while(r!='\0')
{printf("%d \t %d \n",r->name,r->next);
r=r->next;
}
}

Storing Data Using Pointer in C language

#include
#include
#include
void main()
{struct student
{
int name;
struct student *next;
}*std,*r,*q;
q='\0';
int m,i,a;
printf("How many students:-\n");
scanf("%d",& m);
printf("Enter %d Elements:\n",m);
for(i=1;i<=m;i++)
{scanf("%d",&a);
std=(struct student*)malloc(sizeof(struct student));
std->name=a;
std->next='\0';
if(q=='\0')
{q=std;
}
else
{r=q;
while(r->next!='\0')
r=r->next;
r->next=std;
}
}
r=q;
while(r!='\0')
{printf("%d \t %d \n",r->name,r->next);
r=r->next;
}
}

Structure In C Language

#include
#include

void main()
{
struct student{int roll;
char name[20];
int marks;
}stud[5];

int i=0,no,flag=0;
char ch='y';
printf("\nEnter information of 20 student:-");
for(i=0;i<5;i++)
{printf("\nEnter the roll number of the student %d :-",i+1);
scanf("%d",& stud[i].roll);
printf("\n Enter the name of the student %d:-",i+1);
scanf("%s",& stud[i].name);
printf("\n Enter the marks of the student %d:-",i+1);
scanf("%d",& stud[i].marks);
}
while((ch=='Y')||(ch=='y'))
{clrscr();
printf("\nEnter student rollno to display:-\n");
scanf("%d",& no); flag=0;
for(i=0;i<5;i++)
{if(stud[i].roll==no)
printf("Roll Number:- %d Name:- %s Total Marks :- %d",stud[i].roll,stud[i].name,stud[i].marks);
flag=1;

}

if(flag==0)
printf("the Roll Number %d is not present in the list",no);
printf("\n Enter Y to continue");
printf("\n Enter any othr key to exit");
ch=getche();
}
}

Thursday, February 4, 2010

How to multiply two matrices in c Programming

#include
void main(int *argv,char argc*[])
{
int *mat1[10],*mat2[10],*mat3[10];
int i,j,m,n;
printf("Enter the value row and column:-");
scanf("%d%d",&m,&n);
for(i=0;i{
mat1[i]=(int*)calloc(m,sizeof(int));
mat2[i]=(int*)calloc(m,sizeof(int));
mat3[i]=(int*)calloc(m,sizeof(int));
}
printf("Enter the value of Matrix1:-\n");
for(i=0;i{
for(j=0;jscanf("%d",(*(mat1+i)+j));
}
printf("Enter the value of Matrix2:-\n");
for(i=0;i{for(j=0;jscanf("%d",(*(mat2+i)+j));
}for(i=0;i{for(j=0;j{
*(*(mat3+i)+j)=*(*(mat1+i)+j) * *(*(mat2+i)+j);
}
}
printf("The Product Of Above Two Matrix:-\n");


for(i=0;i{for(j=0;j{printf("%d",*(*(mat3+i)+j));
}
printf("\n");
}
}