0% found this document useful (0 votes)
4 views

C PROGRAM 4

The document is a practical list of C programming exercises for students in standard 10, covering various topics such as generating outputs, performing arithmetic operations, calculating areas and volumes, making conversions, and simple decision structures. It includes example codes for creating shapes like huts and Christmas trees, performing arithmetic operations like addition and subtraction, and checking student pass/fail status based on marks. Each section contains multiple example programs with detailed comments and instructions.

Uploaded by

patelmona936
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

C PROGRAM 4

The document is a practical list of C programming exercises for students in standard 10, covering various topics such as generating outputs, performing arithmetic operations, calculating areas and volumes, making conversions, and simple decision structures. It includes example codes for creating shapes like huts and Christmas trees, performing arithmetic operations like addition and subtraction, and checking student pass/fail status based on marks. Each section contains multiple example programs with detailed comments and instructions.

Uploaded by

patelmona936
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 13

C PROGRAMS PRACTICAL LIST – STD – 10

 Write c program to generate following output


1) Hut
#include<stdio.h>
#define p printf
void main()
{
p(" \n\t\t\t ******************** ");
p(" \n\t\t\t * * * ");
p(" \n\t\t\t * * * ");
p(" \n\t\t\t * * * ");
p(" \n\t\t\t * ********************* ");
p(" \n\t\t\t * * **** **** * ");
p(" \n\t\t\t * * * * **** * ");
p(" \n\t\t\t * * * * * ");
p(" \n\t\t\t *************************** ");
p("\n\n");
}
2) Night Lamp
#include<stdio.h>
#define p printf
void main()
{
p("\n\t\t\t ******************************* ");
p("\n\t\t\t * * ");
p("\n\t\t\t * * ");
p("\n\t\t\t ******************************* ");
p("\n\t\t\t * * ");
p("\n\t\t\t * * ");
p("\n\t\t\t * * ");
p("\n\t\t\t * * ");
p("\n\t\t\t * * ");
p("\n\t\t\t * * ");
p("\n\t\t\t * * ");
p("\n\t\t\t ******************************** ");
p("\n\t\t\t * * * * * * * * * ");
p("\n\t\t\t * * * * * * * * * ");
p("\n\t\t\t * * * * * * * * * ");
3) Christmas Tree 4) Scene
4) First Letter of your Name:
#include<stdio.h>
#define p printf
void main()
{
p(" \n\t\t\t * * ");
p(" \n\t\t\t * * ");
p(" \n\t\t\t * * ");
p(" \n\t\t\t * * ");
p(" \n\t\t\t * * ");
p(" \n\t\t\t ******************* ");
p(" \n\t\t\t * * ");
p(" \n\t\t\t * * ");
p(" \n\t\t\t * * ");
p(" \n\t\t\t * * ");
p(" \n\t\t\t * * ");
p(" \n\t\t\t * * ");
p("\n\n");
}
 Write a C program to perform simple Arithmetic
1) Addition of two numbers
#include<stdio.h>
void main()
{
int a, b, result;
printf("\n Please enter first value:");
scanf("%d", &a);
printf("\n Please enter second value:");
scanf("%d", &b);

result = a + b;
printf("\n Addition of %d and %d is %d",a, b,result);
printf("\n\n");
}
2) Subtraction of second number from first
#include<stdio.h>
void main()
{
int a, b, result;
printf("\n Please enter first value:");
scanf("%d", &a);
printf("\n Please enter second value:");
scanf("%d", &b);

result = a - b;
printf("\n Subtraction of %d from %d is %d", a, b, result);
printf("\n\n");
}
3) Multiplication of two numbers
#include<stdio.h>
void main()
{
int a, b, result;
printf("\n Please enter first value:");
scanf("%d", &a);
printf("\n Please enter second value:");
scanf("%d", &b);

result = a * b;
printf("\n Multiplication of %d and %d is %d", a, b, result);
printf("\n\n");
}
4) Division of first number by second
#include<stdio.h>
void main()
{
float a, b, result;
printf("\n Please enter first value:");
scanf("%f", &a);
printf("\n Please enter second value:");
scanf("%f", &b);

result = a / b;
printf("\n Division of %.2f by %.2f is %.2f",a, b,result);
printf("\n\n");
}

