Showing posts with label Structure. Show all posts
Showing posts with label Structure. Show all posts
C Program Structure Example
How to write a C Program Structure Example in C Programming Language ?
Solution For C Program :C Program To Make Employee Payment Record Using Structure
How to write a C Program To Make Employee Payment Record Using Structure in C Programming Language ?
Solution For C Program :
/*C Program To Make Employee Payment Record Using Structure.*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct employee
{
int bs,att;
char name[10];
};
struct employee emp[10];
void main()
{
int i;
float ded,da,hra,net,gross,sal;
clrscr();
for(i=1;i<4;i++)
{
printf("enter the name of %d employee: ",i);
scanf("%s",emp[i].name);
printf("enter the attendence of preset month = ");
scanf("%d",&emp[i].att);
printf("enter the basic salary =");
scanf("%d",&emp[i].bs);
}
printf("\n\ndata stored are :\n");
for(i=1;i<4;i++)
{
printf("Name of %d employee: %s\n",i,emp[i].name);
sal=(emp[i].bs/30)*emp[i].att;
da=sal*0.1;
hra=sal*0.2;
gross=sal+da+hra;
ded=gross*0.1;
net=gross-ded;
printf("Gross salary =%f\n",gross);
printf("Net salary =%f\n",net);
}
getch();
}
You may also learn these C Program/Code :
C Program To Swap Two Numbers Without Using Third Variable
C Program To Store Students Record Using Structure
How to write a C Program To Store Students Record Using Structure in C Programming Language ?
Solution For C Program :
/*C Program To Store Students Record Using Structure.*/
#include<stdio.h>
#include<conio.h>
struct student{
int role_no;
char name[20];
int marks;
char course[20];
};
struct student stud[10];
void main()
{
int i;
clrscr();
printf("enter the students record one by one.\n");
for(i=0;i<3;i++)
{
printf("Enter the role no= ");
scanf("%d",&stud[i].role_no);
printf("Enter the name of student: ");
scanf("%s",&stud[i].name);
printf("Enter the marks obtained= ");
scanf("%d",&stud[i].marks);
printf("Enter the course: ");
scanf("%s",&stud[i].course);
}
clrscr();
printf("---------STUDENTS RECORD FILE-------\n");
for(i=0;i<3;i++)
{
printf("\nROLE NO.: %d",stud[i].role_no);
printf("\nNAME: %s",stud[i].name);
printf("\nCOURSE: %s",stud[i].course);
printf("\nMARKS OBTAINED: %d",stud[i].marks);
printf("\n----------------------------------\n\n");
}
getch();
}
You may also learn these C Program/Code :
C Program To Swap Two Numbers Without Using Third Variable
Generic stack in C Program
How to Declares a stack structure and functions generically using a C macro in C Programming Language ?
Solution:
#ifndef __ETS_STACK__ #define __ETS_STACK__ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dbg.h> // Contains function exitWithMessage /* DESCRIPTION: Declares a stack structure and functions generically using a C macro. NORMAL TYPE USAGE: (int, char, float, ...) DEFINE_STACK(float) // Put this in the correct scope (global probably). Stack_float stack1; Stack_float_init( &stack1 , 10 ); // Initialize with maximum capacity being 10. Stack_float_push( &stack1, (float)5); // Pushes the float value into stack1 float a = Stack_float_pop( &stack1 ); printf("%f", a); // Will print 5.0000... Stack_float_free( &stack1 ); POINTER TYPE USAGE: (char*, string, ...) typedef char* string DEFINE_STACK(string) // TYPE can't contain a '*' token, so typedef to bypass restriction. Stack_string this_is_another_stack; Stack_string_init( &this_is_another_stack, 1 ); // Initialize with maximum capacity being 1. string test = (string) malloc(5 * sizeof(char)); // If not on heap then BAD things can happen, (but whatever i don't judge). test[0] = 'h'; // (Just don't free a variable on the stack) test[1] = 'e'; test[2] = 'y'; test[3] = '\0'; Stack_string_push( &this_is_another_stack, test); string temp = Stack_string_pop( &this_is_another_stack); printf("%s", temp); // Prints "hey" free(temp); // REMEMBER to free elements after poping to prevent memory leaks. Stack_string_free( &this_is_another_stack ); */ #define DEFINE_STACK(TYPE) \ \ typedef struct{ \ TYPE *array; \ int top; \ int capacity; \ }Stack_##TYPE##; \ \ void Stack_##TYPE##_init(Stack_##TYPE *stack, int capacity){ \ stack->top=-1; \ stack->capacity = capacity; \ stack->array = ( TYPE *)calloc(stack->capacity, sizeof( TYPE )); \ } \ \ void Stack_##TYPE##_push(Stack_##TYPE *stack, TYPE data){ \ if(stack->top < stack->capacity) stack->array[++(stack->top)] = data; \ else exitWithMessage("ERROR: too many items for stack."); \ } \ \ TYPE Stack_##TYPE##_pop(Stack_##TYPE *stack){ \ if(stack->top >= 0) { \ TYPE var = stack->array[stack->top--]; \ stack->array[stack->top+1] = 0; \ return var; \ } else exitWithMessage("ERROR: can't pop, no items in stack."); \ } \ \ void Stack_##TYPE##_free(Stack_##TYPE *stack){ \ free(stack->array); \ } \ #endif // !__ETS_STACK__
C Program To Multiply Two Polynomials
How to in Write a C program to multiply two polynomials in C Programming Language ?
Solution:
/*
Write a C program to multiply two polynomials.
*/
C Program LEXICAL ANALYSER
How to write a C Program Lexical Analyser in C Programming Language ?
Soution:
/*Implement Lexical Analyse program in C*/
C Program Implement Binary Search Tree And Its Traversals
How to write a c program binary tree and its traversals in C Programming Language ?
https://en.wikipedia.org/wiki/Tree_traversal
Solution:
/* Binary tree and its traversals */
#include <stdio.h>
#include <stdlib.h>
struct btree* create(struct btree*, int);
void inorder(struct btree*);
void preorder(struct btree*);
void postorder(struct btree*);
void levelorder(struct btree*);
int l=0,r=0,i;
struct btree
{
int data;
struct btree *lptr, *rptr;
};
int main()
{
struct btree *root;
root=NULL;
int value,b,n;
do
{
printf("\nCase options\n1->Enter elements into btree\n2->Inorder print\n3->Preorder print\n4->Postorder print\n5->Levelorder print\n0->Exit\n");
scanf("%d",&b);
switch(b)
{
case 1: printf("\nHow many elements u want to enter the elements in the btree\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the value into the btree\n");
scanf("%d",&value);
root = create(root,value);
}
printf("No. of nodes:\nTo left: %d\nTo Right: %d\nIn Totality: %d\n",l,r, (l+r+1) );
break;
case 2: printf("\n Inorder print\n");
inorder(root);
break;
case 3: printf("\n Pre order print\n");
preorder(root);
break;
case 4: printf("\n Post order print\n");
postorder(root);
break;
case 5: printf("\n Level order print\n");
levelorder(root);
break;
case 0: break;
}
if( b==0)
exit (0);
}
while(b!=0);
}
struct btree* create(struct btree *root, int value)
{
struct btree *temp,*temp1;
struct btree *nn;
if(root == NULL)
{
printf("\nThe newnode is the root node\n");
nn = (struct btree*)malloc(sizeof(struct btree));
nn->data = value;
nn->lptr = NULL;
nn->rptr = NULL;
root=nn;
}
else if (root != NULL)
{
temp = root;
while (temp != NULL)
{
temp1=temp;
if(temp->data >= value)
{
if (temp->data != value)
temp= temp->lptr;
else
{
printf("\nRe-enter a unique value\n");
i--;
break;
}
}
else if(temp->data <= value)
{
if(temp->data != value)
temp= temp->rptr;
else
{
printf("\nRe-enter a unique value\n");
i--;
break;
}
}
}
if(temp1->data >value)
{
temp1->lptr= (struct btree*)malloc (sizeof(struct btree*));
l++;
temp1=temp1->lptr;
temp1->data=value;
temp1->lptr=temp1->rptr=NULL;
}
if(temp1->data <value)
{
temp1->rptr= (struct btree*)malloc (sizeof(struct btree*));
r++;
temp1=temp1->rptr;
temp1->data=value;
temp1->lptr=temp1->rptr=NULL;
}
}
return root;
}
void inorder (struct btree* root)
{
if( root !=NULL)
{
inorder(root->lptr);
printf("%d\n", root->data);
inorder(root->rptr);
}
}
void preorder (struct btree* root)
{
if( root !=NULL)
{
printf("%d\n", root->data);
preorder(root->lptr);
preorder(root->rptr);
}
}
void postorder (struct btree* root)
{
if( root !=NULL)
{
postorder(root->lptr);
postorder(root->rptr);
printf("%d\n", root->data);
}
}
void levelorder (struct btree* root)
{
static struct btree *t1, *t2;
t1=root;
printf("%d\n", root->data);
levelorder(t1->lptr);
printf("%d\n", t1->data);
t2=root;
levelorder(t2->rptr);
printf("%d\n", t2->data);
}
GJK C Program Example-1
GJK C Program Example-1
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <stdbool.h>
#include "vector3.h"
typedef struct TSimplex {
TVec3 points[4];
int size;
} TSimplex;
typedef enum EShapeType {
CS_SPHERE,
CS_CONVEX,
} EShapeType;
typedef struct TConvexShape {
TVec3 * points;
int count;
int type;
float radius; // for sphere
} TConvexShape;
// ===========================
// HELPERS
// ===========================
bool Helper_SameDirection( TVec3 a, TVec3 b ) {
return Vec3_Dot( a, b ) > 0;
}
// ===========================
// SIMPLEX ROUTINE
// ===========================
void Simplex_RemovePoint( TSimplex * s, int num ) {
if( s->size > 0 ) {
if( num == 0 ) {
s->points[0] = s->points[1];
s->points[1] = s->points[2];
s->points[2] = s->points[3];
}
if( num == 1 ) {
s->points[1] = s->points[2];
s->points[2] = s->points[3];
}
if( num == 2 ) {
s->points[2] = s->points[3];
}
s->size--;
}
}
void Simplex_AddPoint( TSimplex * s, TVec3 p ) {
if( s->size < 3 ) {
s->points[ s->size ] = p;
s->size++;
}
}
// ===========================
// CONVEX SHAPE ROUTINE
// ===========================
void ConvexShape_CreateTriangle( TConvexShape * shape, TVec3 a, TVec3 b, TVec3 c ) {
shape->count = 3;
shape->points = malloc( shape->count * sizeof( TVec3 ));
shape->points[0] = a;
shape->points[1] = b;
shape->points[2] = c;
shape->type = CS_CONVEX;
shape->radius = 0;
}
void ConvexShape_CreateTetrahedron( TConvexShape * shape, TVec3 a, TVec3 b, TVec3 c, TVec3 d ) {
shape->count = 4;
shape->points = malloc( shape->count * sizeof( TVec3 ));
shape->points[0] = a;
shape->points[1] = b;
shape->points[2] = c;
shape->points[3] = d;
shape->type = CS_CONVEX;
shape->radius = 0;
}
void ConvexShape_CreateSphere( TConvexShape * shape, TVec3 position, float radius ) {
shape->count = 1;
shape->points = malloc( shape->count * sizeof( TVec3 ));
shape->points[ 0 ] = position;
shape->type = CS_SPHERE;
shape->radius = radius;
}
TVec3 ConvexShape_GetFarthestPointInDirection( TConvexShape * shape, TVec3 dir ) {
if( shape->type == CS_CONVEX ) {
TVec3 farthest;
float lastDot = -FLT_MAX;
for( int i = 0; i < shape->count; i++ ) {
float dot = Vec3_Dot( dir, shape->points[i] );
if( dot > lastDot ) {
farthest = shape->points[i];
lastDot = dot;
}
}
return farthest;
} else {
if( fabs( dir.x ) < 0.000001 &&
fabs( dir.y ) < 0.000001 &&
fabs( dir.z ) < 0.000001 ) {
printf( "Warn! Zero dir passed!\n" );
}
TVec3 dn = Vec3_Normalize( dir );
return Vec3_Add( shape->points[0], Vec3_Scale( dn, shape->radius ));
}
}
// ===========================
// GJK ALGORITHM ROUTINE
// ===========================
TVec3 GJK_GetSupport( TConvexShape * shape1, TConvexShape * shape2, TVec3 dir ) {
return Vec3_Sub( ConvexShape_GetFarthestPointInDirection( shape1, dir ), ConvexShape_GetFarthestPointInDirection( shape2, Vec3_Negate( dir )));
}
bool GJK_ProcessLine( TSimplex * simplex, TVec3 * outDirection ) {
TVec3 a = simplex->points[1];
TVec3 b = simplex->points[0];
TVec3 ab = Vec3_Sub( b, a );
TVec3 aO = Vec3_Negate( a );
if( Helper_SameDirection( ab, aO )) {
*outDirection = Vec3_Cross( Vec3_Cross( ab, aO ), ab );
} else {
Simplex_RemovePoint( simplex, 0 );
*outDirection = aO;
}
return false;
}
bool GJK_ProcessTriangle( TSimplex * simplex, TVec3 * outDirection ) {
TVec3 a = simplex->points[2];
TVec3 b = simplex->points[1];
TVec3 c = simplex->points[0];
TVec3 aO = Vec3_Negate( a );
TVec3 ab = Vec3_Sub( b, a );
TVec3 ac = Vec3_Sub( c, a );
TVec3 abPerp = Vec3_Cross( Vec3_Cross( ac, ab ), ab );
TVec3 acPerp = Vec3_Cross( Vec3_Cross( ab, ac ), ac );
if( Helper_SameDirection( abPerp, aO )) {
Simplex_RemovePoint( simplex, 0 );
*outDirection = abPerp;
} else {
if( Helper_SameDirection( acPerp, aO )) {
Simplex_RemovePoint( simplex, 1 );
*outDirection = acPerp;
} else {
return true;
}
}
return false;
}
bool GJK_ProcessTetrahedron( TSimplex * simplex, TVec3 * outDirection ) {
TVec3 a = simplex->points[3];
TVec3 b = simplex->points[2];
TVec3 c = simplex->points[1];
TVec3 d = simplex->points[0];
TVec3 ac = Vec3_Sub( c, a );
TVec3 ab = Vec3_Sub( b, a );
TVec3 ad = Vec3_Sub( d, a );
TVec3 acd = Vec3_Cross( ad, ac );
TVec3 abd = Vec3_Cross( ab, ad );
TVec3 abc = Vec3_Cross( ac, ab );
TVec3 aO = Vec3_Negate( a );
if( Helper_SameDirection( abc, aO )) {
if( Helper_SameDirection( Vec3_Cross( abc, ac ), aO )) {
Simplex_RemovePoint( simplex, 2 );
Simplex_RemovePoint( simplex, 0 );
*outDirection = Vec3_Cross( Vec3_Cross( ac, aO ), ac );
} else if( Helper_SameDirection( Vec3_Cross( ab, abc ), aO )) {
Simplex_RemovePoint( simplex, 1 );
Simplex_RemovePoint( simplex, 0 );
*outDirection = Vec3_Cross( Vec3_Cross( ab, aO ), ab );
} else {
Simplex_RemovePoint( simplex, 0 );
*outDirection = abc;
}
} else if( Helper_SameDirection( acd, aO )) {
if( Helper_SameDirection( Vec3_Cross( acd, ad ), aO )) {
Simplex_RemovePoint( simplex, 2 );
Simplex_RemovePoint( simplex, 1 );
*outDirection = Vec3_Cross( Vec3_Cross( ad, aO ), ad );
} else if ( Helper_SameDirection( Vec3_Cross( ac, acd ), aO )) {
Simplex_RemovePoint( simplex, 2 );
Simplex_RemovePoint( simplex, 0 );
*outDirection = Vec3_Cross( Vec3_Cross( ac, aO ), ac );
} else {
Simplex_RemovePoint( simplex, 2 );
*outDirection = acd;
}
} else if( Helper_SameDirection( abd, aO )) {
if( Helper_SameDirection( Vec3_Cross( abd, ab ), aO )) {
Simplex_RemovePoint( simplex, 1 );
Simplex_RemovePoint( simplex, 0 );
*outDirection = Vec3_Cross( Vec3_Cross( ab, aO ), ab );
} else if( Helper_SameDirection( Vec3_Cross( ad, abd ), aO )) {
Simplex_RemovePoint( simplex, 2 );
Simplex_RemovePoint( simplex, 1 );
*outDirection = Vec3_Cross( Vec3_Cross( ad, aO ), ad );
} else {
Simplex_RemovePoint( simplex, 1 );
*outDirection = abd;
}
} else {
return true;
}
return false;
}
bool GJK_ProcessSimplex( TSimplex * simplex, TVec3 * outDirection ) {
if( simplex->size == 2 ) {
return GJK_ProcessLine( simplex, outDirection );
} else if ( simplex->size == 3 ) {
return GJK_ProcessTriangle( simplex, outDirection );
} else {
return GJK_ProcessTetrahedron( simplex, outDirection );
}
}
bool GJK_IsIntersects( TConvexShape * shape1, TConvexShape * shape2 ) {
TVec3 dir = Vec3_Set( 0, 1, 0 );
TSimplex simplex = { 0 };
Simplex_AddPoint( &simplex, GJK_GetSupport( shape1, shape2, dir ));
dir = Vec3_Negate( dir );
int convergenceLimit = 45;
for( int i = 0; i < convergenceLimit; i++ ) {
TVec3 lastSupport = GJK_GetSupport( shape1, shape2, dir );
if( Helper_SameDirection( dir, lastSupport )) {
Simplex_AddPoint( &simplex, lastSupport );
if( GJK_ProcessSimplex( &simplex, &dir )) {
printf( "Intersection! %d iteration(s)!\n", i );
return true;
}
} else {
printf( "No intersection! %d iteration(s)!\n", i );
return false;
}
}
printf( "No intersection! Convergence limit has reached!\n" );
return false;
}
int main(int argc, char **argv) {
{
printf( "Triangle-Triangle Intersection Test - " );
TConvexShape shape1, shape2;
ConvexShape_CreateTriangle( &shape1, Vec3_Set( 0, 0, 0 ), Vec3_Set( 0, 1, 0 ), Vec3_Set( 1, 0, 0 ));
ConvexShape_CreateTriangle( &shape2, Vec3_Set( 0, 0.5, 0 ), Vec3_Set( 0, 1.5, 1 ), Vec3_Set( 1, 0.5, 1 ));
GJK_IsIntersects( &shape1, &shape2 );
}
{
printf( "Triangle-Tetrahedron Intersection Test - " );
TConvexShape shape1, shape2;
ConvexShape_CreateTriangle( &shape1, Vec3_Set( 0, 0, 0.5 ), Vec3_Set( 0, 1, 0.5 ), Vec3_Set( 1, 0, 0.5 ));
ConvexShape_CreateTetrahedron( &shape2, Vec3_Set( 0, 0, 0 ), Vec3_Set( 0, 1, 0 ), Vec3_Set( 1, 0, 0 ), Vec3_Set( 0, 0, 1 ));
GJK_IsIntersects( &shape1, &shape2 );
}
{
{
printf( "Sphere-Tetrahedron Intersection Test Without Small Offset - " );
TConvexShape shape1, shape2;
ConvexShape_CreateSphere( &shape1, Vec3_Set( 0,0,0 ), 1 );
ConvexShape_CreateTetrahedron( &shape2, Vec3_Set( 0, 0, 0 ), Vec3_Set( 0, 1, 0 ), Vec3_Set( 1, 0, 0 ), Vec3_Set( 0, 0, 1 ));
GJK_IsIntersects( &shape1, &shape2 );
}
{
printf( "Sphere-Tetrahedron Intersection Test With Small Offset - " );
TConvexShape shape1, shape2;
ConvexShape_CreateSphere( &shape1, Vec3_Set( 0.0001, 0, 0 ), 1 );
ConvexShape_CreateTetrahedron( &shape2, Vec3_Set( 0, 0, 0 ), Vec3_Set( 0, 1, 0 ), Vec3_Set( 1, 0, 0 ), Vec3_Set( 0, 0, 1 ));
GJK_IsIntersects( &shape1, &shape2 );
}
}
{
printf( "Tetrahedron-Tetrahedron Intersection Test - " );
TConvexShape shape1, shape2;
ConvexShape_CreateTetrahedron( &shape1, Vec3_Set( 0, 0, 0.5 ), Vec3_Set( 0, 1, 0.5 ), Vec3_Set( 1, 0, 0.5 ), Vec3_Set( 0, 0, 1.5 ));
ConvexShape_CreateTetrahedron( &shape2, Vec3_Set( 0, 0, 0 ), Vec3_Set( 0, 1, 0 ), Vec3_Set( 1, 0, 0 ), Vec3_Set( 0, 0, 1 ));
GJK_IsIntersects( &shape1, &shape2 );
}
{
printf( "Sphere-Sphere Intersection Test - " );
TConvexShape shape1, shape2;
ConvexShape_CreateSphere( &shape1, Vec3_Set( 1,0,0 ), 1 );
ConvexShape_CreateSphere( &shape2, Vec3_Set( 0,0,0 ), 1 );
GJK_IsIntersects( &shape1, &shape2 );
}
return 0;
}
Adding two polynomial functions C Program Using Structure
How to write a C Program to Adding Two Polynomial Functions in C Programming Language ?
Solution:
/*Adding two polynomial functions*/
#include <stdio.h>
#include<stdlib.h>
struct poly* link(struct poly*);
void display(struct poly*);
struct poly* addlink(struct poly*,struct poly*, struct poly*);
struct poly
{
int coeff, pow;
struct poly *ptr;
};
int main()
{
struct poly *head1,*head2,*head3;
int num;
head1=NULL;
head2=NULL;
head3=NULL;
while(1)
{
printf("\nEnter\n1->To create first polynomial function\n2->To create second polynomial function\n3->To display first polynomial function\n4->To display second polynomial function\n5->To add both the polynomial functions\n6->To display the new polynomial created after addition\n");
scanf("%d",&num);
switch(num)
{
case 1: head1=link(head1);
break;
case 2: head2=link(head2);
break;
case 3: display(head1);
break;
case 4: display(head2);
break;
case 5: head3=addlink(head1,head2,head3);
break;
case 6: display(head3);
break;
default: printf("\nBoss ! Enter the correct value\n");
}
}
}
struct poly* link(struct poly *head1)
{
struct poly *newnode,*temp;
int value,degree;
newnode=temp=NULL;
printf("\nEnter the coefficient of the polynomial\n");
scanf("%d",&value);
printf("\nEnter the degree for variable x\n");
scanf("%d",°ree);
newnode=(struct poly*) malloc (sizeof (struct poly));
newnode->pow=degree;
newnode->coeff=value;
temp=head1;
if(temp==NULL)
{
printf("\nThe first node is created\n");
newnode->ptr=NULL;
return newnode;
}
else
{
printf("\nThe next node is being linked\n");
temp->ptr=newnode;
temp=temp->ptr;
return head1;
}
}
void display(struct poly* head)
{
if(head == NULL)
{
printf("\nThe polynomial function is not created.\nPlease create a new polynomial function.\n");
}
while(head != NULL && head->ptr != NULL)
{
printf("The polynomial function has been detected\n");
printf("%dx^%d+",head->coeff,head->pow);
head=head->ptr;
}
if(head->ptr == NULL)
{
// printf("\nEntering the last node\n");
printf("%dx^%d",head->coeff,head->pow);
head=head->ptr;
}
}
struct poly* addlink(struct poly* head,struct poly* tail,struct poly *head3 )
{
struct poly *temp1,*temp,*newnode;
temp=newnode=temp1=head3=NULL;
newnode=( struct poly*) malloc(sizeof(struct poly));
if( head == NULL || tail == NULL)
{
printf("\nYou have no node to get added\n");
}
if(head !=NULL && tail == NULL)
{
printf("\nThe existing first polynomial is the final polynomial\n");
return head;
}
if(head == NULL && tail !=NULL)
{
printf("\nThe existing second polynomial is the final polynomial\n");
return tail;
}
head3=newnode;
if(head3==NULL)
{
printf("\nEnter a node first\n");
}
if(head3 != NULL)
{
while(head !=NULL && tail !=NULL)
{
if(head->pow > tail->pow)
{
temp=tail;
temp1=head;
while((head->pow) > (temp->pow))
{
printf("\nThe element's degree in first poly. is greater than the second\n");
if(temp->ptr == NULL)
{
newnode->coeff=temp->coeff;
newnode->pow=temp->pow;
newnode->ptr=NULL;
head3=newnode;
return head3;
temp1=temp1->ptr;
}
temp=temp->ptr;
}
printf("\nYou have come to the end of the tail pointer\n");
}
if(tail->pow > head->pow)
{
temp=head;
temp1=tail;
while((tail->pow) > (temp->pow))
{
printf("\nThe element's degree in second poly. is greater than the first\n");
if(temp->ptr ==NULL)
{
newnode->coeff=temp->coeff;
newnode->pow=temp->pow;
newnode->ptr=NULL;
head3=newnode;
return head3;
temp1=temp1->ptr;
}
temp=temp->ptr;
}
printf("\nYou have come to the end of the tail pointer\n");
}
if(head->pow == tail->pow)
{
temp=head;
temp1=tail;
while((temp->pow == temp1->pow))
{
newnode->coeff = (temp->coeff + tail->coeff);
newnode->pow=temp->pow;
head3=newnode;
return head3;
temp=temp->ptr;
temp1=temp1->ptr;
}
}
}
}
}
Subscribe to:
Posts (Atom)