0% found this document useful (0 votes)
35 views5 pages

ASSIGMENT3

The document contains 4 programs demonstrating different C programming concepts: 1) Using a ternary operator to check the greatest of two numbers. 2) Using macros to initialize Pi and calculate the area and circumference of a circle. 3) Using the math.h library to calculate sine and power functions. 4) Illustrating the use of increment and decrement operators.

Uploaded by

ankitnit27
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)
35 views5 pages

ASSIGMENT3

The document contains 4 programs demonstrating different C programming concepts: 1) Using a ternary operator to check the greatest of two numbers. 2) Using macros to initialize Pi and calculate the area and circumference of a circle. 3) Using the math.h library to calculate sine and power functions. 4) Illustrating the use of increment and decrement operators.

Uploaded by

ankitnit27
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/ 5

COMPUTER PROGRAMMING LAB

Assignment 3
PROGRAM 1
//Write a program to check the greatest of two numbers by using the ternary
operator.

#include<stdio.h>

int main(){
int a,b;
printf("Enter two integers:\n");
scanf("%d %d", &a, &b);
a>=b?printf("The greatest number is %d.", a):printf("The greatest number is
%d.",b);
return 0;
}
OUTPUT

PROGRAM 2
//Write a program to use macro to initialize the value of Pi and calculate the area and
circumference of circle.

#include <stdio.h>

#define pi 22.0/7
int main(){

float a;

printf("Enter the radius of the circle in meter:");

scanf("%f", &a);

printf("The area and circumference of the circle of radius %f meter is %f square


meter and %f meter respectively.",a,pi*a*a,2*pi*a);

return 0;
}

OUTPUT

PROGRAM 3
/*
Write a program to use the math.h header file and calculate the following:
a) Sine of an angle input by user
b)Power of the number raised to the power another number entered by user
*/

#include<stdio.h>

#include <math.h>

int main(){
float a;

printf("Enter the angle in radians whose sine need to be calculated:");

scanf("%f", &a);

printf("sin(%f}=%f_\n", a, sin(a));

int b, c;

printf("Enter the base number:");

scanf("%d",&b);

printf("Enter the exponent number:");

scanf("%d", &c);

printf("The calculate answer is %f.",pow(b, c));

return 0;
}
OUTPUT
PROGRAM 4
//Write a program to illustrate the use of increment and decrement operators

#include<stdio.h>

int main(){

int a=5,b=2,c=-1,d=5;

printf("%d \n", a++ + ++a + a);

printf("%d \n",++d + d++ + d);

printf("%d \n", b-- + --b + b);

printf("%d \n", --c + c++ +c);

printf("%d \n",1 || c++);

printf("%d \n", c);

printf("%d \n", 0 || c++);

printf("d \n", c);

printf("%d \n", 1 && ++a);

printf("%d \n", a);

printf("%d \n", 0 && b++);


printf("%d\n",b);

return 0;
}
OUTPUT

You might also like