5) Calculate Simple Interest


#include<stdio.h>
void main()
{
float P, R, N;
float I;
printf("\n Please enter Principal amount:");
scanf("%f", &P);
printf("\n Please enter rate of interest:");
scanf("%f", &R);
printf("\n Please enter total duration in years:");
scanf("%f", &N);

I = (P * R * N)/100;
printf("\n Principal Amount: %10.2f", P);
printf("\n Rate of Interest: %10.2f", R);
printf("\n Total Duration in years: %10.2f", N)
printf("\n Calculated Interest: %10.2f", I);
printf("\n\n");
}
6) Find profit and Loss
#include<stdio.h>
void main()
{
float cp, sp;
printf("\nPlease enter cost price of the product: ");
scanf("%f", &cp);
printf("\nPlease enter selling price of the product: ");
scanf("%f", &sp);

if(sp > cp)


{
printf(" \nHere we get a profit.");
printf(" \nProfit amount: %.2f", (sp-cp));
}
else
{
printf(" \nHere we will be in loss.");
printf(" \nLoss Amount: %.2f", (cp-sp));
}
printf("\n\n");
}
7) Swapping the value of two variables
#include<stdio.h>
void main()
{
int a, b, temp;
a = 10;
b = 15;
printf("\nValues before swapping:");
printf("\na = %d, b = %d", a, b);
temp=a;
a=b;
b=temp;
printf("\n=======================");
printf("\nValues after swapping:");
printf("\na = %d, b = %d", a, b);
printf("\n\n");
}

 Area and volume


