0% found this document useful (0 votes)
11 views1 page

Include

Uploaded by

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

Include

Uploaded by

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

#include <stdio.

h>
// Recursive function to calculate sum of first n natural numbers
int sum(int n) {
if (n == 0) {
return 0; // Base case }
return n + sum(n - 1); // Recursive step
}
int main() {
int n;
printf("Enter a positive integer: ");
scanf("%d", &n);
// Calculate and display the sum
printf("The sum of the first %d natural numbers is: %d\n", n, sum(n));
return 0;
}

#include <stdio.h>
int main() {
int num, i;
unsigned long long factorial = 1;
printf("Enter a positive integer: ");
scanf("%d", &num);
if (num < 0) {
printf("Factorial is not defined for negative numbers.\n");
} else {
for (i = 1; i <= num; i++) {
factorial *= i;}
printf("Factorial of %d = %llu\n", num, factorial); }
return 0;
}
#include <stdio.h>
int main() {
int n, a = 0, b = 1, next, i = 1;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
while (i <= n) {
printf("%d ", a);
next = a + b;
a = b;
b = next;
i++; }
return 0;
}
#include <stdio.h>
int main() {
int n, a = 0, b = 1, next, i;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (i = 1; i <= n; i++) {
printf("%d ", a);
next = a + b;
a = b;
b = next; }
return 0;
}
#include <stdio.h>
int main() {
int n, a = 0, b = 1, next, i = 1;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
do {
printf("%d ", a);
next = a + b;
a = b;
b = next;
i++;
} while (i <= n);
return 0;
}
#include <stdio.h>
void add(int a, int b) { printf("%d\n", a + b); }
int main() {
int x = 5, y = 10;
add(x, y); // Call by value
return 0;
}
#include <stdio.h>
void add(int *a, int *b) { printf("%d\n", *a + *b); }
int main() {
int x = 5, y = 10;
add(&x, &y); // Call by reference
return 0;
}
#include <stdio.h>//Entry Control Loop)
int main() {
int i;
for (i = 1; i <= 5; i++) {
printf("%d ", i);
}
return 0;
}
#include <stdio.h>//Exit Control Loop
int main() {
int i = 1;
do {
printf("%d ", i);
i++;
} while (i <= 5);
return 0;
}

You might also like