#include <stdio.
h>
int main() {
float principal, rate, time, interest;
// Take user input for principal, rate, and time
printf("Enter principal amount: ");
scanf("%f", &principal);
printf("Enter interest rate: ");
scanf("%f", &rate);
printf("Enter time period (in years): ");
scanf("%f", &time);
// Calculate simple interest
interest = (principal * rate * time) / 100;
// Display the result
printf("Simple Interest is: %.2f\n", interest);
return 0;
Output:
Enter principal amount: 100
Enter interest rate: 6
Enter time period (in years): 2
Simple Interest is: 120.00
// using nested if-else
#include<stdio.h>
int main(){
int a,b,c;
int big;
printf("Enter three numbers: ");
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
largest number = a;
else if(b>c)
largest number = b;
else
largest number = c;
printf("Largest number is: %d", largest number);
return 0;
Output:
Enter three numbers: 13 25 6
Largest number is: 25
#include <stdio.h>
#include <math.h> int
main() {
float a, b, c, r1, r2, d;
printf("Enter the values of a b c: ");
scanf(" %f %f %f", & a, & b, & c);
d = b * b - 4 * a * c;
if (d > 0) { r1 = -b + sqrt(d) / (2 * a);
r2 = -b - sqrt(d) / (2 * a);
printf("The real roots = %f %f", r1, r2);
else if (d == 0) { r1 = -b / (2 * a); r2 = -b / (2 * a);
printf("Roots are equal =%f %f", r1, r2);
Else
printf("Roots are imaginary");
return 0;
Output:
Case 1: Enter the values of a b c: 1 4 3
The real roots = -3.000000 -5.000000
Case 2: Enter the values of a b c: 1 2 1
Roots are equal =-1.000000 -1.000000
Case 3: Enter the values of a b c: 1 1 4
Roots are imaginary
#include<stdio.h>
#include<conio.h> int
main() {
int a,b;
int op;
printf(" 1.Addition\n 2.Subtraction\n 3.Multiplication\n 4.Division\n");
printf("Enter the values of a & b: ");
scanf("%d %d",&a,&b);
printf("Enter your Choice : ");
scanf("%d",&op);
switch(op)
case 1 :
printf("Sum of %d and %d is : %d",a,b,a+b);
break;
case 2 :
printf("Difference of %d and %d is : %d",a,b,a-b);
break;
case 3 :
printf("Multiplication of %d and %d is : %d",a,b,a*b);
break;
case 4 :
printf("Division of Two Numbers is %d : ",a/b); break;
default : printf(" Enter Your Correct Choice.");
break;
return 0;
Output:
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter the values of a & b: 20 15
Enter your Choice : 1
Sum of 20 and 15 is : 35
#include
int main() {
int rows = 5;
// This loop to print all rows
for (int i = 0; i < rows; i++) {
// Inner loop 1 to print
// white spaces for each row
for (int j = 0; j < 2 * (rows - i) - 1; j++)
{ printf(" ");
// Inner loop 2 to print star // (*)
character for each row for (int k =
0; k < 2 * i + 1; k++) {
printf("* ");
printf("\n");
return 0;
Output:
** *
** ***
** *** **
** *** ****
#include <stdio.h> int
main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
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: 2008
2008 is a leap year.