1) Area of circle
#include<stdio.h>
#define PI 3.14
void main()
{
float r, A ;
printf("\n Enter the Radius : ");
scanf("%f",&r);

A = PI * r * r;
printf("\nThe area of Circle with Radius %.2f is %.2f", r, A);
printf("\n\n");
}
2) Circumference of circle
#include<stdio.h>
#define PI 3.14
void main()
{
float r, c;
printf("\n Enter the Radius of Circle :");
scanf("%f", &r);

c = 2 * PI * r;
printf("\n The Circumference of a circle of Radius %.2f is %.2f", r,
c);
printf("\n\n");
}
3) Area of Square
#include<stdio.h>
void main()
{
float a , A;
printf("\n Enter the length:");
scanf("%f", &a);
A = a * a;
printf("\n The area of Square of Length %.2f is %.2f",a, A);
printf("\n\n");
}
4) Perimeter of Square
#include<stdio.h>
void main()
{
float P , a;
printf("\n Enter the length :");
scanf("%f", &a);
P = 4 * a;
printf("\n The perimeter of Square of Length %.2f is %.2f",a , P);
printf("\n\n");
}
5) Area of Rectangle
#include<stdio.h>
void main()
{
float A, L, B;
printf("\n Enter the length :");
scanf("%f",&L);
printf("\n Enter the Breadth :");
scanf("%f",&B);

A = L * B;
printf("\n The area of rectangle of length %.2f and breadth %.2f is
%.2f", L , B, A);
printf("\n\n");
}
6) Perimeter of Rectangle
#include<stdio.h>
void main()
{
float P, L, B;
printf("\n Enter the length :");
scanf("%f",&L);
printf("\n Enter the Breadth :");
scanf("%f",&B);

P = 2*(L + B);
printf("\n The area of rectangle of length %.2f and breadth %.2f is
%.2f", L , B, P);
printf("\n\n");
}
7) Area of Triangle
#include<stdio.h>
void main()
{
float A, L, B;
printf("\n Enter the length :");
scanf("%f",&L);
printf("\n Enter the Breadth :");
scanf("%f",&B);

A = (L * B)/2;
printf("\n The area of Triangle of length %.2f and breadth %.2f is
%.2f", L , B, A);
printf("\n\n");
}
8) Volume of cylinder
#include<stdio.h>
#define PI 3.14
void main()
{
float V, r, h;
printf("\n enter the radius of Cylinder :");
scanf("%f", &r);
printf("\n Enter the height of Cylinder :");
scanf("%f", &h );

V = PI * r * r * h;
printf("\n The volume of Cylinder of radius %f and height %f is %f
",r,h,V);
printf("\n\n");
}
9) Volume of Cone
#include<stdio.h>
#define PI 3.14
void main()
{
float V, r, h;
printf("\n enter the radius of Cone :");
scanf("%f", &r);
printf("\n Enter the height of Cone :");
scanf("%f", &h );

V = (PI * r * r * h)/3;
printf("\n The volume of cone of radius %f and height %f is %f
",r,h,V);
printf("\n\n");
}
10) Volume of sphere
#include<stdio.h>
#define PI 3.14
void main()
{
float V, r;
printf("\n enter the radius of Sphere :");
scanf("%f", &r);

V = (PI * r * r * r)*1.33;
printf("\n The volume of Sphere with radius %f is %f”, r, V);
printf("\n\n");
}
 Conversions
1) Meters to Centimeters
#include<stdio.h>
void main()
{
float cm, m;
printf("\n Please enter the measurement in meters:");
scanf("%f", &m);

cm = m*100;
printf("\n Entered measurement in centimeters: %.2f", cm);
printf("\n\n");
}
2) Centimeters to Meters
#include<stdio.h>
void main()
{
float cm, m;
printf("\n Please enter the measurement in centimeters:");
scanf("%f", &cm);

m = cm/100;
printf("\n Entered measurement in meters: %.2f", m);
printf("\n\n");
}
3) Meters to Kilometers
#include<stdio.h>
void main()
{
float Km, m;
printf("\n Enter the measurement in meters:");
scanf("%f", &m);

Km = m / 1000;
printf("\n Entered measurement in Kilometers: %.2f", Km);
printf("\n\n");
}
4) Kilometers to meters
#include<stdio.h>
void main()
{
float Km, m;
printf("\n Enter the measurement in meters:");
scanf("%f", &m);

m = Km * 1000;
printf("\n Entered measurement in meters: %.2f", m);
printf("\n\n");
}
5) Grams to Kilograms
#include<stdio.h>
void main()
{
float Kg, g;
printf("\n Enter the weight in Grams :");
scanf("%f", &g);

Kg = g / 1000;
printf("\n Entered weight in kilograms %.2f", Kg);
printf("\n\n");
}
6) Kilograms to grams
#include<stdio.h>
void main()
{
float Kg, g;
printf("\n Enter the weight in Kilograms :");
scanf("%f", Kg&);

g = Kg * 1000;
printf("\n Entered weight in kilograms %.2f", g);
printf("\n\n");
}
7) Kilometer to miles
#include<stdio.h>
void main()
{
float km, mile;
printf("\n Please enter the measurement in kilometers:");
scanf("%f", &km);

mile = km/1.609;
printf("\n Entered measurement in miles: %.2f", mile);
printf("\n\n");
}
8) Miles to Kilometers
#include<stdio.h>
void main()
{
float km, mile;
printf("\n Please enter the measurement in miles:");
scanf("%f", &mile);

km = mile * 1.609;
printf("\n Entered measurement in kilometers: %.2f", km);
printf("\n\n"); }
9) Capital Letter to Small
#include<stdio.h>
void main()
{
char cap, small;
printf("\n Please enter the character in capital letter:");
scanf("%c", &cap);
printf("\n ASCII value of %c is %d", cap, cap);
small = cap + 32;

printf("\n Entered character in small letter: %c", small);


printf("\n ASCII value of %c is %d", small, small);
printf("\n\n");
}
10) Small Letter to Capital
#include<stdio.h>
void main()
{
char cap, small;
printf("\n Please enter the character in small letter:");
scanf("%c", &small);

cap = small - 32;


printf("\n Entered character in capital letter: %c", cap);
printf("\n\n");
}
11) Fahrenheit to Celsius
#include<stdio.h>
void main()
{
float F, C;
printf("\nEnter the temperature in Fahrenheit :");
scanf("%f", &F);

C = (F-32) * 5/9;
printf("\n The entered Temperature in Celsius %.2f", C);
printf("\n\n");
}
12) Celsius to Fahrenheit
#include<stdio.h>
void main()
{
float F, C;
printf("\nEnter the temperature in Celsius :");
scanf("%f", &C);

F = (C + 32) * 9/5;
printf("\n Th entered Temperature of %.2f is %.2f", C , F);
printf("\n\n");
}

 Simple Decision Structure


