Program1 To 4
Program1 To 4
C PROGRAMMING LAB
PART – A
1. Program to read radius of a circle and to find area and circumference
2. Program to read three numbers and find the biggest of three
3. Program to demonstrate library functions in math.h
4. Program to check for prime
5. Program to generate n primes
6. Program to read a number, find the sum of the digits, reverse the number and check it for
palindrome
7. Program to read numbers from keyboard continuously till the user presses 999 and to find
the sum of only positive numbers
8. Program to read percentage of marks and to display appropriate message (Demonstration
of else-if ladder)
9. Program to find the roots of quadratic equation (demonstration of switch Case statement)
10. Program to read marks scored by n students and find the average of marks
(Demonstration of single dimensional array)
11. Program to remove Duplicate Element in a single dimensional Array
12. Program to perform addition and subtraction of Matrices
PART – B
13. Program to find the length of a string without using built in function
14. Program to demonstrate string functions
15. Program to demonstrate pointers in C
16. Program to check a number for prime by defining isprime() function
17. Program to read, display and to find the trace of a square matrix
18. Program to read, display and add two m x n matrices using functions
19. Program to read, display and multiply two m x n matrices using functions
20. Program to read a string and to find the number of alphabets, digits, vowels, consonants,
spaces and special characters
21. Program to Reverse a String using Pointer
22. Program to Swap Two Numbers using Pointers
23. Program to demonstrate student structure to read & display records of n students
24. Program to demonstrate the difference between structure & union
1
C PROGRAMMING LAB
Exercise: 1
Date:
Write C program to read radius of a circle and to find area and circumference.
AIM
To write a C program to read radius of a circle and to find area and circumference.
The basic formula for area of a circle and circumference of circle.
Area of Circle = PI * R * R
Circumference of Circle = 2 * PI * R
ALOGRITHM
Step 1: Start the process.
Step 2: Input the radius of the circle either from the user or specify it.
Step 3: Calculate the area of circle and circumference with the formula specified along with
radius defined.
Step 4: Display the result.
Step 5: Stop the process.
PROGRAM
// A C Program to read radius of a circle and find area and circumference of it
#define PI 3.1416
#include<stdio.h>
#include<conio.h>
void main()
{
float radius, area, circumference;
clrscr();
printf("Enter the radius of a circle:\n");
scanf("%f",&radius);
area=PI * radius * radius;
circumference=2.0 * PI * radius;
printf("Area of Circle is %f\n",area);
printf("Circumference of Circle is %f\n",circumference);
getch();
}
2
C PROGRAMMING LAB
INPUT/OUTPUT
RESULT
Thus the above program has been executed and its output verified successfully using Turbo C
IDE and Command prompt.
3
C PROGRAMMING LAB
Exercise: 2
Date:
Write a C program to read three numbers and find the biggest of three.
AIM
To write a C program to read three numbers and find the biggest of three.
ALOGRITHM
Step 1: Start the process
Step 2: Input the three numbers.
Step 3: Compare the three numbers using if … else if … else statement.
Step 4: Display the biggest as result.
Step 5: Stop the process
PROGRAM
// A C Program to read three numbers and the find the biggest of three
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the three numbers:\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
printf("Biggest is %d\n",a);
else if (b>c)
printf("Biggest is %d\n",b);
else
printf("Biggest is %d\n",c);
getch();
}
4
C PROGRAMMING LAB
INPUT/OUTPUT
RESULT
Thus the above program has been executed and its output verified successfully using Turbo C
IDE and Command prompt.
5
C PROGRAMMING LAB
Exercise: 3
Date:
AIM
To write a C program to demonstrate library functions in math.h.
ALOGRITHM
Step 1: Start the process.
Step 2: Apply mathematical function contained in math.h.
Step 3: Display the result.
Step 4: Stop the process
PROGRAM
//A C Program to demonstrate library functions in math.h
#include<stdio.h>
#include<math.h>
#include<conio.h>
int main()
{
clrscr();
printf("\nResult of ceil(3.6) is %f",ceil(3.6));
printf("\nResult of ceil(3.3) is %f",ceil(3.3));
printf("\nResult of floor(3.6) is %f",floor(3.6));
printf("\nResult of floor(3.2) is %f",floor(3.2));
printf("\nResult of sqrt(16) is %f",sqrt(16));
printf("\nResult of sqrt(7) is %f",sqrt(7));
printf("\nResult of pow(2,4) is %f",pow(2,4));
printf("\nResult of pow(3,3) is %f",pow(3,3));
printf("\nResult of abs(-12) is %d",abs(-12));
getch();
return 0;
}
6
C PROGRAMMING LAB
INPUT/OUTPUT
RESULT
Thus the above program has been executed and its output verified successfully using Turbo C
IDE and Command prompt.
7
C PROGRAMMING LAB
Exercise: 4
Date:
AIM
To write a C program to check for prime.
ALOGRITHM
Step 1: Start the process.
Step 2: Input the number.
Step 3: Check whether the number is prime or not using for and if statements.
Step 4: Display the result.
Step 5: Stop the process
PROGRAM
// A C Program to check whether the given number is prime or not
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,f=0;
clrscr();
printf("Enter the number:\n");
scanf("%d",&num);
for(i=2;i<num;i++)
if((num%i)==0) f=1;
if(f==0)
printf("%d is a prime number\n",num);
else
printf("%d is not a prime number\n",num);
getch();
}
8
C PROGRAMMING LAB
INPUT/OUTPUT
RESULT
Thus the above program has been executed and its output verified successfully using Turbo C
IDE and Command prompt.
9
C PROGRAMMING LAB
Exercise: 5
Date:
AIM
To write a C program to generate n primes.
ALOGRITHM
Step 1: Start the process.
Step 2: Input the number of prime numbers to be generated.
Step 3: Check whether the number is prime or not using for and if statements.
Step 4: Display the number if it is prime.
Step 5: Repeat the Step 3 thru Step 4 until the number of prime number to be reached.
Step 6: Stop the process
PROGRAM
// A C Program to generate a set of prime numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j=1,count=0,f;
clrscr();
printf("Enter how many prime numbers?\n");
scanf("%d",&n);
printf("The %d prime numbers are as follows:\n",n);
while(count<n)
{
f=0;
for(i=2;i<j;i++)
if((j%i)==0) f=1;
if(f==0)
{
printf("%d\n",j);
count++;
}
j++;
}
getch();
}
10