0% found this document useful (0 votes)
6 views4 pages

Codes

The document contains multiple C programs that perform different tasks: generating a multiplication table, creating Floyd's Triangle, calculating the sine of an angle using a series expansion, and checking if a number is a perfect number. Each program prompts the user for input and displays the corresponding output. The code snippets demonstrate basic programming concepts such as loops, functions, and conditional statements.

Uploaded by

advaithshetty33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Codes

The document contains multiple C programs that perform different tasks: generating a multiplication table, creating Floyd's Triangle, calculating the sine of an angle using a series expansion, and checking if a number is a perfect number. Each program prompts the user for input and displays the corresponding output. The code snippets demonstrate basic programming concepts such as loops, functions, and conditional statements.

Uploaded by

advaithshetty33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <stdio.

h>

int main() {
int n, k;
printf("Enter the number of rows (n) and columns (k)
for the multiplication table: ");
scanf("%d %d", &n, &k);

printf("Multiplication Table:\n");
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
printf("%d\t", i * j);
}
printf("\n");
}

return 0;
}
#include <stdio.h>

int main() {
int N, num = 1;
printf("Enter the number of rows
for Floyd's Triangle: ");
scanf("%d", &N);

printf("Floyd's Triangle:\n");
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= i; j++) {
printf("%d ", num++);
}
printf("\n");
}

return 0;
}
#include <stdio.h>
#include <math.h>

double factorial(int n) {
double fact = 1;
for (int i = 1; i <= n; i++) {
fact *= i;
}
return fact;
}

double sineSeries(double x, int n) {


double sum = 0;
int sign = 1;

for (int i = 1; i <= n; i += 2) {


sum += sign * (pow(x, i) / factorial(i));
sign *= -1;
}

return sum;
}

int main() {
double x;
int terms;

printf("Enter the value of x (in radians): ");


scanf("%lf", &x);
printf("Enter the number of terms for the sine series: ");
scanf("%d", &terms);

printf("sin(%.2lf) ≈ %.6lf\n", x, sineSeries(x, terms));

return 0;
#include <stdio.h>

int isPerfectNumber(int num) {


int sum = 0;
for (int i = 1; i <= num / 2; i++) {
if (num % i == 0) {
sum += i;
}
}
return sum == num;
}

int main() {
int num;
printf("Enter a number to check if it is a perfect number: ");
scanf("%d", &num);

if (isPerfectNumber(num)) {
printf("%d is a perfect number.\n", num);
} else {
printf("%d is not a perfect number.\n", num);
}

return 0;
}

You might also like