1) Check whether student is pass or fail (1 Subject)
#include<stdio.h>
void main()
{
int mark;
printf("\n Please enter your marks: ");
scanf("%d", &mark);
if(mark>32)
{
printf("\n Congratulations... You are PASS.");
}
else
{
printf("\n Sorry... You are fail.");
}
printf("\n\n");
}
2) Check whether student is pass or fail (5 Subject)
#include<stdio.h>
void main()
{
int m1, m2, m3, m4, m5;
printf("\n Please enter your marks: ");
scanf("%d %d %d %d %d", &m1, &m2, &m3, &m4, &m5);

if(m1>32 && m2>32 && m3>32 && m4>32 && m5>32)


{
printf("\n Result: PASS.");
}
else
{
printf("\n Result : FAIL.");
}
printf("\n\n");
}
3) Check whether given number is even or odd
#include<stdio.h>
void main()
{
int num;
printf("\n Please enter the number: ");
scanf("%d", &num);

if(num%2==0)
{
printf("\n Given number is Even");
}
else
{
printf("\n Given number is Odd");
}
printf("\n\n");
}
4) Check whether person is eligible to vote or not
#include<stdio.h>
void main()
{
int age;
printf("\n Please enter the age: ");
scanf("%d", &year);

if(age > 17)


{
printf("\n You are eligible to vote");
}
else
{
printf("\n You are not eligible to vote ");
}
printf("\n\n");
}
5) Check whether entered year is leap year or not.
#include<stdio.h>
void main()
{
int year;

printf("\n Please enter the year: ");


scanf("%d", &year);

if(year%4==0)
{
printf("\n Given year is Leap year");
}
else
{
printf("\n Given year is not a Leap year");
}
printf("\n\n");
}
 Complex Decision Structures
