Document 6
Document 6
Institute of Technology,
Allahabad
Week 6 Assignment
Output:
Program 2:
#include <stdio.h>
// Main function
int main() {
int number;
// Call the function to find the sum of digits and print the result
printf("Sum of digits of %d is: %d\n", number, sumOfDigits(number));
return 0;
}
Output:
Program 3:
#include <stdio.h>
int main() {
int month;
return 0;
}
Output:
Program 4:
A)Using function:
#include <stdio.h>
return result;
}
int main() {
double x;
int terms;
return 0;
}
Output:
B)Using recursive Function:
#include <stdio.h>
int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
} else {
if (currentTerm == terms) {
return 0;
} else {
// Main function
int main() {
double x;
int terms;
scanf("%lf", &x);
printf("Enter the number of terms: ");
scanf("%d", &terms);
return 0;
Output:
Program 5:
#include <stdio.h>
int main() {
int x, y, z;
return 0;
}
Output:
Program 6:
#include <stdio.h>
int main() {
int num;
return 0;
}
Output:
Program 7:
#include <stdio.h>
#include <math.h>
int main() {
double x, y;
int n;
// Check if n is non-negative
if (n < 0) {
printf("Invalid input. n should be a non-negative integer.\n");
} else {
// Calculate X^n using pow function
y = pow(x, n);
return 0;
}
Output:
Program 8:
#include <stdio.h>
printf("\n");
}
int main() {
int num;
return 0;
}
Output:
Program 9:
#include <stdio.h>
printf("\n");
}
int main() {
// Print the first 25 numbers of the Fibonacci sequence
printFibonacciSequence(25);
return 0;
}
Output:
Program 10:
#include <stdio.h>
int main() {
int decimalNumber;
return 0;
}
Output:
Program 11:
#include <stdio.h>
#include <math.h>
// Check if the sum of areas of PAB, PBC, and PAC is approximately equal to ABC
if (fabs(areaABC - (areaPAB + areaPBC + areaPAC)) < 1e-6) {
printf("The point P(%lf, %lf) lies inside the triangle ABC.\n", x, y);
printf("Distance between A and B: %lf\n", distanceAB);
printf("Distance between B and C: %lf\n", distanceBC);
printf("Distance between C and A: %lf\n", distanceCA);
printf("Area of triangle ABC: %lf\n", areaABC);
return 1;
} else {
printf("The point P(%lf, %lf) does not lie inside the triangle ABC.\n", x, y);
return 0;
}
}
int main() {
double x1, y1, x2, y2, x3, y3, x, y;
// Get user input for the vertices of the triangle (x1, y1), (x2, y2), (x3, y3)
printf("Enter the coordinates of vertex A (x1 y1): ");
scanf("%lf %lf", &x1, &y1);
// Check if the point lies inside the triangle and print the result
pointInsideTriangle(x, y, x1, y1, x2, y2, x3, y3);
return 0;
Output: