0% found this document useful (0 votes)
3 views23 pages

C Programming Part A

The document contains a series of C programming exercises aimed at first-semester BCA students, covering fundamental concepts such as calculating the area and circumference of a circle, finding the largest of three numbers, checking for prime numbers, and performing matrix operations. Each program includes code snippets demonstrating various programming techniques and concepts, including loops, conditionals, arrays, and mathematical functions. The exercises serve as practical applications for students to enhance their programming skills in C.

Uploaded by

freefirecsk1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views23 pages

C Programming Part A

The document contains a series of C programming exercises aimed at first-semester BCA students, covering fundamental concepts such as calculating the area and circumference of a circle, finding the largest of three numbers, checking for prime numbers, and performing matrix operations. Each program includes code snippets demonstrating various programming techniques and concepts, including loops, conditionals, arrays, and mathematical functions. The exercises serve as practical applications for students to enhance their programming skills in C.

Uploaded by

freefirecsk1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

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

Programming in C I Sem BCA


1. Program to read radius of a circle and to find area and circumference

#include <stdio.h>
#include <conio.h>
void main()
{
int rad;
float PI = 3.14, area, ci;
clrscr();

printf ("Enter radius of circle:\n");


scanf ("%d", &rad);

area = PI * rad * rad;


printf ("\nArea of circle : %f\n ", area);

ci = 2 * PI * rad;
printf("\nCircumference : %f\n ", ci);
getch();
}

Programming in C I Sem BCA


2. Program to read three numbers and find the biggest of three
#include <stdio.h>
#include <conio.h>
void main()
{
int a, b, c;
clrscr ();

printf ("Enter value of a, b & c :\n");


scanf ("%d %d %d", &a, &b, &c);

if ((a > b) && (a > c))


printf ("a is greatest\n");

if ((b > c) && (b > a))


printf ("b is greatest\n");

if ((c > a) && (c > b))


printf ("c is greatest\n");

getch();
}

Programming in C I Sem BCA


3. Program to demonstrate library functions in math.h
#include <stdio.h>
#include <conio.h>
#include <math.h>

void main()
{
printf ("%f\n",sqrt(10.0));

printf ("%f\n",exp(4.0));

printf ("%f\n",log(4.0));

printf ("%f\n",pow(3,3));

getch();
}

Programming in C I Sem BCA


4. Program to check for prime
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i;
clrscr ();

printf ("Enter the number for N\n");


scanf ("%d",&n);

for (i=2; i <= n / 2; i++)


{
if ( n % i == 0)
{
printf ("%d is not prime number\n",n);
exit(0);
}
}
printf ("%d is prime number\n",n);
getch();
}

Programming in C I Sem BCA


5. Program to generate n primes
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,n;
clrscr();

printf ("Enter the number till which you want prime numbers\n");
scanf ("%d",&n);

printf ("Prime numbers are:-\n");


for (i = 2; i <= n; i++)
{
int c = 0;
for (j = 1; j <= i; j++)
{
if (i%j == 0)
{
c++;
}
}
if (c == 2)
{
printf ("%d ",i);
}
}
getch();
}

Programming in C I Sem BCA


6. Program to read a number, find the sum of the digits, reverse the number and
check it for palindrome

#include<stdio.h>

#include<conio.h>

void main()

int n,m,rev,digit;

clrscr();

printf ("Enter the value for N\n");

scanf ("%d", &n);

m = n;

rev = 0;

while(n!=0)

{
digit = n % 10;
n = n / 10;
rev = rev * 10 + digit;
}
if (m == rev)

printf ("Given no is palindrome\n");

else

printf ("Given no is not palindrome\n");

getch();

Programming in C I Sem BCA


7. Program to read numbers from keyboard continuously till the user presses 999
and to find the sum of only positive numbers

#include<stdio.h>

#include<conio.h>

void main()

int value = 0;
int sum = 0;
clrscr();

while(sum != 999)

{
printf ("\nenter number:");
scanf ("%d", &value);

if (value == 999)
{
break;
}
else
{
sum = sum + value;
}

printf ("sum = %d",sum);


}
printf ("Final OutPut: %d",sum);
getch();
}

Programming in C I Sem BCA


8. Program to read percentage of marks and to display appropriate message
(Demonstration of else-if ladder)

#include<stdio.h>

#include<conio.h>

void main ()

float m1,m2,m3;

float per,avg;

float total;

clrscr();

printf ("enter the marks of m1\n");

scanf ("%f", &m1);

printf ("enter the marks of m2\n");

scanf ("%f", &m2);

printf ("enter the marks of m3\n");

scanf ("%f", &m3);

total= m1 + m2 + m3;

printf ("\nthe total mark is %.2f\n", total);

per = (total / 300)*100;

avg = (total / 3);

Programming in C I Sem BCA


printf ("the percentage mark is : %.2f\n", per);

printf ("the average mark is: %.2f\n\n", avg);

// Grade calculation

if (per >= 80)

printf ("Grade : A\n");

else if (per >= 60)

printf ("Grade : B\n");

else if (per >= 40)

printf ("Grade : C\n");

else if (per < 40)

printf ("Fail\n");

getch();

Programming in C I Sem BCA


Programming in C I Sem BCA
9. Program to find the roots of quadratic equation (demonstration of switch Case
statement)

#include <stdio.h>

#include<conio.h>

#include <math.h>

void main()

float a, b, c;

float root1, root2, imaginary;

