1. Simple Hello World Program.
#include <stdio.h>
int main() {
printf("Hello World");
return 0;
Output: Hello World
2. Addition Program
#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);
// Perform addition
sum = num1 + num2;
// Display the result
printf("The sum of %d and %d is: %d\n", num1, num2, sum);
return 0;
}
Output:
Enter the first number: 10
Enter the second number: 10
The sum of 10 and 10 is: 20
Practical No: 1
A. To calculate simple interest taking principal, rate of
interest & number of year as input from user
#include <stdio.h>
int main()
{
float principal, rate, time, simpleInterest;
// Taking input from the user
printf("Enter Principal amount: ");
scanf("%f", &principal);
printf("Enter Rate of Interest (in %%): ");
scanf("%f", &rate);
printf("Enter Time (in years): ");
scanf("%f", &time);
// Calculating Simple Interest
simpleInterest = (principal * rate * time) / 100;
// Displaying the result
printf("Simple Interest = %.2f\n", simpleInterest);
return 0;
}
Output:
Enter Principal amount: 2000
Enter Rate of Interest (in %): 8
Enter Time (in years): 1
Simple Interest = 160.00
B. Write a program to find out greatest of three
number using conditional operator.
#include <stdio.h>
int main()
{
int a, b, c, greatest;
// Taking input from the user
printf("Enter three numbers:\n");
scanf("%d %d %d", &a, &b, &c);
// Using conditional (ternary) operator to find the greatest
greatest = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
// Displaying the result
printf("The greatest number is: %d\n", greatest);
return 0;
}
Output:
Enter three numbers:
100
150
200
The greatest number is: 200
C. Write a program to check if the year entered is leap
year or not.
#include <stdio.h>
int main()
int year;
// Taking input from the user
printf("Enter a year: ");
scanf("%d", &year);
// Checking leap year conditions
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
printf("%d is a leap year.\n", year);
} else {
printf("%d is not a leap year.\n", year);
return 0;
Output: Enter a year: 2023
2023 is not a leap year.