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

C Programs Week5

The document contains C programs for various functions including finding the cube of a number, calculating the diameter, circumference, and area of a circle, determining the maximum and minimum of two numbers, and checking if a number is even or odd. Each program is structured with a main function and specific functions to perform the required calculations. The programs prompt the user for input and display the results accordingly.

Uploaded by

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

C Programs Week5

The document contains C programs for various functions including finding the cube of a number, calculating the diameter, circumference, and area of a circle, determining the maximum and minimum of two numbers, and checking if a number is even or odd. Each program is structured with a main function and specific functions to perform the required calculations. The programs prompt the user for input and display the results accordingly.

Uploaded by

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

C PROGRAMS

WEEK 5

PROGRAM-16
16. Write a C program to find cube of any number using
function.

Program
/*Write a C program to find cube of any number using functions*/
#include<stdio.h>
void cube(int n);
int main()
{
int n;
printf("Enter the number:\t");
scanf("%d",&n);
cube(n);
return 0;
}

void cube(int n)
{
int c;
c=n*n*n;
printf("The Cube of %d is %d\n",n,c);
}
PROGRAM-17
17. Write a C program to find diameter, circumference and area
of circle using functions.

Program
/*Write a C program to find diameter, circumference and
area of circle using functions*/
#include<stdio.h>
#define PI 3.14
void doc(int r);
void coc(int r);
void aoc(int r);
float d,c,a;
int main()
{
int r;
printf("Enter the radius:\t");
scanf("%d",&r);
doc(r);
coc(r);
aoc(r);
return 0;
}

void doc(int r)
{
d=2*r;
printf("The Diameter of a circle with radius %d is %0.2f\n",r,d);
}

void coc(int r)
{
c=2*PI*r;
printf("The circumference of a circle with radius %d is %0.2f\n",r,c);

void aoc(int r)
{
a=PI*r*r;
printf("The Area of a circle with radius %d is %0.2f\n",r,a);
}
PROGRAM-18
18. Write a C program to find maximum and minimum between two
numbers using functions.

Program
/*Write a C program to find maximum and minimum between two
numbers using functions*/
#include<stdio.h>
int max(int n1,int n2);
int min(int n1,int n2);
int main()
{
int n1,n2,maximum,minimum;
printf("Enter two numbers:\t");
scanf("%d %d",&n1,&n2);
maximum=max(n1,n2);
minimum=min(n1,n2);
printf("The Maximum between %d and %d is %d\n",n1,n2,maximum);
printf("The Minimum between %d and %d is %d\n",n1,n2,minimum);
return 0;
}

int max(int n1,int n2)


{
return (n1>n2)?n1:n2;
}

int min(int n1,int n2)


{
return (n1<n2)?n1:n2;
}
PROGRAM-19
19. Write a C program to check whether a number is even or odd
using functions.

Program
/*Write a C program to check whether a number is even or odd
using functions*/
#include<stdio.h>
void evenodd(int n);
int main()
{
int n;
printf("Enter the number:\t");
scanf("%d",&n);
evenodd(n);
return 0;
}

void evenodd(int n)
{
(n%2==0)?printf("%d is Even Number",n):printf("%d is Odd Number",n);
}

You might also like