Assignment 1: Introduction to C
Programming
// ✅ Answer 1: Hello World!
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
// ✅Answer 2: Display full name, student ID, and university name
in new lines
#include <stdio.h>
int main() {
printf("Your Full Name\n");
printf("Your Student ID\n");
printf("Sonargaon University\n");
return 0;
// ✅ Answer 3: Display all three in three lines using one printf
#include <stdio.h>
int main() {
printf("Your Full Name\nYour Student ID\nSonargaon
University\n");
return 0;
}
// ✅ Answer 4: Print three specific lines with formatting
#include <stdio.h>
int main() {
printf("\"Life is a dream, realize it. \n\nLife is a challenge,
meet it.\nLife is beauty, admire it.\"\n");
return 0;
// ✅ Answer 5: Take an integer input from the user and display it
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
printf("You entered: %d\n", num);
return 0;
// ✅ Answer 6: Take a float input from the user and display it
#include <stdio.h>
int main() {
float number;
printf("Enter a floating-point number: ");
scanf("%f", &number);
printf("You entered: %.2f\n", number);
return 0;
}
// ✅ Answer 7: Take a single character input and display it
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf(" %c", &ch); // Note the space before %c to consume any
previous newline
printf("You entered: '%c'\n", ch);
return 0;
// ✅ Answer 8: Take two integers and display their sum
#include <stdio.h>
int main() {
int a, b;
printf("Enter two integers: ");
scanf("%d %d", &a, &b);
printf("Sum: %d\n", a+b);
return 0;
// ✅ Answer 9: Take two float numbers and display their product
#include <stdio.h>
int main() {
float x, y;
printf("Enter two float numbers: ");
scanf("%f %f", &x, &y);
printf("Product: %.2f\n", x*y);
return 0;
// ✅ Answer 10: Convert Celsius to Fahrenheit
#include <stdio.h>
int main() {
float celsius, fahrenheit;
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
fahrenheit = (celsius*9/5)+32;
printf("Temperature in Fahrenheit: %.2f\n", fahrenheit);
return 0;
// ✅ Answer 11: Take two characters and show their ASCII values
#include <stdio.h>
int main() {
char ch1, ch2;
printf("Enter two characters: ");
scanf(" %c %c", &ch1, &ch2);
printf("You entered the characters: '%c' and '%c'\n", ch1, ch2);
printf("The ASCII value of '%c' is: %d\n", ch1, ch1);
printf("The ASCII value of '%c' is: %d\n", ch2, ch2);
return 0;
}
// ✅ Answer 12: Demonstrate single-line and multi-line comments
#include <stdio.h>
int main() {
// This is a single-line comment
printf("Single-line and multi-line comments demo\n");.
/*
This is a
multi-line comment
*/
return 0;