0% found this document useful (0 votes)
2 views4 pages

C Programs

The document contains several C programming examples, including a simple Hello World program, an addition program, and programs for calculating simple interest, finding the greatest of three numbers, and checking for leap years. Each program includes user input, processing, and output statements. The examples illustrate basic programming concepts and operations in C.

Uploaded by

mrroyal956
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

C Programs

The document contains several C programming examples, including a simple Hello World program, an addition program, and programs for calculating simple interest, finding the greatest of three numbers, and checking for leap years. Each program includes user input, processing, and output statements. The examples illustrate basic programming concepts and operations in C.

Uploaded by

mrroyal956
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like