|
source,target
|
|
"#include <stdio.h> |
|
int main() { |
|
printf(""Hello, world!\n""); |
|
return 0; |
|
}","A simple C program that prints 'Hello, world!' to the console."
|
|
"#include <stdio.h> |
|
|
|
int factorial(int n) { |
|
if (n == 0) |
|
return 1; |
|
else |
|
return n * factorial(n - 1); |
|
} |
|
|
|
int main() { |
|
int n = 5; |
|
printf(""Factorial of %d is %d\n"", n, factorial(n)); |
|
return 0; |
|
}",A C program to calculate the factorial of a number using recursion.
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
int n, sum = 0; |
|
printf(""Enter a number: ""); |
|
scanf(""%d"", &n); |
|
for (int i = 1; i <= n; i++) { |
|
sum += i; |
|
} |
|
printf(""Sum of first %d natural numbers is %d\n"", n, sum); |
|
return 0; |
|
}",A C program to calculate the sum of the first 'n' natural numbers.
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
double a, b, product; |
|
printf(""Enter two numbers: ""); |
|
scanf(""%lf %lf"", &a, &b); |
|
product = a * b; |
|
printf(""Product = %.2lf"", product); |
|
return 0; }",A C Program to Multiply Two Numbers
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
|
|
printf(""Hello, World!""); |
|
|
|
return 0; |
|
}","Program to Display Hello, World!"
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
|
|
int number; |
|
|
|
printf(""Enter an integer:""); |
|
|
|
scanf(""%d"", &number); |
|
|
|
printf(""You entered: %d"", number); |
|
|
|
return 0;}",A C Program to Print an Integer
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
|
|
int number; |
|
|
|
printf(""Enter an integer:""); scanf(""%d"", &number); |
|
|
|
printf(""You entered: %d"", number); |
|
|
|
return 0; }", A Program to Print an Integer
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
|
|
char c; |
|
|
|
printf(""Enter a character:""); |
|
|
|
scanf(""%c"", &c); |
|
|
|
|
|
|
|
|
|
|
|
printf(""ASCII value of %c = %d"", c, c); |
|
|
|
return 0; }",A Program to Print SCII Value
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
|
|
int dividend, divisor, quotient, remainder; |
|
|
|
printf(""Enter dividend:""); |
|
|
|
printf(""Enter divisor:""); |
|
|
|
scanf(""%d"", ÷nd); |
|
|
|
scanf(""%d"", &divisor); |
|
|
|
|
|
|
|
quotient = dividend / divisor; |
|
|
|
|
|
|
|
|
|
|
|
remainder = dividend % divisor; |
|
|
|
printf(""Quotient = %d |
|
"", quotient); |
|
|
|
return 0; |
|
|
|
}",C Program to Compute Quotient and Remainder
|
|
" #include<stdio.h> |
|
|
|
int main() { |
|
|
|
int intType; |
|
|
|
float floatType; |
|
|
|
double doubleType; |
|
|
|
|
|
|
|
char charType; |
|
|
|
|
|
|
|
printf(""Size of int: %zu bytes |
|
"", sizeof(intType)); |
|
|
|
printf(""Size of float: %zu bytes |
|
"", sizeof(floatType)); |
|
|
|
printf(""Size of double: %zu bytes |
|
"", sizeof(doubleType)); |
|
|
|
printf(""Size of char: %zu byte |
|
"", sizeof(charType)); |
|
|
|
return 0; }","C Program to Find the Size of int, float, double and char"
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
|
|
int a; |
|
|
|
long b; |
|
|
|
long long c; |
|
|
|
double e; |
|
|
|
long double f; |
|
|
|
printf(""Size of int = %zu bytes |
|
"", sizeof(a)); |
|
|
|
printf(""Size of long int = %zu bytes |
|
"", sizeof(b)); |
|
|
|
printf(""Size of long long int = %zu bytes |
|
"", sizeof(c)); |
|
|
|
printf(""Size of double = %zu bytes |
|
"", sizeof(e)); |
|
|
|
printf(""Size of long double = %zu bytes |
|
"", sizeof(f)); |
|
|
|
return 0; |
|
|
|
}",C Program to Demonstrate the Working of Keyword long
|
|
"#include<stdio.h> |
|
|
|
int main() { |
|
|
|
double first, second, temp; |
|
|
|
printf(""Enter first number:""); |
|
|
|
scanf(""%lf"", &first); |
|
|
|
printf(""Enter second number: ""); |
|
|
|
scanf(""%lf"", &second); |
|
|
|
|
|
|
|
temp = first; |
|
|
|
|
|
|
|
first = second; |
|
|
|
|
|
|
|
second = temp; |
|
|
|
|
|
|
|
printf("" |
|
After swapping, first number = %.2lf |
|
"", first); |
|
|
|
printf(""After swapping, second number = %.2lf"", second); |
|
|
|
return 0; }",C Program to Swap Two Numbers
|
|
" #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; }",C Program to Check Whether a Number is Even or Odd
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
|
|
char c; |
|
|
|
int lowercase_vowel, uppercase_vowel; |
|
|
|
printf(""Enter an alphabet:""); |
|
|
|
scanf(""%c"", &c); |
|
|
|
|
|
|
|
lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); |
|
|
|
|
|
|
|
uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); |
|
|
|
|
|
|
|
if (lowercase_vowel || uppercase_vowel) |
|
|
|
printf(""%c is a vowel."", c); |
|
|
|
else |
|
|
|
printf(""%c is a consonant."", c); |
|
|
|
return 0;}", C Program to Check Whether a Character is a Vowel or Consonant
|
|
" #include <stdio.h> |
|
|
|
int main() { |
|
|
|
double n1, n2, n3; |
|
|
|
printf(""Enter three different numbers: ""); |
|
|
|
scanf(""%lf %lf %lf"", &n1, &n2, &n3); |
|
|
|
|
|
|
|
if(n1 >= n2 && n1 >= n3) |
|
|
|
printf(""%.2f is the largest number."", n1); |
|
|
|
|
|
|
|
if (n2 >= n1 && n2 >= n3) |
|
|
|
printf(""%.2f is the largest number."", n2); |
|
|
|
|
|
|
|
if (n3 >= n1 && n3 >= n2) |
|
|
|
printf(""%.2f is the largest number."", n3); |
|
|
|
return 0;}",C Program to Find the Largest Number Among Three Numbers usinf if statement
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
|
|
double n1, n2, n3; |
|
|
|
printf(""Enter three different numbers:""); |
|
|
|
scanf(""%lf %lf %lf"", &n1, &n2, &n3); |
|
|
|
|
|
|
|
if (n1 >= n2 && n1 >= n3) |
|
|
|
printf(""%.2f is the largest number."", n1); |
|
|
|
|
|
|
|
if (n2 >= n1 && n2 >= n3) |
|
|
|
printf(""%.2f is the largest number."", n2); |
|
|
|
|
|
|
|
if (n3 >= n1 && n3 >= n2) |
|
|
|
printf(""%.2f is the largest number."", n3); |
|
|
|
return 0; } ",C Program to Find the Largest Number Among Three Numbers using if else statements
|
|
"#include <math.h> |
|
|
|
#include <stdio.h> |
|
|
|
int main() { |
|
|
|
double a, b, c, discriminant, root1, root2, realPart, imagPart; |
|
|
|
printf(""Enter coefficients a, b and c:""); |
|
|
|
scanf(""%lf %lf %lf"", &a, &b, &c); |
|
|
|
discriminant = b * b - 4 * a * c; |
|
|
|
|
|
|
|
if (discriminant > 0) { |
|
|
|
root1 = (-b + sqrt(discriminant)) / (2 * a); |
|
|
|
root2 = (-b - sqrt(discriminant)) / (2 * a); |
|
|
|
printf(""root1 = %.2lf and root2 = %.2lf"", root1, root2); |
|
|
|
} |
|
|
|
|
|
|
|
else if (discriminant == 0) { |
|
|
|
root1 = root2 = -b / (2 * a); |
|
|
|
printf(""root1 = root2 = %.2lf;"", root1); |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
realPart = -b / (2 * a); |
|
|
|
imagPart = sqrt(-discriminant) / (2 * a); |
|
|
|
printf(""root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi"", realPart, imagPart, realPart, imagPart); |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} ",C Program to Find the Roots of a Quadratic Equation
|
|
" #include <stdio.h> |
|
|
|
int main() { |
|
|
|
double n1, n2, n3; |
|
|
|
printf(""Enter three numbers:""); |
|
|
|
scanf(""%lf %lf %lf"", &n1, &n2, &n3); |
|
|
|
|
|
|
|
if (n1 >= n2) { |
|
|
|
|
|
|
|
if (n1 >= n3) |
|
|
|
printf(""%.2lf is the largest number."", n1); |
|
|
|
else |
|
|
|
printf(""%.2lf is the largest number."", n3); |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
if (n2 >= n3) |
|
|
|
printf(""%.2lf is the largest number."", n2); |
|
|
|
else |
|
|
|
printf(""%.2lf is the largest number."", n3); |
|
|
|
} |
|
|
|
return 0;}", C Program to Find the Largest Number Among Three Numbers using nested if statement
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
|
|
int year; |
|
|
|
printf(""Enter a year:""); |
|
|
|
scanf(""%d"", &year); |
|
|
|
|
|
|
|
if (year % 400 == 0) { |
|
|
|
printf(""%d is a leap year."", year); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else if (year % 100 == 0) { |
|
|
|
printf(""%d is not a leap year."", year); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else if (year % 4 == 0) { |
|
|
|
printf(""%d is a leap year."", year); |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
printf(""%d is not a leap year."", year); |
|
|
|
} |
|
|
|
return 0; } ",C Program to Check Leap Year
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
|
|
double num; |
|
|
|
printf(""Enter a number:""); |
|
|
|
scanf(""%lf"", &num); |
|
|
|
if (num <= 0.0) { |
|
|
|
if (num == 0.0) |
|
|
|
printf(""You entered 0.""); |
|
|
|
else |
|
|
|
printf(""You entered a negative number.""); |
|
|
|
} |
|
|
|
else |
|
|
|
printf(""You entered a positive number.""); |
|
|
|
return 0; |
|
|
|
}", C Program to Check Whether a Number is Positive or Negative
|
|
"#include <stdio.h> |
|
|
|
int main() { |
|
|
|
char c; |
|
|
|
printf(""Enter a character:""); |
|
|
|
scanf(""%c"", &c); |
|
|
|
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) |
|
|
|
printf(""%c is an alphabet."", c); |
|
|
|
else |
|
|
|
printf(""%c is not an alphabet."", c); |
|
|
|
return 0;}", C Program to Check Whether a Character is an Alphabet or not
|
|
|