0% found this document useful (0 votes)
26 views7 pages

Programs of C

The document contains 13 C programming code examples demonstrating various programming concepts like: 1) Printing statements and taking user input 2) If-else conditional statements 3) For loops 4) Function definitions and calls 5) Mathematical calculations The programs cover basics like printing text, taking user input, solving equations to more advanced concepts like calculating distance between two points and pattern printing using nested for loops.
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)
26 views7 pages

Programs of C

The document contains 13 C programming code examples demonstrating various programming concepts like: 1) Printing statements and taking user input 2) If-else conditional statements 3) For loops 4) Function definitions and calls 5) Mathematical calculations The programs cover basics like printing text, taking user input, solving equations to more advanced concepts like calculating distance between two points and pattern printing using nested for loops.
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
You are on page 1/ 7

Program 1

#include <stdio.h>

int main(void)
{
int a, b, c;
a = 5;
b = 8;
c = 18;

printf("%dx + %dy = %d", a, b, c);


return 0;
}

Program 2
#include <stdio.h>

int main(void)
{
printf("\tAmitendu Bikash Dhusiya\n");
printf("\t5A, 30/2 Mohan Lal Bahawalwala Road\n");
printf("\tHowrah, 711201\n");
return 0;
}

Program 3
#include <stdio.h>

int main(int argc, char const *argv[])


{
int totn = 5;
int i;
for (i = 1; i <= 10; i++)
{
printf("5 x %i = %i \n", i, 5 * i);
}

return 0;
}

Program 4
#include <stdio.h>
int main(void)
{
int a, b, c, x;

printf("Please Enter 1 digit: ");


scanf("%d", &a);
printf("Please Enter 2 digit: ");
scanf("%d", &b);
printf("Please Enter 3 digit: ");
scanf("%d", &c);

x = a / (b - c);
printf("The solution of the Equation is: %i", x);
return 0;
}

Program 5
#include <stdio.h>

int main(void)
{
char temptype;
float fahrenheit, celsius;

printf("Enter your temparature type [C|F]: ");


scanf("%c", &temptype);
if (temptype == 'C' || temptype == 'c')
{
printf("Enter your Fahrenheit Temparature: ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("The Temparature in Celsius will be: %f", celsius);
}
else if (temptype == 'F' || temptype == 'f')
{
printf("Enter your Celsius Temparature: ");
scanf("%f", &celsius);
fahrenheit = (celsius * 9 / 5) + 32;
printf("The Temparature in Fahrenheit will be: %f", fahrenheit);
}
else
{
printf("Please enter C or F ONLY\n");
printf("=NOW RERUN THE PROGRAM!=\n");
}
return 0;
}

Program 6
#include <stdio.h>
#include <math.h>

#define PI 3.14159265358979323846

int main(void)
{
double radii, area;
printf("Enter your Radius of your Circle: ");
scanf("%lf", &radii);
area = PI * pow(radii, 2);
printf("The area of the Circle is: %lf", area);
}

Program 7
#include <stdio.h>

int add(int a, int b);


int sub(int a, int b);
int main(void)
{
int first, second;

first = 20;
second = 10;

add(first, second);
sub(first, second);
}

int add(int a, int b)


{
int sol;
sol = a + b;
printf("%d + %d = %d\n", a, b, sol);
}

int sub(int a, int b)


{
int sol;
sol = a - b;
printf("%d - %d = %d\n", a, b, sol);
}

Program 8
#include <stdio.h>

int main(void)
{
printf("||======================================================||\n");
printf("||Name: Amitendu Bikash Dhusiya ||\n");
printf("||Door No: 5A, Street: 30/2 Mohan Lal Bahawalwala Road ||\n");
printf("||City: Howrah, Pin: 711201 ||\n");
printf("||======================================================||\n");
return 0;
}

Program 9
#include <stdio.h>

int main(void)
{
int i, j, n;
n = 4;
for (i = 0; i < n; i++)
{
for (j = 0; j < i; j++)
{
printf("*");
}
printf("*\n");
}
}

Program 10
#include <stdio.h>

int main(void)
{
printf("||===============|| ||===============||\n");
printf("|| || || ||\n");
printf("|| || || ||\n");
printf("|| || >>-------> || ||\n");
printf("|| || || ||\n");
printf("|| || || ||\n");
printf("||===============|| ||===============||\n");
return 0;
}
Program 11
#include <stdio.h>
#include <math.h>

int main(void)
{
float a, b, c, d, area, sp;

printf("Enter the 1 side length: ");


scanf("%f", &a);
printf("Enter the 2 side length: ");
scanf("%f", &b);
printf("Enter the 3 side length: ");
scanf("%f", &c);

sp = (a + b + c) / 2;
d = sp * (sp - a) * (sp - b) * (sp - c);
area = sqrt(d);

printf("The Area of the Triangle is: %f", area);


return 0;
}

Program 12
#include <stdio.h>

int sum(int x, int y);


int diff(int x, int y);
int prod(int x, int y);
int divi(int x, int y);

int main(void)
{
int a, b;

printf("Enter the 1st Value: ");


scanf("%d", &a);
printf("Enter the 2st Value: ");
scanf("%d", &b);

sum(a, b);
diff(a, b);
prod(a, b);
divi(a, b);
}
int sum(int x, int y)
{
int sol;

sol = x + y;
printf("++++++++++++++++++++++++++++++++\n");
printf("| ADDITION = %i| \n", sol);
}
int diff(int x, int y)
{
int sol;

sol = x - y;
printf("| SUBSTRACTION = %i| \n", sol);
}
int prod(int x, int y)
{
int sol;

sol = x * y;
printf("| MULTIPLICATION = %i| \n", sol);
}
int divi(int x, int y)
{
int sol;

sol = x / y;
printf("| DIVISION = %i| \n", sol);
printf("++++++++++++++++++++++++++++++++\n");
}

Program 13
#include <stdio.h>
#include <math.h>

int main()
{
int x1, y1, x2, y2;
double distance;

printf("Enter the 1st (X, Y) Point: ");


scanf("%d %d", &x1, &y1);
printf("Enter the 2nd (X, Y) Point: ");
scanf("%d %d", &x2, &y2);
// Calculate the squared differences of coordinates
int diff_x = x2 - x1;
int diff_y = y2 - y1;

// Calculate the distance using the formula


distance = sqrt(diff_x * diff_x + diff_y * diff_y);

printf("The distance between the points is: %lf", distance);

return 0;
}

You might also like