1. Write a C program to print your name, date of birth. and mobile number.
Expected Output:
Name : Alexandra Abramov
DOB : July 14, 1975
Mobile : 99-9999999999
Cod:
#include <stdio.h>
int main(void){
printf ("Name : Alexandra Abramov \n");
printf ("DOB : July 14, 1975 \n");
printf("Mobile : 99-9999999999\n");
return 0;
2. Write a C program to get the C version you are using.
Expected Output:
We are using C18!
#include <stdio.h>
int main()
#if __STDC_VERSION__>=201710L
printf ("We are using C18\n");
#elif __STDC_VERSION__>=201112L
printf ("We are using version C11!\n");
#elif __STDC_VERSION__>=99409L
printf("We are using C95!\n");
#elif __STDC_VERSION__ >=199901L
printf ("we are using C99!\n");
#else
printf("We are using C89/C90!\n");
#endif
return 0;
In copilatorul dat de ex rezultatul va fi C18. Rezultatul difera in fct de compilatorul folosit.
3. Write a C program to print a block F using hash (#), where the F has a height
of six characters and width of five and four characters. And also to print a big 'C'.
Expected Output:
#include <stdio.h>
int main()
{
printf("######\n");
printf("#\n");
printf("#\n");
printf("#####\n");
printf("#\n");
printf("#\n");
printf("#\n");
return(0);
}
######
#
#
#####
#
#
#
#include <stdio.h>
int main()
{
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 a reverse way.
Test Characters: 'X', 'M', 'L'
Expected Output:
The reverse of XML is LMX
#include <stdio.h>
int main()
char char1 = 'X';
char char2 = 'M';
char char3 ='L';
printf ("The reverse of %c%c%c is %c%c%c" ,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.
Expected Output:
Perimeter of the rectangle = 24 inches
Area of the rectangle = 35 square inches
#include <stdio.h>
int main()
int height = 7;
int width =5;
int Perimeter=(2*height+2*width);
int area=height*width;
printf ("Perimeter of the rectangle=%d inches\n", Perimeter);
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 radius
of 6 inches.
Expected Output:
Perimeter of the Circle = 37.680000 inches
Area of the Circle = 113.040001 square inches
#include <stdio.h>
int main()
int radius=6;
float perimeter=2*3.14*radius;
float area=3.14*radius*radius;
printf("Perimeter of the Circle =%f inches\n", perimeter);
printf ("Area of the Circle = %f square inches", area);
return 0;
7. Write a C program to display multiple variables. Sample Variables :
a+ c, x + c,dx + x, ((int) dx) + ax, a + x, s + b, ax + b, s + c, ax + c, ax + ux
Declaration :
int a = 125, b = 12345;
long ax = 1234567890;
short s = 4043;
float x = 2.13459;
double dx = 1.1415927;
char c = 'W';
unsigned long ux = 2541567890;
#include <stdio.h>
int main()
{
int a = 125, 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=%ld\n", ((int) dx) + ax); //long double
printf ("a + x=%f\n", a+x);
printf ("s + b=%d\n", s+b);
printf ("ax + b=%ld\n", ax+b);
printf ("s + c=%hd\n", s+c); // hd- Unsigned Integer(Short)
printf ("ax + c=%ld\n", ax+c);
printf ("ax + ux=%lu\n", ax+ux);
return 0;
}
8. Write a C program to convert specified days into years, weeks and days.
Note: Ignore leap year.
Test Data :
Number of days : 1329
Expected Output :
Years: 3
Weeks: 33
Days: 3
#include <stdio.h>
int main()
int days;
int weeks;
int years;
days=1329;
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 calculate the
sum of the two integers.
Test Data :
Input the first integer: 25
Input the second integer: 38
Expected Output:
Sum of the above two integers = 63
#include <stdio.h>
int main()
int a, b, sum;
printf ("Input the firs integer: ");
scanf ("%d", &a);
printf ("Input the second integer: ");
scanf ("%d", &b);
sum=a+b;
printf ("Sum of the above two integers = %d\n", sum);
return 0;
10. Write a C program that accepts two integers from the user and calculate the
product of the two integers.
Test Data :
Input the first integer: 25
Input the second integer: 15
Expected Output:
Product of the above two integers = 375
#include <stdio.h>
int main()
int a, b, product;
printf ("Input the firs integer: ");
scanf ("%d", &a);
printf ("Input the second integer: ");
scanf ("%d", &b);
product=a*b;
printf ("Product of the above two integers = %d\n", product);
return 0;
11. Write a C program that accepts two item’s weight (floating points' values )
and number of purchase (floating points' values) and calculate the average value
of the items.
Test Data :
Weight - Item1: 15
No. of item1: 5
Weight - Item2: 25
No. of item2: 4
Expected Output:
Average Value = 19.444444