0% found this document useful (0 votes)
6 views6 pages

Basic C Programs

Uploaded by

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

Basic C Programs

Uploaded by

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

C programs

1. Area and Circumference of a Circle

#include <stdio.h>

#define PI 3.14159

int main() {

float radius, area, circumference;

printf("Enter radius: ");

scanf("%f", &radius);

area = PI * radius * radius;

circumference = 2 * PI * radius;

printf("Area: %.2f\n", area);

printf("Circumference: %.2f\n", circumference);

return 0;

2. Print ASCII Value of a Character

#include <stdio.h>

int main() {

char c;

printf("Enter a character: ");

scanf("%c", &c);

printf("ASCII value of %c is %d\n", c, c);

return 0;

Twinkle Tiwari C Program 15 sept 2025


3. Area of a Triangle

#include <stdio.h>

int main() {

float base, height, area;

printf("Enter base and height: ");

scanf("%f %f", &base, &height);

area = 0.5 * base * height;

printf("Area of Triangle: %.2f\n", area);

return 0;

4. Convert Person’s Name into Abbreviated Form

#include <stdio.h>

int main() {

char fname[20], mname[20], lname[20];

printf("Enter first, middle, and last name: ");

scanf("%s %s %s", fname, mname, lname);

printf("Abbreviated name: %c.%c.%s\n", fname[0], mname[0], lname);

return 0;

5. Simple Interest

#include <stdio.h>

int main() {

float p, r, t, si;

printf("Enter principal, rate and time: ");

scanf("%f %f %f", &p, &r, &t);

si = (p * r * t) / 100;

Twinkle Tiwari C Program 15 sept 2025


printf("Simple Interest: %.2f\n", si);

return 0;

6. Gross Salary of an Employee

#include <stdio.h>

int main() {

float basic, da, hra, gross;

printf("Enter basic salary: ");

scanf("%f", &basic);

da = 0.10 * basic;

hra = 0.20 * basic;

gross = basic + da + hra;

printf("Gross Salary: %.2f\n", gross);

return 0;

7. Percentage of 5 Subjects

#include <stdio.h>

int main() {

int s1, s2, s3, s4, s5;

float total, percentage;

printf("Enter marks of 5 subjects: ");

scanf("%d %d %d %d %d", &s1, &s2, &s3, &s4, &s5);

total = s1 + s2 + s3 + s4 + s5;

percentage = total / 5;

printf("Percentage: %.2f%%\n", percentage);

return 0;

Twinkle Tiwari C Program 15 sept 2025


8. Convert Celsius into 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;

9. Display Size of Different Data Types

#include <stdio.h>

int main() {

printf("Size of int: %lu bytes\n", sizeof(int));

printf("Size of float: %lu bytes\n", sizeof(float));

printf("Size of double: %lu bytes\n", sizeof(double));

printf("Size of char: %lu bytes\n", sizeof(char));

return 0;

10. Factorial of a Given Number

#include <stdio.h>

int main() {

int n, i;

long long factorial = 1;

printf("Enter an integer: ");

Twinkle Tiwari C Program 15 sept 2025


scanf("%d", &n);

for(i = 1; i <= n; ++i) {

factorial *= i;

printf("Factorial of %d = %lld\n", n, factorial);

return 0;

11. Read Integer (N) and Print First Three Powers

#include <stdio.h>

int main() {

int n;

printf("Enter an integer: ");

scanf("%d", &n);

printf("N^1 = %d\n", n);

printf("N^2 = %d\n", n*n);

printf("N^3 = %d\n", n*n*n);

return 0;

12. Area of a Circle (Duplicate of #1)

// Already covered in #1

13. LCM of Two Numbers

#include <stdio.h>

int main() {

int a, b, max;

printf("Enter two numbers: ");

scanf("%d %d", &a, &b);

Twinkle Tiwari C Program 15 sept 2025


max = (a > b) ? a : b;

while(1) {

if (max % a == 0 && max % b == 0) {

printf("LCM = %d\n", max);

break;

++max;

return 0;

14. GCD of Two Numbers

#include <stdio.h>

int main() {

int a, b, gcd;

printf("Enter two numbers: ");

scanf("%d %d", &a, &b);

while (a != b) {

if (a > b)

a = a - b;

else

b = b - a;

printf("GCD = %d\n", a);

return 0;

Twinkle Tiwari C Program 15 sept 2025

You might also like