Download as pdf or txt
Download as pdf or txt
You are on page 1of 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