0% found this document useful (0 votes)
9 views4 pages

c-programs

The document contains a collection of six C programming exercises aimed at BCom Business Statistics students at Rani Channamma University. Each exercise includes a brief description and the corresponding C code to perform tasks such as calculating the area and circumference of a circle, finding the largest of three numbers, demonstrating math library functions, checking for prime numbers, generating prime numbers, and manipulating digits of a number. The document serves as a practical guide for students to enhance their programming skills.

Uploaded by

okb9065
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)
9 views4 pages

c-programs

The document contains a collection of six C programming exercises aimed at BCom Business Statistics students at Rani Channamma University. Each exercise includes a brief description and the corresponding C code to perform tasks such as calculating the area and circumference of a circle, finding the largest of three numbers, demonstrating math library functions, checking for prime numbers, generating prime numbers, and manipulating digits of a number. The document serves as a practical guide for students to enhance their programming skills.

Uploaded by

okb9065
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/ 4

lOMoARcPSD|56042252

C-programs(1-6) - 2018-2019

Bcom business statistics (Rani Channamma University)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Ok Bro ([email protected])
lOMoARcPSD|56042252

1. Write a C Program to read radius of a circle and to find area and circumference
//C program to find the area of a circle and circumference of circle
#include<stdio.h>
void main()
{
float r;

printf("Enter radius:");
scanf("%f",&r);

printf("Area of Circle is: %.2f", 3.14*r*r);


printf("Circumference of a circle:%.2f", 2*3.14*r);

2. Write a C Program to read three numbers and find the biggest of three
#include <stdio.h>

int main()
{
int A, B, C;

printf("Enter the numbers A, B and C: ");


scanf("%d %d %d", &A, &B, &C);

if (A >= B && A >= C)


printf("%d is the largest number.", A);

if (B >= A && B >= C)


printf("%d is the largest number.", B);

if (C >= A && C >= B)


printf("%d is the largest number.", C);

return 0;
}

3. Write a C Program to demonstrate library functions in math.h


// C code to illustrate
// the use of sqrt function
#include <stdio.h>
#include <math.h>

int main ()
{
float val1, val2;

val1 = 1.6;
Downloaded by Ok Bro ([email protected])
lOMoARcPSD|56042252

val2 = 1.2;

printf ("value1 = %.1lf\n", ceil(val1));


printf ("value2 = %.1lf\n", ceil(val2));

printf("Value1 = %.1lf\n", floor(val1));


printf("Value2 = %.1lf\n", floor(val2));

printf("Square root of %lf is %lf\n", 225.0, sqrt(225.0) );


printf("Square root of %lf is %lf\n", 300.0, sqrt(300.0) );

return(0);
}

4. Write a C Program to check for prime

#include <math.h>
#include <stdio.h>
int main()
{
int n, i, flag = 1;

// Ask user for input


printf("Enter a number: \n");

// Store input number in a variable


scanf("%d", &n);

// Iterate from 2 to sqrt(n)


for (i = 2; i <= sqrt(n); i++) {

// If n is divisible by any number between


// 2 and n/2, it is not prime
if (n % i == 0) {
flag = 0;
break;
}
}

if (n <= 1)
flag = 0;

if (flag == 1) {
printf("%d is a prime number", n);
}
else {
printf("%d is not a prime number", n);
}

return 0;
}

5. Write a C Program to generate n primes


Downloaded by Ok Bro ([email protected])
lOMoARcPSD|56042252

#include<stdio.h>
#include<conio.h>
void main()
{
int n, i, j, count;
clrscr();
printf("Prime no.series\n");
printf("Enter any number\n");
scanf("%d", &n);
printf("The prime numbers between 1 to %d\n",n);
for(i = 1; i <= n; i++)
{
count = 0;
for(j = 1; j <=i; j++)
if(i % j == 0)
{
count++;
}
if(count == 2)
{
printf("%d\t", i);
}
}
getch();
}

6. Write a C 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( )
{
clrscr( )
int num,sum=0,rev=0,d;
printf("Enter the number: ");
scanf("%d",&n);

while(num){
d=num%10;
num=num/10;
sum=sum+d;
rev=rev*10+d;
}

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


printf("\nReverse of the number = %d",rev);
getch( );
}

Downloaded by Ok Bro ([email protected])

You might also like