Write a C Program to display your name
#include <stdio.h>
int main() {
printf("Hello, I am ChatGPT!\n");
return 0;
}
Write a C Program to display two numbers
#include <stdio.h>
int main() {
int num1 = 5;
int num2 = 10;
printf("First number: %d\n", num1);
printf("Second number: %d\n", num2);
return 0;
}
OR
#include <stdio.h>
int main() {
int num1, num2;
// Input two numbers
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
// Display the entered numbers
printf("The first number is: %d\n", num1);
printf("The second number is: %d\n", num2);
return 0;
}
Write a C program to add two numbers
#include <stdio.h>
int main() {
int num1, num2, sum;
// Input two numbers
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
// Add the two numbers
sum = num1 + num2;
// Display the result
printf("The sum of %d and %d is: %d\n", num1, num2, sum);
return 0;
}
Write a C Program to add three numbers
#include <stdio.h>
int main() {
int num1, num2, num3, sum;
// Input three numbers
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
printf("Enter the third number: ");
scanf("%d", &num3);
// Add the three numbers
sum = num1 + num2 + num3;
// Display the result
printf("The sum of %d, %d, and %d is: %d\n", num1, num2, num3, sum);
}
Write a C Program to perform arithmetic operations
#include <stdio.h>
int main() {
int num1, num2, sum, diff, product;
float quotient;
// Input two numbers
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
// Perform arithmetic operations
sum = num1 + num2;
diff = num1 - num2;
product = num1 * num2;
// Check if the second number is not zero before division
if (num2 != 0) {
quotient = (float)num1 / num2;
// Display the result
printf("Sum: %d\n", sum);
printf("Difference: %d\n", diff);
printf("Product: %d\n", product);
printf("Quotient: %.2f\n", quotient);
} else {
printf("Cannot perform division. The second number cannot be zero.\n");
}
}
Write a C Program to compare two numbers using if-else
#include <stdio.h>
int main() {
int num1, num2;
// Input two numbers
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
// Compare the two numbers
if (num1 > num2) {
printf("%d is greater than %d\n", num1, num2);
} else if (num1 < num2) {
printf("%d is less than %d\n", num1, num2);
} else {
printf("%d is equal to %d\n", num1, num2);
}
return 0;
}
Write a C Program to check whether a number is even or odd
#include <stdio.h>
int main() {
int number;
// Input the number
printf("Enter an integer: ");
scanf("%d", &number);
// Check if the number is even or odd
if (number % 2 == 0) {
printf("%d is an even number.\n", number);
} else {
printf("%d is an odd number.\n", number);
}
return 0;
}