1) Find grade of student based on the percentage
#include<stdio.h>
void main()
{
char grade;
float perc;
printf("\n Please enter your percentage: ");
scanf("%f", &perc);
if(perc > 85)
{
grade = 'A';
}
else if(perc > 70)
{
grade = 'B';
}
else if(perc > 55)
{
grade = 'C';
}
else if(perc > 40)
{
grade = 'D';
}
else if(perc > 32)
{
grade = 'E';
}
else
{
grade = 'F';
}
printf("\n Your Percentage: %.2f", perc);
printf("\n your grade: %c", grade);
printf("\n\n");
}
2) Find maximum number among given three numbers.
#include<stdio.h>
void main()
{
int a, b, c;
printf("\n Please enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if(a>b && a>c)
{
printf("%d is Maximum.", a);
}
else if(b>a && b>c)
{
printf("%d is Maximum.", b);
}
else
{
printf("%d is Maximum.", c);
}
printf("\n\n");
}
3) Calculate commission of salesman as per the criteria:
Sale > 20000  15%, >15000  10%, > 10000  5%, <=1000  nil
#include<stdio.h>
void main()
{
float sale;
float cmsn;

printf("\n Please enter the selling of salesman:");


scanf("%f", &sale);

if( sale >= 20000)


{
cmsn=(sale * 0.15);
}
else if(sale >= 15000)
{
cmsn=(sale * 0.10);
}
else if(sale >= 10000)
{
cmsn=(sale * 0.05);
}
else
{
cmsn = 0;
}
printf("\n Total Selling of Salesman :%10.2f", sale);
printf("\n Total Commision of Salesman :%10.2f",cmsn);
printf("\n Total Payable Amount :%10.2f",(sale + cmsn));
printf("\n\n");
}
4) Do operations based on choices given (switch case)
#include<stdio.h>
void main()
{

int num1, num2, choice;


printf("Enter two numbers:");
scanf("%d %d", &num1, &num2);

printf("\nMENU OF ARITHMETIC OPERATIONS:");


printf("\n1 - Addition");
printf("\n2 - Subtraction");
printf("\n3 - Multiplication");
printf("\n4 - Addition");
printf("\n Enter your choice:");
scanf("%d", &choice);

switch(choice)
{
case 1: printf("\n Addition of %d and %d is %d",num1,num2, (num1+num2));
break;
case 2: printf("\n Subtraction of %d from %d is %d", num2, num1, (num1-num2));
break;
case 3: printf("\n Multiplication of %d and %d is %d", num1, num2,
(num1*num2));
break;
case 4: printf("\n Division of %d by %d is %f",num1, num2,(num1/(float)num2));
break;
default: printf("\n You have entered invalid choice... please try again.
");
break;
}
printf("\n\n");
}
5) Check whether given number is prime or not
#include<stdio.h>
void main()
{
int num, i;
int prime=1;
printf("\nPlease enter the number:");
scanf("%d", &num);
for(i=2; i<=(num-1); i++)
{
if(num%i==0)
{
prime=0;
break;
}
}
if(prime==1)
{
printf("\n %d is a prime number", num);
}
else
{
printf("\n %d is not a prime number", num);
}
printf("\n\n"); }
 Simple Loop Structures
1) Generate 1 to 10 horizontally.
#include<stdio.h>
void main()
{
int i;
printf("\n1 to 10 horizontally.\n\n");
for(i=1;i<=10;i++)
{
printf("%d \t",i);
}
printf("\n\n");
}
2) Generate 1 to 10 vertically.
#include<stdio.h>
void main()
{
int i;
printf("\n1 to 10 horizontally.\n\n");
for(i=1;i<=10;i++)
{
printf("%d \n",i);
}
printf("\n\n");

}
3) Generate table of any fixed number
#include<stdio.h>
void main()
{
int i;
printf("\n Table of 35\n");
for(i=1;i<=10;i++)
{
printf("\n\t 35 * %3d = %3d", i, 35*i);
}
printf("\n\n");
}
4) Generate Table of any entered number
#include<stdio.h>
void main()
{
int i, num;
printf("\n Please enter the number whose table you want:");
scanf("%d", &num);
for(i=1;i<=10;i++)
{
printf("\n\t %3d * %3d = %3d", num, i, num*i);
}
printf("\n\n");
}
5) Generate all Even numbers between 1 and 50
#include<stdio.h>
void main()
{
int i;
printf("\n All even numbers between 1 and 50");
for(i=1;i<=50;i++)
{
if(i%2==0)
{
printf("\n\t %3d",i);
}
}
printf("\n\n"); }
6) Generate all Odd numbers between 1 and 50
#include<stdio.h>
void main()
{
int i;
printf("\n All Odd numbers between 1 and 50");
for(i=1;i<=50;i++)
{
if(i%2!=0)
{
printf("\n\t %3d",i);
}
}
printf("\n\n");
}
7) Generate all Prime numbers between 1 and 100
#include<stdio.h>
void main()
{
int i,j;
int prime=1;
for(i=1;i<=100;i++)
{
int prime=1;
for(j=2; j<=(i/2); j++)
{
if(i%j==0)
{
prime=0;
break;
}
}
if(prime==1)
{
printf("\n\t %2d",i);
}
}
printf("\n\n");
}

8) Generate following structures**


**
***
****
*****
#include<stdio.h>
void main()
{
int i, j;
for(i=1; i<=5;i++)
{
for(j=1; j<=i;j++)
{
printf("*");
}
printf("\n");
}
printf("\n\n");
}

You might also like