C Demo Programs
C Demo Programs
#include <stdio.h>
int main() {
char c;
scanf("%c", &c);
return 0;
Output:
Enter a character: 4
ASCII value of 4 = 52
Q2. C Program to Find the Size of int, float, double and char.
#include<stdio.h>
int main() {
int intType;
float floatType;
double doubleType;
char charType;
Output:
#include<stdio.h>
int main() {
scanf("%lf", &first);
scanf("%lf", &second);
temp = first;
first = second;
second = temp;
Output:
#include <stdio.h>
int main() {
Output:
#include <math.h>
#include <stdio.h>
int main() {
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
else if (discriminant == 0) {
}
// if roots are not real
else {
realPart = -b / (2 * a);
return 0;
Output:
#include <stdio.h>
int main() {
int n, i, sum = 0;
scanf("%d", &n);
sum += i;
return 0;
Output:
Sum = 15
Q7. C Program to Find Factorial of a Number.
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
if (n < 0)
else {
fact *= i;
return 0;
Output:
Enter an integer: 8
Factorial of 8 = 40320
#include <stdio.h>
int main() {
int i, n;
// initialize first and second terms
int t1 = 0, t2 = 1;
scanf("%d", &n);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
return 0;
Output:
Fibonacci Series: 0, 1, 1, 2
#include <stdio.h>
int main() {
scanf("%d", &n);
while (n != 0) {
remainder = n % 10;
n /= 10;
return 0;
Output:
#include <stdio.h>
int main() {
original = n;
while (n != 0) {
remainder = n % 10;
n /= 10;
if (original == reversed)
else
return 0;
1221 is a palindrome.
#include<stdio.h>
int main() {
int n;
return 0;
if (n>=1)
return n*multiplyNumbers(n-1);
else
return 1;
Output:
Factorial of 6 = 720
#include <stdio.h>
#include <math.h>
// function prototype
int main() {
long long n;
scanf("%lld", &n);
return 0;
}
// function definition
while (n!=0) {
rem = n % 10;
n /= 10;
++i;
return dec;
Output:
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
while (n > 100 || n < 1) {
scanf("%d", &n);
scanf("%f", &num[i]);
sum += num[i];
avg = sum / n;
return 0;
Output:
1. Enter number: 2
2. Enter number: 3
3. Enter number: 5
4. Enter number: 6
Average = 4.00
#include <stdio.h>
int main() {
scanf("%d", &r);
printf("Enter the number of columns (between 1 and 100): ");
scanf("%d", &c);
scanf("%d", &a[i][j]);
scanf("%d", &b[i][j]);
if (j == c - 1) {
printf("\n\n");
return 0;
Output:
2 4
6 8
**
***
****
*****
#include <stdio.h>
int main() {
int i, j, rows;
scanf("%d", &rows);
printf("* ");
printf("\n");
return 0;