float discriminant;

clrscr();

printf ("Enter values of a, b, c of quadratic equation (aX^2 + bX + c):\n");

scanf ("%f %f %f", &a, &b, &c);

/* Calculate discriminant */

discriminant = (b * b) - (4 * a * c);

/* Compute roots of quadratic equation based on the nature of discriminant */

switch(discriminant > 0)

case 1:

/* If discriminant is positive */

root1 = (-b + sqrt(discriminant)) / (2 * a);

Programming in C I Sem BCA


root2 = (-b - sqrt(discriminant)) / (2 * a);

printf ("Two distinct and real roots exists: %.2f and %.2f",root1, root2);

break;

case 0:

/* If discriminant is not positive */

switch(discriminant < 0)

case 1:

/* If discriminant is negative */

root1 = root2 = -b / (2 * a);

imaginary = sqrt(-discriminant) / (2 * a);

printf ("Two distinct complex roots exists: %.2f + i%.2f and %.2f - i%.2f",root1,
imaginary, root2, imaginary);

break;

case 0:

/* If discriminant is zero */

root1 = root2 = -b / (2 * a);

printf ("Two equal and real roots exists: %.2f and %.2f", root1, root2);

break;

Programming in C I Sem BCA


}

getch();

Programming in C I Sem BCA


10.Program to read marks scored by n students and find the average of marks
(Demonstration of single dimensional array)

#include<stdio.h>

#include<conio.h>

void main()

int n, i;

float num[100], sum = 0.0, avg;

clrscr();

printf ("Enter the numbers of students \n");

scanf ("%d", &n);

while (n > 100 || n < 1)

printf ("Error! number should in range of (1 to 100).\n");

printf ("Enter the number again: ");

scanf ("%d", &n);

for (i = 0; i < n; ++i)

printf ("%d. Enter number: ", i + 1);

scanf ("%f", &num[i]);

sum += num[i];

Programming in C I Sem BCA


}

avg = sum / n;

printf ("Average = %.2f", avg);

getch();

Programming in C I Sem BCA


11. Program to remove Duplicate Element in a single dimensional Array

#include<stdio.h>

#include<conio.h>

void main()

int arr[10], i, j, k, Size;

clrscr();

printf ("\n Please Enter Number of elements in an array:\n");

scanf ("%d", &Size);

printf ("\n Please Enter %d elements of an Array \n", Size);

for (i = 0; i < Size; i++)

scanf ("%d", &arr[i]);

for (i = 0; i < Size; i++)

for(j = i + 1; j < Size; j++)

if(arr[i] == arr[j])

for(k = j; k < Size; k++)


Programming in C I Sem BCA
{

arr[k] = arr[k + 1];

Size--;

j--;

printf ("\n Final Array after Deleteing Duplicate Array Elements is:\n");

for (i = 0; i < Size; i++)

printf ("%d\t", arr[i]);

getch();

Programming in C I Sem BCA


12. Program to perform addition and subtraction of Matrices

#include<stdio.h>
#include<conio.h>
void main()
{
int n, m, c, d, first[10][10], second[10][10], sum[10][10], diff[10][10];
clrscr();

printf ("\nEnter the number of rows and columns of the first matrix \n\n");
scanf ("%d%d", &m, &n);

printf ("\nEnter the %d elements of the first matrix \n\n", m*n);


for (c = 0; c < m; c++) // to iterate the rows
for (d = 0; d < n; d++) // to iterate the columns
scanf ("%d", &first[c][d]);

printf ("\nEnter the %d elements of the second matrix \n\n", m*n);


for (c = 0; c < m; c++) // to iterate the rows
for (d = 0; d < n; d++) // to iterate the columns
scanf ("%d", &second[c][d]);

/* printing the first matrix */

printf ("\n\nThe first matrix is: \n\n");


for (c = 0; c < m; c++) // to iterate the rows
{
for (d = 0; d < n; d++) // to iterate the columns
{
printf ("%d\t", first[c][d]);

Programming in C I Sem BCA


}
printf ("\n");
}

/* printing the second matrix */

printf ("\n\nThe second matrix is: \n\n");


for (c = 0; c < m; c++) // to iterate the rows
{
for (d = 0; d < n; d++) // to iterate the columns
{
printf ("%d\t", second[c][d]);
}
printf ("\n");
}

/* finding the SUM of the two matrices and storing in another matrix sum of the
same size */

for (c = 0; c < m; c++)

for (d = 0; d < n; d++)

sum[c][d] = first[c][d] + second[c][d];

// printing the elements of the sum matrix

printf ("\n\nThe sum of the two entered matrices is: \n\n");

for (c = 0; c < m; c++)

Programming in C I Sem BCA


{
for (d = 0; d < n; d++)
{
printf ("%d\t", sum[c][d]);
}
printf ("\n");
}

/*finding the DIFFERENCE of the two matrices and storing in another matrix
difference of the same size */

for (c = 0; c < m; c++)

for (d = 0; d < n; d++)

diff[c][d] = first[c][d] - second[c][d];

// printing the elements of the diff matrix

printf ("\n\nThe difference(subtraction) of the two entered matrices is: \n\n");


for (c = 0; c < m; c++)
{
for (d = 0; d < n; d++)
{
printf ("%d\t", diff[c][d]);
}
printf ("\n");
}
getch();
}

Programming in C I Sem BCA


Programming in C I Sem BCA
Programming in C I Sem BCA

You might also like