source
stringlengths 78
862
| target
stringlengths 29
83
|
---|---|
#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);
// displays output
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);
// %d displays the integer value of a character
// %c displays the actual character
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);
// Computes quotient
quotient = dividend / divisor;
// Computes remainder
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;
// sizeof evaluates the size of a variable
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; // equivalent to long int b;
long long c; // equivalent to long long int 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);
// value of first is assigned to temp
temp = first;
// value of second is assigned to first
first = second;
// value of temp (initial value of first) is assigned to second
second = temp;
// %.2lf displays number up to 2 decimal points
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);
// true if num is perfectly divisible by 2
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);
// evaluates to 1 if variable c is a lowercase vowel
lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
// evaluates to 1 if variable c is a uppercase vowel
uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// evaluates to 1 (true) if c is a vowel
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 is greater than both n2 and n3, n1 is the largest
if(n1 >= n2 && n1 >= n3)
printf("%.2f is the largest number.", n1);
// if n2 is greater than both n1 and n3, n2 is the largest
if (n2 >= n1 && n2 >= n3)
printf("%.2f is the largest number.", n2);
// if n3 is greater than both n1 and n2, n3 is the largest
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 is greater than both n2 and n3, n1 is the largest
if (n1 >= n2 && n1 >= n3)
printf("%.2f is the largest number.", n1);
// if n2 is greater than both n1 and n3, n2 is the largest
if (n2 >= n1 && n2 >= n3)
printf("%.2f is the largest number.", n2);
// if n3 is greater than both n1 and n2, n3 is the largest
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;
// condition for real and different roots
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("root1 = %.2lf and root2 = %.2lf", root1, root2);
}
// condition for real and equal roots
else if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf("root1 = root2 = %.2lf;", root1);
}
// if roots are not real
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);
// outer if statement
if (n1 >= n2) {
// inner if...else
if (n1 >= n3)
printf("%.2lf is the largest number.", n1);
else
printf("%.2lf is the largest number.", n3);
}
// outer else statement
else {
// inner if...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);
// leap year if perfectly divisible by 400
if (year % 400 == 0) {
printf("%d is a leap year.", year);
}
// not a leap year if divisible by 100
// but not divisible by 400
else if (year % 100 == 0) {
printf("%d is not a leap year.", year);
}
// leap year if not divisible by 100
// but divisible by 4
else if (year % 4 == 0) {
printf("%d is a leap year.", year);
}
// all other years are not leap years
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 |
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
- Downloads last month
- 10