20 C Programs With Output
20 C Programs With Output
Hello World
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
Output: Sum: 8
Output: a: 3, b: 5
Output: Even
6. Fibonacci Series
#include <stdio.h>
int main() {
int n = 5, t1 = 0, t2 = 1, next;
for(int i = 1; i <= n; i++) {
printf("%d ", t1);
next = t1 + t2;
t1 = t2;
t2 = next;
}
return 0;
}
Output: 0 1 1 2 3
7. Reverse a Number
#include <stdio.h>
int main() {
int n = 123, rev = 0;
while(n != 0) {
rev = rev * 10 + n % 10;
n /= 10;
}
printf("Reversed: %d", rev);
return 0;
}
Output: Prime
9. Find GCD
#include <stdio.h>
int main() {
int a = 48, b = 18;
while(a != b) {
if(a > b) a -= b;
else b -= a;
}
printf("GCD: %d", a);
return 0;
}
Output: GCD: 6
Output: LCM: 20
Output: olleh
Output: Digits: 5
Output: Armstrong
Output: Palindrome
Output: Result: 8
Output: A: 65 ... Z: 90
Output: Power: 8
Output: 5 x 1 = 5 ... 5 x 10 = 50
Output: Sum: 6
Output: Largest: 20