Programming In C Practical 3

Question 1
Write a program to print square of given number.
square.cpp
C
				#include<stdio.h>
#include<conio.h>

void main()
{
	clrscr();
	int num,sq;
	printf("\nEnter a number : ");
	scanf("%d",&num);
	sq=num*num;
	printf("\nSquare of number is: %d",sq);
	getch();
}
			
Output
Question 2
Celsius to Fahrenheit conversion.
numbers.cpp
C
				#include<stdio.h>
#include<conio.h>

void main()
{
	clrscr();
	int celsius;
	float far;
	printf("\nEnter a temperature in celsius : ");
	scanf("%d",&celsius);
	far=celsius*(9f/5)+32;
	printf("\nTemperature in Fahrenheit is: %f",far);
	getch();
}
			
Output
Question 3
Area calculation of circle with PI value constant and #define function.
numbers.cpp
C
				#include<stdio.h>
#include<conio.h>

#define Pi 3.14

void main()
{
	clrscr();
	int r;
	float carea;
	printf("\nEnter radius of circle: ");
	scanf("%d",&r);
	carea=Pi*r*r;
	printf("\nArea of circle: %f",carea);
	getch();
}
			
Output

Leave a Comment

Your email address will not be published. Required fields are marked *