[Link] a C program to print your name, date of birth, and mobile number.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
printf("Name : Mobin Haque\n");
printf("DOB : July 13, 2002\n");
printf("Mobile : 01742650312\n");
return 0;
}
2. Write a C program to get the C version you are using.
#include<stdio.h>
int main(int argc, char** argv)
{
printf("ID:2102064\n\n");
#if _STDC_VERSION_>= 201710L
printf("We are using C18!\n");
#elif_STDC_VERSION_>= 201112L
printf("We are using C11!\n");
#elif_STDC_VERSION_>=199901L
printf("We are using C99!\n");
#else
printf("We are using C89/C90!\n");
#endif
return 0;
}
3. Write a C program to print a block F using the hash (#), where the F has a
height of six characters and width of five and four characters. And also print a
very large 'C'.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
printf("######\n");
printf("#\n");
printf("#\n");
printf("#####\n");
printf("#\n");
printf("#\n");
printf("#\n");;
printf(" ######\n");
printf(" ## ##\n");
printf(" #\n");
printf(" #\n");
printf(" #\n");
printf(" #\n");
printf(" #\n");
printf(" ## ##\n");
printf(" ######\n");
return 0;
}
4. Write a C program to print the following characters in reverse : 'X', 'M', 'L'
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
char char1='X';
char char2='M';
char char3='L';
printf("The reverse of %c%c%c is %c%c%c\n",
char1,char2,char3,
char3,char2,char1);
return 0;
}
5. Write a C program to compute the perimeter and area of a rectangle with a
height of 7 inches and width of 5 inches.
#include<stdio.h>
/*--------Height and Width of a rectangle in inches-------*/
int width;
int height;
int area;
int perimeter;
int main()
{
printf("ID:2102064\n\n");
height=7;
width=5;
perimeter = 2*(height+width);
printf("Perimeter of the rectangle = %d inches\n",perimeter);
area = height*width;
printf("Area of the rectangle = %d square inches\n",area);
return 0;
}
6. Write a C program to compute the perimeter and area of a circle with a
given radius.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int radius;
float area, perimeter;
radius=6;
perimeter = 2*3.14*radius;
printf("Perimeter of the Circle = %f inches\n",perimeter);
area = 3.14*radius*radius;
printf("Area of the Circle = %f square inches\n",area);
return 0;
}
7. Write a C program to display multiple variables:
a+ c, x + c,dx + x, ((int) dx) + ax, a + x, s + b, ax + b, s + c, ax + c, ax + ux
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int a=125;
int b=12345;
long ax=1234567890;
short s=4043;
float x=2.13459;
double dx=1.1415927;
char c='W';
unsigned long ux=2541567890;
printf("a+c=%d\n",a+c);
printf("x+c=%f\n",x+c);
printf("dx+x=%f\n",dx+x);
printf("((int)dx)+ax=%1d\n",((int)dx)+ax);
printf("a+x=%f\n",a+x);
printf("s+b=%d\n",s+b);
printf("ax+b=%1d\n",ax+b);
printf("s+c=%hd\n",s+c);
printf("ax+c=%1d\n",ax+c);
printf("ax+ux=%1u\n",ax+ux);
return 0;
}
8. Write a C program to convert specified days into years, weeks and days.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int days,years,weeks;
days=1329;
//Converts days to years,weeks and days
years=days/365;
weeks=(days%365)/7;
days=days-((years*365)+(weeks*7));
printf("Years: %d\n",years);
printf("Weeks: %d\n",weeks);
printf("Days : %d\n",days);
return 0;
}
9. Write a C program that accepts two integers from the user and calculates
the sum of the two integers.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int x,y,sum;
printf("\nInput the first integer: ");
scanf("%d",&x);
printf("\nInput the second integer: ");
scanf("%d",&y);
sum=x+y;
printf("\nSum of the above two integers = %d\n",sum);
return 0;
}
10. Write a C program that accepts two integers from the user and calculates
the product of the two integers.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int x,y,result;
printf("\nInput the first integer: ");
scanf("%d",&x);
printf("\nInput the second integer: ");
scanf("%d",&y);
result=x*y;
printf("\nProduct of the above two integers = %d\n",result);
return 0;
}
11. investment program:
/*--------INVESTMENT PROBLEM---------*/
#define PERIOD 10
#define PRINCIPAL 5000.00
/*--------MAIN PROGRAM BEGINS--------*/
main()
{/*-------DECLARATION STATMENTS----------*/
printf("ID:2102064\n\n");
int year;
float amount,value,inrate;
/*--------ASSIGNMENT STATEMENT-----------*/
amount=PRINCIPAL;
inrate=0.11;
year=0;
/*--------COMPUTATION STATEMENT-----------*/
/*--------COMPUTATION USING While LOOP------*/
while(year<=PERIOD)
{
printf(" %2d %8.2f\n",year,amount);
value=amount+inrate*amount;
year=year+1;
amount=value;
}
/*--------While LOOP ENDS-----*/
}
/*---------PROGRAM ENDS---------*/
12. Multiplication of 5 and 10 is 50.
#include<stdio.h>
int mul (int a, int b);
int main ()
{
printf("ID:2102064\n\n");
int a,b,c;
a=5;
b=10;
c=mul(a,b);
printf("multiplication of %d and %d is %d",a,b,c);
}
int mul (int x, int y)
{
int p;
p=x*y;
return (p);
}
13. Write a program to display the equation of a line in the form:
ax + by = c
for a = 5, b = 8 and c = 18.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int a=5,b=8,c=18;
printf("%d x + %d y = %d",a,b,c);
return 0;
}
14. Write a program to output the following
multiplication table:
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int num, i;
printf("Enter a number: ");
scanf("%d",&num);
for(i=1;i<=10;i++)
{
printf(" %d * %d = %d\n", num, i, num*i);
}
return 0;
}
15. Given the values of three variables a, b and c, write
a program to compute and display the value of x,
where:
Execute your program for the following values:
a = 250, b = 85, c = 25
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int a = 250, b = 85, c = 25, x=a/(b-c);
printf("%d/(%d-%d)=%d",a,b,c,x);
return 0;
}
16. Write a C program that accepts three integers and finds the maximum of
three.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int a,b,c;
printf("Enter the value of a: ");
scanf("%d",&a);
printf("Enter the value of b: ");
scanf("%d",&b);
printf("Enter the value of c: ");
scanf("%d",&c);
if((a>b)&&(a>c))
printf("a is greatest");
if((b>a)&&(b>c))
printf("b is greatest");
if((c>a)&&(c>b))
printf("c is greatest");
return 0;
}
17. Write a C program that reads the value of distance travelled by a car and
the time taken for the same. Next, compute the speed at which the car
travelled.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
float s, vi, a, t;
printf("Enter initial velocity of car = ");
scanf("%f", &vi);
printf("Enter acceleration = ");
scanf("%f", &a);
printf("Enter time = ");
scanf("%f", &t);
s = vi * t + 1.0/2.0 *a * t * t;
printf("Distance covered by car is = %f m", s);
return 0;
}
18. Write a C program to print the current system date.
#include <stdio.h>
#include <time.h>
void main(void)
{
printf("ID:2102064\n\n");
// Get the current time
time_t current_time = time(NULL);
// Convert the time to a string using the desired format
char date_string[20];
strftime(date_string, 20, "%Y-%m-%d", localtime(¤t_time));
// Print the date string
printf("The current date is: %s\n", date_string);
}
19. Write a program using one print statement to print the pattern of asterisks
as shown below:
#include<stdio.h>
int main(void)
{
printf("ID:2102064\n\n");
printf("*\n*\t*\n*\t*\t*\n*\t*\t*");
return 0;
}
20. Write a program that will print the following figure using suitable
characters:
#include<stdio.h>
void main()
{
printf("ID:2102064\n\n");
printf("___________ ___________\n");
printf("| | | |\n");
printf("| |>>----->| |\n");
printf("|_________| |_________|\n");
return 0;
}
21. Write a C program that accepts two item's weight and number of
purchases (floating point values) and calculates their average value.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
double w1, w2, n1, n2, result;
printf("Weight - Item1: ");
scanf("%lf", &w1);
printf("No. of Item1: ");
scanf("%lf", &n1);
printf("Weight - Item2: ");
scanf("%lf", &w2);
printf("No. of Item2: ");
scanf("%lf", &n2);
result = ((w1 * n1) + (w2 * n2)) / (n1 + n2);
printf("Average Value = %f\n", result);
return 0;
}
22. Area of a triangle is given by the formula:
Where a, b and c are sides of the triangle and 2S =a + b + c. Write a program
to compute the area of the triangle given the values of a, b and c.
#include<stdio.h>
#include<math.h>
void main()
{
printf("ID:2102064\n\n");
float a, b, c, A, s;
printf("Enter value of a,b,c\n");
scanf("%f,%f,%f, &a,&b,&c");
s = (a+b+c)/2;
A = sqrt(s * (s-a) * (s-b) * (s-c));
printf("Area of triangle is %f", A);
return 0;
}
23. Write a program to display the following simple arithmetic calculator:
#include<stdio.h>
void main()
{
printf("ID:2102064\n\n");
printf(" _______ ________ \n");
printf("X = | | , Y =| |\n");
printf(" ------- -------- \n");
printf(" ______ ______ \n");
printf("sum = | | Difference = | |\n");
printf(" ------ ------ \n");
printf(" ______ _____ \n");
printf("Product = | | , DIvision = | |\n");
printf(" ------ ----- \n");
return 0;
}
24. Distance between two points (X1,Y1),(X2,Y2).Write a
program to compute D given the coordinates of the points.
#include<stdio.h>
#include<math.h>
int main()
{
printf("ID:2102064\n\n");
int X1, Y1, X2, Y2;
float D;
printf("Input value: ",X1,Y1,X2,Y2);
scanf("%d%d%d%d", &X1,&Y1,&X2,&Y2);
D = sqrt ((X2-X1) * (X2-X1) + (Y2-Y1) * (Y2-Y1));
printf("%2f", D);
return 0;
}
25. A point on the circumference of a circle whose centre is (o, o) is (4,5).
Write a program to compute perimeter and area of the circle.
#include<stdio.h>
#include<math.h>
int main()
{
printf("ID:2102064\n\n");
int X1 = 0, X2 = 0, Y1 = 4, Y2 = 5;
double D, d, red, area, peri, PI = 3.14159;
d = (X2-X1) * (X2-X1) + (Y2-Y1) * (Y2-Y1);
D = sqrt (d);
red = D/2;
peri = 2 * PI * red;
area = PI * red * red;
printf("area is %.2lf\nPerimeter is %.2lf\n", area, peri);
return 0;
}
26. The line joining the points (2,2) and (5,6) which lie on the circumference of
a circle is the diameter of the circle. Write a program to compute the area of
the circle.
#include<stdio.h>
#include<math.h>
int main()
{
printf("ID:2102064\n\n");
int X1 = 2, X2 = 2, Y1 = 5, Y2 = 6;
double D, d, red, area, peri, PI = 3.1416;
d = (X2-X1) * (X2-X1) + (Y2-Y1) * (Y2-Y1);
D = sqrt (d);
red = D/2;
peri = 2 * PI * red;
area = PI * red * red;
printf("area is %.2lf\n", area);
return 0;
}
27. Write a C program that accepts an employee's ID, total worked hours in a
month and the amount he received per hour. Print the ID and salary (with two
decimal places) of the employee for a particular month.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
char id[10];
int hour;
double value, salary;
printf("Input the Employee ID(Max. 10 chars): ");
scanf("%s", &id);
printf("\nInput the working hours: ");
scanf("%d", &hour);
printf("\nSalary amount/hr: ");
scanf("%lf", &value);
salary = value * hour;
printf("\nEmployees ID = %s\nSalary = US$ %.2lf\n", id, salary);
return 0;
}
28. Write a C program to calculate a bike’s average consumption from the
given total distance (integer value) travelled (in km) and spent fuel (in litters,
float number – 2 decimal points).
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int x;
float y;
printf("Input total distance in km: ");
scanf("%d", &x);
printf("Input total fuel spent in liters: ");
scanf("%f", &y);
printf("Average consumption (km/lt) %.3f", x/y);
return 0;
}
29. Write a C program to read an amount (integer value) and break the
amount into the smallest possible number of bank notes.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int amt, total;
printf("Input the amount: ");
scanf("%d", &amt);
total = (int)amt/100;
printf("There are: ");
printf("\n%d Note(s) of 100.00\n", total);
amt = amt - (total*100);
total = (int)amt/50;
printf("%d Note(s) of 50.00\n", total);
amt = amt-(total*50);
total = (int)amt/20;
printf("%d Note(s) of 20.00\n", total);
amt = amt-(total*20);
total = (int)amt/10;
printf("%d Note(s) of 10.00\n", total);
amt = amt-(total*10);
total = (int)amt/5;
printf("%d Note(s) of 5.00\n", total);
amt = amt-(total*5);
total = (int)amt/2;
printf("%d Note(s) of 2.00\n", total);
amt = amt-(total*2);
total = (int)amt/1;
printf("%d Note(s) of 1.00\n", total);
return 0;
}
30. Write a C program to convert a given integer (in seconds) to hours,
minutes and seconds.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int sec, h, m, s;
printf("Input seconds: ");
scanf("%d", &sec);
h = (sec/3600);
m = (sec-(3600*h))/60;
s = (sec-(3600*h) - (m*60));
printf("H:M:S - %d:%d:%d\n", h,m,s);
return 0;
}
31. Write a C program to convert a given integer (in days) to years, months
and days, assuming that all months have 30 days and all years have 365
days.
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int ndays, y, m, d;
printf("Input no. of days: ");
scanf("%d", &ndays);
y = (int)ndays/365;
ndays = ndays - (365*y);
m = (int)ndays/30;
d = (int)ndays - (m*30);
printf("%d Year(s) \n %d Month(s) \n %d Day(s)",
y,m,d);
return 0;
}
32. Write a C program that accepts 4 integers p, q, r, s from the user where q,
r and s are positive and p is even. If q is greater than r and s is greater than p
and if the sum of r and s is greater than the sum of p and q print "Correct
values", otherwise print "Wrong values".
#include<stdio.h>
int main()
{
printf("ID:2102064\n\n");
int p, q, r, s;
printf("\nInput the first integer: ");
scanf("%d", &p);
printf("\nInput the second integer: ");
scanf("%d", &q);
printf("\nInput the third integer: ");
scanf("%d", &r);
printf("\nInput the fourth integer: ");
scanf("%d", &s);
if((q > r) && (s > p) && ((r + s) > (p + q)) && (r >
0) && (s > 0) && (p%2 == 0))
{
printf("\nCorrect Values\n");
}
else
{
printf("\nWrong Values\n");
}
return 0;
}