1.
write a program to calculate simple interest of the loan
taken by Mr. Suresh and display the same as output
#include <stdio.h>
int main() {
float principal, rate, time, simple_interest;
printf("Enter Principal amount: ");
scanf("%f", &principal);
printf("Enter Rate of interest: ");
scanf("%f", &rate);
printf("Enter Time (in years): ");
scanf("%f", &time);
simple_interest = (principal * rate * time) / 100;
printf("Simple Interest = %.2f\n", simple_interest);
return 0;
}
[Link]. Ramesh basic salary is input through keyboard
who's dearness allowances is 40% of basic salary,House
rental allowance is 20% of the basic salary.P.F. is 5% of
the basic salary,bus allowance is 2000 rupees, write a c
program to calculate net and gross salaries of ramesh
and display same
main()
{
float bs,hra,da,pf,net,gross;
intbus=2000;
printf(“\n Enter the basic salary of Mr. Ramesh”);
scanf(“%f”,&bs);
da=(bs*40)/100;
hra=(bs*20)/100;
pf=(bs*5)/100;
net=bs+da+hra;
gross=net-pf-bus;
printf(“\n Basic salary :%f”,bs);
printf(“\n Dearness Allowance:%f”,da);
printf(“\n House rental allowance :%f”,hra);
printf(“\n profund :%f”,pf);
printf(“\n Bus Allowance :%d”,bus);
printf(“\n Net salary :%f”,net);
printf(“\n Gross salary :%f”,gross);
}
[Link] a C program to calculate compound interest.
A = P(1 + r/100)^t
#include <stdio.h>
#include <math.h>
int main() {
double principal, rate, time, compoundInterest, amount;
// Input values
printf("Enter Principal amount: ");
scanf("%lf", &principal);
printf("Enter Annual Interest Rate (in %%): ");
scanf("%lf", &rate);
printf("Enter Time (in years): ");
scanf("%lf", &time);
// Formula: A = P(1 + r/100)^t
amount = principal * pow((1 + rate / 100), time);
compoundInterest = amount - principal;
// Output results
printf("\nFinal Amount = %.2lf", amount);
printf("\nCompound Interest = %.2lf", compoundInterest);
return 0;
}
[Link] a C program to calculate monthly EMI given principal, rate of
interest, and time.
#include <stdio.h>
#include <math.h>
int main() {
double principal, annualRate, monthlyRate;
int years, months;
double emi;
// Input values
printf("Enter the principal loan amount: ");
scanf("%lf", &principal);
printf("Enter the annual interest rate (in %%): ");
scanf("%lf", &annualRate);
printf("Enter the loan tenure (in years): ");
scanf("%d", &years);
// Convert annual rate to monthly rate
monthlyRate = annualRate / (12 * 100);
// Total number of monthly payments
months = years * 12;
// EMI calculation
emi = (principal * monthlyRate * pow(1 + monthlyRate, months)) /
(pow(1 + monthlyRate, months) - 1);
// Display result
printf("\nMonthly EMI = %.2lf\n", emi);
return 0;
}
[Link] a c program to calculate area and circumference
of a circle where radius of circle is given as input
#define pi 3.14
main()
float r,area,circum;
printf("Enter the radius of circle \n");
scanf("%f",&r);
area=pi*r*r;
circum=2*pi*r;
printf("The circumference of the circle is %f \n",circum);
printf("The area of the circle is %f \n",area);
[Link] a C program to calculate area and perimeter of a rectangle.
#include <stdio.h>
int main() {
float length, width, area, perimeter;
// Input values
printf("Enter the length of the rectangle: ");
scanf("%f", &length);
printf("Enter the width of the rectangle: ");
scanf("%f", &width);
// Calculate area and perimeter
area = length * width;
perimeter = 2 * (length + width);
// Display results
printf("\nArea of Rectangle = %.2f\n", area);
printf("Perimeter of Rectangle = %.2f\n", perimeter);
return 0;
}
7. Write a C program to calculate area of a triangle using Heron’s formula.
#include <stdio.h>
#include <math.h>
int main() {
double a, b, c, s, area;
// Input sides of triangle
printf("Enter side a: ");
scanf("%lf", &a);
printf("Enter side b: ");
scanf("%lf", &b);
printf("Enter side c: ");
scanf("%lf", &c);
// Calculate semi-perimeter
s = (a + b + c) / 2;
// Calculate area using Heron's formula
area = sqrt(s * (s - a) * (s - b) * (s - c));
// Display result
printf("\nArea of Triangle = %.2lf\n", area);
return 0;
8. Write a C program to find square root of a number.
#include <stdio.h>
#include <math.h>
int main() {
int number, result;
printf("Enter a number: ");
scanf("%d", &number);
result = sqrt(number);
printf("Square root of %d\n", result);
return 0;
9. Write a C program to calculate the surface area and volume of a cylinder.
#include <stdio.h>
#define PI 3.14159
int main() {
float radius, height, surfaceArea, volume;
// Input values
printf("Enter the radius of the cylinder: ");
scanf("%f", &radius);
printf("Enter the height of the cylinder: ");
scanf("%f", &height);
// Calculate surface area and volume
surfaceArea = 2 * PI * radius * (radius + height);
volume = PI * radius * radius * height;
// Display results
printf("\nSurface Area of Cylinder = %.2f\n", surfaceArea);
printf("Volume of Cylinder = %.2f\n", volume);
return 0;
}
10write a c program to convert fahreinheit temperature
to celsius and vice-versa
main()
float f,c,fh;
printf("Enter Fahreinheit \n");
scanf("%f",&f);
c=((f*5)/9)+32;
printf("celsius:%f \n",c);
fh=(c-32)*9/5;
printf("fahreinheit:%f",fh);
}
[Link] a C program to convert kilometers into meters and centimeters.
#include <stdio.h>
int main() {
float kilometers, meters, centimeters;
// Input value
printf("Enter distance in kilometers: ");
scanf("%f", &kilometers);
// Conversion
meters = kilometers * 1000;
centimeters = kilometers * 100000;
// Display results
printf("\nDistance in meters = %.2f m\n", meters);
printf("Distance in centimeters = %.2f cm\n", centimeters);
return 0;
}
12. Write a C program to demonstrate bitwise operators.
#include <stdio.h>
int main() {
int a = 10; // 1010 in binary
int b = 4; // 0100 in binary
printf("a = %d (Binary: 1010)\n", a);
printf("b = %d (Binary: 0100)\n\n", b);
// Bitwise AND
printf("a & b = %d\n", a & b);
// Bitwise OR
printf("a | b = %d\n", a | b);
// Bitwise XOR
printf("a ^ b = %d\n", a ^ b);
// Bitwise NOT
printf("~a = %d\n", ~a);
// Left Shift
printf("a << 1 = %d\n", a << 1);
// Right Shift
printf("a >> 1 = %d\n", a >> 1);
return 0;
13. Write a C program to evaluate arithmetic expressions.
#include <stdio.h>
int main() {
float a = 10, b = 5, c = 2;
float result;
// Arithmetic expression
result = a + b * c - a / b;
printf("Given Expression: a + b * c - a / b\n");
printf("Where a = %.2f, b = %.2f, c = %.2f\n", a, b, c);
printf("Result = %.2f\n", result);
return 0;
}
14. Write a C program to evaluate expressions using predefined values.
#include <stdio.h>
int main() {
int a = 12,b = 4, c = 3,result1, result2, result3;
// Evaluating expressions
result1 = a + b * c;
result2 = (a - b) / c;
result3 = a % b + c;
printf("Predefined values:\n");
printf("a = %d, b = %d, c = %d\n\n", a, b, c);
printf("Expression 1: a + b * c = %d\n", result1);
printf("Expression 2: (a - b) / c = %d\n", result2);
printf("Expression 3: a %% b + c = %d\n", result3);
return 0;
}
15. Write a C program to demonstrate logical operators AND, OR, and NOT.
#include <stdio.h>
int main() {
int a = 10,b = 5;
printf("Given values: a = %d, b = %d\n\n", a, b);
// Logical AND
printf("(a > 5 && b < 10) = %d\n", (a > 5 && b < 10));
// Logical OR
printf("(a < 5 || b < 10) = %d\n", (a < 5 || b < 10));
// Logical NOT
printf("!(a > b) = %d\n", !(a > b));
return 0;
}
16. Write a C program to find maximum of three numbers using conditional
operator.
#include <stdio.h>
int main() {
int a = 15, b = 25, c = 10;
int max;
// Using conditional operator
max = (a > b) ?
((a > c) ? a : c) :
((b > c) ? b : c);
printf("Given numbers: a = %d, b = %d, c = %d\n", a, b, c);
printf("Maximum number = %d\n", max);
return 0;
17. Write a C program to find the youngest among three persons.
#include <stdio.h>
int main() {
int age1 = 25, age2 = 20, age3 = 22;
int youngest;
// Using conditional operator
youngest = (age1 < age2) ?
((age1 < age3) ? age1 : age3) :
((age2 < age3) ? age2 : age3);
printf("Ages: Person1 = %d, Person2 = %d, Person3 = %d\n",
age1, age2, age3);
printf("Youngest age = %d\n", youngest);
return 0;}
18. Write a C program to find the biggest of three numbers using nested if.
#include <stdio.h>
int main() {
int a = 15, b = 25, c = 10;
printf("Given numbers: a = %d, b = %d, c = %d\n", a, b, c);
if (a > b) {
if (a > c) {
printf("Biggest number = %d\n", a);
} else {
printf("Biggest number = %d\n", c);
} else {
if (b > c) {
printf("Biggest number = %d\n", b);
} else {
printf("Biggest number = %d\n", c);
return 0;
19. Write a C program to find minimum of three numbers using conditional
operator.
#include <stdio.h>
int main() {
int a = 12, b = 8, c = 15,min;
// Using conditional operators in a different style
min = (a < b && a < c) ? a : (b < c ? b : c);
printf("Given numbers: a = %d, b = %d, c = %d\n", a, b, c);
printf("Minimum number = %d\n", min);
return 0;
}
20. Write a C program to check whether a number is negative.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num < 0) {
printf("The number is negative.\n");
} else {
printf("The number is not negative.\n");
return 0;
}
21. Write a C program to check whether a number is even.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0) {
printf("The number is even.\n");
} else {
printf("The number is not even (it is odd).\n");
return 0;
}
22. Write a C program to check whether a character is vowel or consonant.
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' ||
ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') {
printf("The character is a vowel.\n");
} else {
printf("The character is consonant.\n");
return 0;
}
23. Write a C program to check whether a number is even or odd.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0) {
printf("The number is even.\n");
} else {
printf("The number is odd.\n");
return 0;
}
24. Write a C program to check whether a number is divisible by 13.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 13 == 0) {
printf("The number is divisible by 13.\n");
} else {
printf("The number is not divisible by 13.\n");
return 0;
}
26. Write a C program to calculate total, average, and grade of a student.
#include <stdio.h>
int main() {
int m1, m2, m3, total;
float average;
printf("Enter marks of three subjects: ");
scanf("%d %d %d", &m1, &m2, &m3);
total = m1 + m2 + m3;
average = total / 3.0;
printf("Total = %d\n", total);
printf("Average = %.2f\n", average);
if (average >= 90)
printf("Grade = A\n");
else if (average >= 75)
printf("Grade = B\n");
else if (average >= 60)
printf("Grade = C\n");
else if (average >= 50)
printf("Grade = D\n");
else
printf("Grade = Fail\n");
return 0;
}
27. Write a C program to perform arithmetic operations using switch case.
#include <stdio.h>
int main() {
int a, b, choice;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
printf("\nChoose an operation:\n");
printf("1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Division\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice) {
case 1:
printf("Addition = %d\n", a + b);
break;
case 2:
printf("Subtraction = %d\n", a - b);
break;
case 3:
printf("Multiplication = %d\n", a * b);
break;
case 4:
printf("Division = %.2f\n", (float)a / b);
break;
default:
printf("Invalid choice\n");
return 0;
}
28. Write a menu-driven calculator program using switch case.
#include <stdio.h>
int main() {
int choice;
float a, b;
printf("Menu Driven Calculator\n");
printf("1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Division\n");
printf("Enter your choice: ");
scanf("%d", &choice);
printf("Enter two numbers: ");
scanf("%f %f", &a, &b);
switch(choice) {
case 1:
printf("Result = %.2f\n", a + b);
break;
case 2:
printf("Result = %.2f\n", a - b);
break;
case 3:
printf("Result = %.2f\n", a * b);
break;
case 4:
if (b != 0)
printf("Result = %.2f\n", a / b);
else
printf("Division by zero is not allowed\n");
break;
default:
printf("Invalid choice\n");
return 0;
}
29. Write a C program to print first n natural numbers using for loop.
#include <stdio.h>
int main() {
int n, i;
printf("Enter the value of n: ");
scanf("%d", &n);
printf("First %d natural numbers are:\n", n);
for(i = 1; i <= n; i++) {
printf("%d ", i);
return 0;
}
30. Write a C program to print first n natural numbers using while loop.
#include <stdio.h>
int main() {
int n, i = 1;
printf("Enter the value of n: ");
scanf("%d", &n);
printf("First %d natural numbers are:\n", n);
while (i <= n) {
printf("%d ", i);
i++;
return 0;
}
31. Write a C program to print first n natural numbers using do-while loop.
#include <stdio.h>
int main() {
int n, i = 1;
printf("Enter the value of n: ");
scanf("%d", &n);
printf("First %d natural numbers are:\n", n);
do {
printf("%d ", i);
i++;
} while (i <= n);
return 0;
}
33. Write a C program to print numbers from n to 1 using loop.
#include <stdio.h>
int main() {
int n, i;
printf("Enter a number: ");
scanf("%d", &n);
printf("Numbers from %d to 1 are:\n", n);
for(i = n; i >= 1; i--) {
printf("%d ", i);
}
return 0;
}
[Link] a C program to print first n even numbers.
#include <stdio.h>
int main() {
int n, i;
printf("Enter the value of n: ");
scanf("%d", &n);
printf("First %d even numbers are:\n", n);
for(i = 1; i <= n; i++) {
printf("%d ", 2 * i);
}
return 0;
}
[Link] a C program to print first n odd numbers.
#include <stdio.h>
int main() {
int n, i;
printf("Enter the value of n: ");
scanf("%d", &n);
printf("First %d odd numbers are:\n", n);
for(i = 0; i < n; i++) {
printf("%d ", 2 * i + 1);
}
return 0;
}
36. Write a C program to print multiplication table.
#include <stdio.h>
int main() {
int num, i;
printf("Enter a number: ");
scanf("%d", &num);
printf("Multiplication table of %d:\n", num);
for(i = 1; i <= 10; i++) {
printf("%d x %d = %d\n", num, i, num * i);
}
return 0;
}
37. Write a C program to find factorial of a number.
#include <stdio.h>
int main() {
int n, i;
long long factorial = 1;
printf("Enter a number: ");
scanf("%d", &n);
if(n < 0) {
printf("Factorial is not defined for negative numbers.\n");
} else {+
for(i = 1; i <= n; i++) {
factorial = factorial * i;
}
printf("Factorial of %d = %lld\n", n, factorial);
}
return 0;
}
38. Write a C program to check whether a number is palindrome.
#include <stdio.h>
int main() {
int num, original, reversed = 0, remainder;
printf("Enter a number: ");
scanf("%d", &num);
original = num;
while(num != 0) {
remainder = num % 10;
reversed = reversed * 10 + remainder;
num = num / 10;
if(original == reversed)
printf("%d is a palindrome number.\n", original);
else
printf("%d is not a palindrome number.\n", original);
return 0;
}
39. Write a C program to check whether a number is Armstrong number.
#include <stdio.h>
#include <math.h>
int main() {
int num, original, remainder, n = 0;
double result = 0.0;
printf("Enter a number: ");
scanf("%d", &num);
original = num;
// Count number of digits
while (original != 0) {
original /= 10;
n++;
}
original = num;
// Calculate sum of digits raised to power n
while (original != 0) {
remainder = original % 10;
result += pow(remainder, n);
original /= 10;
}
// Check Armstrong condition
if ((int)result == num)
printf("%d is an Armstrong number.\n", num);
else
printf("%d is not an Armstrong number.\n", num);
return 0;
}
40. Write a C program to check whether a number is prime.
#include <stdio.h>
int main() {
int n, i, flag = 0;
printf("Enter a number: ");
scanf("%d", &n);
if(n <= 1) {
printf("%d is not a prime number.\n", n);
} else {
for(i = 2; i <= n / 2; i++) {
if(n % i == 0) {
flag = 1;
break;
if(flag == 0)
printf("%d is a prime number.\n", n);
else
printf("%d is not a prime number.\n", n);
return 0;
}
41. Write a C program to print prime numbers up to n.
#include <stdio.h>
int main() {
int n, i, j, isPrime;
printf("Enter a number: ");
scanf("%d", &n);
printf("Prime numbers up to %d are:\n", n);
for(i = 2; i <= n; i++) {
isPrime = 1; // assume number is prime
for(j = 2; j <= i / 2; j++) {
if(i % j == 0) {
isPrime = 0;
break;
if(isPrime == 1) {
printf("%d ", i);
}
return 0;}
42. Write a C program to reverse a number.
#include <stdio.h>
int main() {
int num, reversed = 0, remainder;
printf("Enter an integer: ");
scanf("%d", &num);
while (num != 0) {
remainder = num % 10; // Get last digit
reversed = reversed * 10 + remainder; // Add it to reversed
number
num /= 10; // Remove last digit
printf("Reversed number = %d\n", reversed);
return 0;
}
43. Write a C program to find sum of digits of a number.
#include <stdio.h>
int main() {
int num, sum = 0, remainder;
printf("Enter an integer: ");
scanf("%d", &num);
// Handle negative numbers
if (num < 0) {
num = -num;
while (num != 0) {
remainder = num % 10; // Get last digit
sum += remainder; // Add to sum
num /= 10; // Remove last digit
printf("Sum of digits = %d\n", sum);
return 0;
}
44. Write a C program to find smallest number of currency notes.
#include <stdio.h>
int main() {
int amount;
printf("Enter the amount: ");
scanf("%d", &amount);
int notes[] = {2000, 500, 200, 100, 50, 20, 10, 5, 1};
int count;
printf("Minimum number of notes:\n");
for (int i = 0; i < 9; i++) {
if (amount >= notes[i]) {
count = amount / notes[i];
printf("%d x %d = %d\n", notes[i], count, notes[i] * count);
amount = amount % notes[i];
return 0;
}
45. Write a C program to count number of digits in a given number.
#include <stdio.h>
int main() {
int num, count = 0;
printf("Enter an integer: ");
scanf("%d", &num);
// Handle zero case
if (num == 0) {
count = 1; }
// Handle negative numbers
if (num < 0) {
num = -num;
while (num != 0) {
num /= 10; // Remove last digit
count++; // Increment count
printf("Number of digits = %d\n", count);
return 0;
}
46. Write a C program to convert Cartesian coordinates to polar coordinates.
#include <stdio.h>
int main() {
int num, count = 0;
printf("Enter an integer: ");
scanf("%d", &num);
// Handle zero case
if (num == 0) {
count = 1;
// Handle negative numbers
if (num < 0) {
num = -num;
while (num != 0) {
num /= 10; // Remove last digit
count++; // Increment count
printf("Number of digits = %d\n", count);
return 0;
47. Write a C program to print all trigonometric ratios of an angle.
#include <stdio.h>
#include <math.h>
int main() {
double angle, rad;
printf("Enter angle in degrees: ");
scanf("%lf", &angle);
// Convert degrees to radians
rad = angle * (3.141592653589793 / 180.0);
double sinx = sin(rad);
double cosx = cos(rad);
double tanx = tan(rad);
printf("sin(%.2lf) = %.4lf\n", angle, sinx);
printf("cos(%.2lf) = %.4lf\n", angle, cosx);
printf("tan(%.2lf) = %.4lf\n", angle, tanx);
// Check before calculating reciprocal values
if (sinx != 0)
printf("cosec(%.2lf) = %.4lf\n", angle, 1/sinx);
else
printf("cosec(%.2lf) is undefined\n", angle);
if (cosx != 0)
printf("sec(%.2lf) = %.4lf\n", angle, 1/cosx);
else
printf("sec(%.2lf) is undefined\n", angle);
if (tanx != 0)
printf("cot(%.2lf) = %.4lf\n", angle, 1/tanx);
else
printf("cot(%.2lf) is undefined\n", angle);
return 0;
}
48. Write a C program to calculate distance between two places using latitude
and longitude.
#include <stdio.h>
#include <math.h>
#define PI 3.141592653589793
#define R 6371.0 // Earth's radius in kilometers
// Function to convert degrees to radians
double toRadians(double degree) {
return degree * (PI / 180.0);
int main() {
double lat1, lon1, lat2, lon2;
double dlat, dlon, a, c, distance;
printf("Enter latitude and longitude of first place:\n");
scanf("%lf %lf", &lat1, &lon1);
printf("Enter latitude and longitude of second place:\n");
scanf("%lf %lf", &lat2, &lon2);
// Convert degrees to radians
lat1 = toRadians(lat1);
lon1 = toRadians(lon1);
lat2 = toRadians(lat2);
lon2 = toRadians(lon2);
// Differences
dlat = lat2 - lat1;
dlon = lon2 - lon1;
// Haversine formula
a = pow(sin(dlat / 2), 2) +
cos(lat1) * cos(lat2) *
pow(sin(dlon / 2), 2);
c = 2 * atan2(sqrt(a), sqrt(1 - a));
distance = R * c;
printf("Distance = %.2lf km\n", distance);
return 0;
49. Write a C program to calculate wind-chill factor.
W=13.12+0.6215T−11.37V0.16+0.3965T⋅V0.16
#include <stdio.h>
#include <math.h>
int main() {
double T, V, W;
printf("Enter temperature (in Celsius): ");
scanf("%lf", &T);
printf("Enter wind speed (in km/h): ");
scanf("%lf", &V);
// Wind-chill formula
W = 13.12 + 0.6215 * T
- 11.37 * pow(V, 0.16)
+ 0.3965 * T * pow(V, 0.16);
printf("Wind Chill Factor = %.2lf °C\n", W);
return 0;
50. Write a C program to check whether a year is a leap year.
#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;
}
51. Write a C program to read numbers until –1 and count positives, negatives,
and zeros.
#include <stdio.h>
int main() {
int num;
int positive = 0, negative = 0, zero = 0;
printf("Enter numbers (-1 to stop):\n");
while (1) {
scanf("%d", &num);
if (num == -1) {
break; // stop input
if (num > 0) {
positive++;
} else if (num < 0) {
negative++;
} else {
zero++;
printf("Positive numbers: %d\n", positive);
printf("Negative numbers: %d\n", negative);
printf("Zeroes: %d\n", zero);
return 0;
52. Write a C program to validate whether input marks are within 0–100.
#include <stdio.h>
int main() {
int marks;
printf("Enter marks: ");
scanf("%d", &marks);
if (marks >= 0 && marks <= 100) {
printf("Valid marks\n");
} else {
printf("Invalid marks! Please enter marks between 0 and 100.\n");
return 0;
53. Write a C program to construct a number pyramid.
#include <stdio.h>
int main() {
int rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
for (int i = 1; i <= rows; i++) {
// Print spaces
for (int j = i; j < rows; j++) {
printf(" ");
// Print numbers in increasing order
for (int k = 1; k <= i; k++) {
printf("%d ", k);
printf("\n");
return 0;
54. Write a C program to construct a number pyramid (alternate pattern).
#include <stdio.h>
int main() {
int rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
for (int i = 1; i <= rows; i++) {
// Print spaces
for (int j = i; j < rows; j++) {
printf(" ");
// Print same number in each row
for (int k = 1; k <= i; k++) {
printf("%d ", i);
printf("\n");
return 0;
55. Write a C program to construct a pyramid of stars.
#include <stdio.h>
int main() {
int rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
for (int i = 1; i <= rows; i++) {
// Print spaces
for (int j = i; j < rows; j++) {
printf(" ");
}
// Print stars
for (int k = 1; k <= i; k++) {
printf("* ");
printf("\n");
return 0;
56. Write a C program to print an inverted star pyramid
#include <stdio.h>
int main() {
int rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
for (int i = rows; i >= 1; i--) {
// Print spaces
for (int j = rows; j > i; j--) {
printf(" ");
// Print stars
for (int k = 1; k <= (2 * i - 1); k++) {
printf("*");
printf("\n");
return 0;