Prog 1&prog 9
Prog 1&prog 9
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define NUM_DAYS_IN_WEEK 7
int main()
{
// Create the calendar
DAYTYPE *weeklyCalendar = fnCreateCal();
return 0;
}
DAYTYPE *fnCreateCal()
{
DAYTYPE *calendar = (DAYTYPE *)malloc(NUM_DAYS_IN_WEEK * sizeof(DAYTYPE));
for(int i = 0; i < NUM_DAYS_IN_WEEK; i++)
{
calendar[i].acDayName = NULL;
calendar[i].iDate = 0;
calendar[i].acActivity = NULL;
}
return calendar;
}
if(tolower(cChoice) == 'n')
continue;
printf("Date: ");
scanf("%d", &calendar[i].iDate);
printf("Activity: ");
char activityBuffer[100];
scanf(" %[^n]", activityBuffer); // Read the entire line, including
spaces
calendar[i].acActivity = strdup(activityBuffer);
printf("n");
getchar(); //remove trailing enter character in input buffer
}
}
Output:
Do you want to enter details for day 1 [Y/N]: N
Do you want to enter details for day 2 [Y/N]: Y
Day Name: Monday
Date: 10
Activity: Meeting with Chairman.
Day 2:
Day Name: Monday
Date: 10
Activity: Meeting with Chairman.
Day 3:
No Activity
Day 4:
No Activity
Day 5:
Day Name: Thursday
Date: 13
Activity: Product Survey
Day 6:
Day Name: Friday
Date: 14
Activity: Budget Breakdown and Planning
Day 7:
Day Name: Saturday
Date: 15
Activity: Outing with family
9. Develop a Program in C for the following operationson Singly Circular Linked List
(SCLL)
with header nodes
a. Represent and Evaluate a Polynomial P(x,y,z) = 6x2y2z-4yz5+3x3yz+2xy5z-2xyz3
b. Find the sum of two polynomials POLY1(x,y,z) and POLY2(x,y,z) and store the result
in POLYSUM(x,y,z)
Support the program with appropriate functions for each of the above operations
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
POLYPTR fnInsertTerm(POLYPTR poly, int coef, int pow_x, int pow_y, int pow_z)
{
POLYPTR cur;
POLYPTR newNode = (POLYPTR)malloc(sizeof(struct PolyTerm));
newNode->coefficient = coef;
newNode->pow_x = pow_x;
newNode->pow_y = pow_y;
newNode->pow_z = pow_z;
newNode->next = NULL;
cur = poly;
while(cur->next != poly)
{
cur = cur->next;
}
cur->next = newNode;
newNode->next = poly;
return poly;
}
result += termValue;
cur = cur->next;
} while (cur != poly);
return result;
}
do
{
polySum = fnInsertTerm(polySum, cur1->coefficient, cur1->pow_x, cur1-
>pow_y, cur1->pow_z);
cur1 = cur1->next;
}while(cur1 != poly1);
do
{
cur1 = polySum->next;
bool bMatchFound = false;
do
{
if(fnMatchTerm(cur1, cur2))
{
cur1->coefficient += cur2->coefficient;
bMatchFound = true;
break;
}
cur1 = cur1->next;
}while(cur1 != polySum);
if(!bMatchFound)
{
polySum = fnInsertTerm(polySum, cur2->coefficient, cur2->pow_x,
cur2->pow_y, cur2->pow_z);
}
cur2 = cur2->next;
}while(cur2 != poly2);
return polySum;
int main()
{
POLYPTR poly1 = (POLYPTR)malloc(sizeof(struct PolyTerm));
poly1->next = poly1;
POLYPTR poly2 = (POLYPTR)malloc(sizeof(struct PolyTerm));
poly2->next = poly2;
POLYPTR polySum = (POLYPTR)malloc(sizeof(struct PolyTerm));
polySum->next = polySum;
return 0;
}
Output:
POLY1(x, y, z) = 6x^2y^2z^1 + 4x^0y^1z^5 + 3x^3y^1z^1 + 2x^1y^5z^1 +
2x^1y^1z^3
POLY2(x, y, z) = 1x^1y^1z^1 + 4x^3y^1z^1