C Practice Set

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

C Practice Set [Basic Programs]

1. Write a program in C to display the message " welcome to


c
program in C me writing?
2. Write a program in C to find the area of circle?
3. Write a program in C to find the area of triangle ?
4. Write a program in C to find the area of sphere?
5. Write a program in C to find the circumference of circle?
6. Write a program in C to find the area of circle using input
value?
7. Write a program in C to find the area of triangle using input
value?
8. Write a program in C to find the area of sphere using input
value?
9. Write a program in C to find the circumference of circle using
input
value?
10.Write a program in C to read and print a given character?
11. Write a program in C to print the ASCII value of given
character?
12. Write a program in C to read and print the given integer?
13. Write a program in C to read and print the given float?
14. Write a program in C to read and print the given float with
two
decimal places?
15. Write a program in C to read and print the given double?
16. Write a program in C to read and print the given double with
two
decimal places?
17. Write a program in C to Arithmetic operations of two integer
numbers?
18. Write a program in C to Arithmetic operations of two integer
numbers. Print these results in separate lines?
19. Write a program in C to Arithmetic operations of two long
numbers. Print these results in separate lines?
20. Write a program in C to Arithmetic operations of two float
numbers. Print these results in separate lines?
21. Write a program in C to Arithmetic operations of two double
numbers. Print these results in separate lines?
22. Write a program in C to print the upper case letters to lower
case?
23. Write a program in C to print the lower case letters to upper

case?
24. Write a program in C to read float value and print integer
equivalent?
25. Write a program in C to read int value and print float
equivalent?
hide
Solutions:

/* Program no: 1 */
/* Purpose: display the message */
#include
int main()
{
printf("%s"," welcome to c programming writting");
}

/* program no : 2 */
/* purpose : area of circle with out reading input */
#include
int main()
{
double radius=0.0,area;
area= 3.14 * radius * radius;
printf("%lf", area);
}

/* program no : 3 */
/* purpose : area of triangle with out reading input */
#include
int main()
{
double breath=5.0,height=4.0,area;
area= 0.5 * breath * height;

printf("%lf", area);
}

/* program no : 4 */
/* purpose : area of sphere with out reading input */
#include
int main()
{
double radious=5.0,area;
area= 4.0/3.0 * 3.14 * radious * radious ;
printf("%lf", area);
}

/* program no : 5 */
/* purpose : circumference of circle with out reading input */
#include
int main()
{
double radious=5.0,circum;
circum= 2*3.14*radious;
printf("%lf", circum);
}

/* program no : 6 */
/* purpose : area of circle with reading input */
#include
int main()
{

double radius,area;
scanf("%lf",&radius);
area= 3.14 * radius * radius;
printf("%lf", area);
}

/* program no : 7 */
/* purpose : area of triangle with reading input */
#include
int main()
{
double breath,height,area;
scanf("%lf%lf", &breath,&height);
area= 0.5 * breath * height;
printf("%lf", area);
}

/* program no : 8 */
/* purpose : area of sphere with reading input */
#include
int main()
{
double radius, area;
scanf("%lf",&radius);
area= 4.0/3.0 * 3.14 * radius * radius *radius;
printf("%lf", area);
}

/* program no : 8 */
/* purpose : area of sphere with reading input */

#include
int main()
{
double radius, area;
scanf("%lf",&radius);
area= 4.0/3.0 * 3.14 * radius * radius *radius;
printf("%lf", area);
}

/* program no : 9 */
/* purpose : circumference of circle with reading input */
#include
int main()
{
double radius,circum;
scanf("%lf", & radius);
circum= 2*3.14*radius;
printf("%lf", circum);
}

/* program no : 10 */
/* purpose : read and print the given character */
#include
int main()
{
char any;
scanf("%c", &any);
printf("%c", any);
}

/* program no : 11 */
/* purpose : read and print the ascii value of the given character */
#include
int main()
{
char any;
scanf("%c", &any);
printf("%d", any);
}

/* program no : 12 */
/* purpose : read and print the given integer */
#include
int main()
{
int any;
scanf("%d", &any);
printf("%d", any);
}

/* program no : 13 */
/* purpose : read and print the given float */
/#include
int main()
{
float any;
scanf("%f", &any);
printf("%f", any);
}

/* program no : 14 */
/* purpose : read and print the given float with two decimal places */
#include
int main()
{
float any;
scanf("%f", &any);
printf("%10.2f", any);
}

/* program no : 15 */
/* purpose : read and print the given double */
#include
int main()
{
double any;
scanf("%lf", &any);
printf("%lf", any);
}

/* program no : 16 */
/* purpose : read and print the given double */
#include
int main()
{
double any;
scanf("%lf", &any);
printf("%10.2lf", any);
}

/* program no : 17 */
/* purpose : Arithmetic operations of two integer numbers */
#include
int main()
{
int one,two;
scanf("%d%d", &one,&two);
printf("%d%d%d%d%d",one+two,one-two,one*two,one/two,one%two);
getch();
}

/* program no : 18 */
/* purpose : Arithmetic operations of two integer numbers */
#include
int main()
{
int one,two;
scanf("%d%d", &one,&two);
printf("%d\n%d\n%d\n%d\n%d",one+two,one-two,one*two,one/two,one
%two);
}

/* program no : 19 */
/* purpose : Arithmetic operations of two long numbers */
#include
int main()
{

long int one,two;


scanf("%ld%ld", &one,&two);
printf("%ld\n%ld\n%ld\n%ld\n%ld",one+two,onetwo,one*two,one/two,one%two);
}

/* program no : 20 */
/* purpose : Arithmetic operations of two float numbers */
#include
int main()
{
float one,two;
scanf("%f%f", &one,&two);
printf("%f\n%f\n%f\n%f",one+two,one-two,one*two,one/two);
}

/* program no : 21 */
/* purpose : Arithmetic operations of two double numbers */
#include
int main()
{
double one,two;
scanf("%lf%lf", &one,&two);
printf("%lf\n%lf\n%lf\n%lf",one+two,one-two,one*two,one/two);
}

/* program no : 22 */

/* purpose : read and print upper to lower */


#include
int main()
{
char any;
scanf("%c", &any);
printf("%c", any+32);
}

/* program no : 23 */
/* purpose : read and print upper to lower */
#include
int main()
{
char any;
scanf("%c", &any);
printf("%c", any-32);
}

/* program no : 24 */
/* purpose : float to int */
#include
int main()
{
float one;
int two;
scanf("%f", &one);
two=(int)one;
printf("%d",two);

/* program no : 25 */
/* purpose : int to float */
#include
int main()
{
int one;
float two;
scanf("%d", &one);
two=(float)one;
printf("%f",two);
}

You might also like