0% found this document useful (0 votes)
11 views2 pages

Important C Programs

The document contains several important C programs including a Hello World program, a program to check if a number is even or odd, a program to calculate the factorial of a number, a prime number checker, and a Fibonacci series generator. Each program is presented with its code and a brief description of its functionality. These examples serve as fundamental exercises for learning C programming.
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)
11 views2 pages

Important C Programs

The document contains several important C programs including a Hello World program, a program to check if a number is even or odd, a program to calculate the factorial of a number, a prime number checker, and a Fibonacci series generator. Each program is presented with its code and a brief description of its functionality. These examples serve as fundamental exercises for learning C programming.
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

Important C Programs

Hello World Program


#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}

Check Even or Odd


#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
if (num % 2 == 0)
printf("%d is even.", num);
else
printf("%d is odd.", num);
return 0;
}

Factorial of a Number
#include <stdio.h>
int main() {
int n, i;
unsigned long long fact = 1;
printf("Enter an integer: ");
scanf("%d", &n);
for(i = 1; i <= n; ++i) {
fact *= i;
}
printf("Factorial of %d = %llu", n, fact);
return 0;
}

Prime Number Check


#include <stdio.h>
int main() {
int n, i, flag = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
for (i = 2; i <= n / 2; ++i) {
if (n % i == 0) {
flag = 1;
break;
}
}
if (n == 1)
printf("1 is neither prime nor composite.");
else {
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
}
return 0;
}
Fibonacci Series
#include <stdio.h>
int main() {
int n, t1 = 0, t2 = 1, nextTerm, i;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (i = 1; i <= n; ++i) {
printf("%d, ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
}
return 0;
}

You might also like