5 Experiments
5 Experiments
#include <stdio.h>
int main()
{
printf("Hello World");
return 0;
}
Output: Hello World
Program 2: Write a C program to print the given integer number?
#include<stdio.h>
int main()
{
int number;
return 0;
}
Output: enter an integer: 96
you entered integer is: 96
Program 3: Write a C program to add two integers?
#include<stdio.h>
int main()
{
int firstNumber, secondNumber, sumOfTwoNumbers;
printf("Enter two integers: ");
scanf("%d%d", &firstNumber, &secondNumber);
sumOfTwoNumbers = firstNumber+secondNumber;
printf("%d + %d = %d", firstNumber, secondNumber, sumOfTwoNumbers);
return 0;
}
Output: Enter two integers: 45
69
45 + 69 = 114
Program 4: Write a C program to find quotient, reminder from the given dividend and
divisor?
#include<stdio.h>
int main()
scanf("%d", ÷nd);
scanf("%d", &divisor);
quotient=dividend/divisor;
remainder=dividend % divisor;
return 0;
Enter divisor: 11
Quotient = 5
Remainder = 5
Experiment 2
Program 5: Write a C program to calculate the area of a triangle given three sides.
#include<stdio.h>
#include<math.h>
main()
{
float a, b, c, s, area;
printf("Enter the three sides of the triangle: ");
scanf("%f%f%f",&a, &b, &c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of the triangle is %f \n", area);
}
Output: Enter the three sides of the triangle: 4 5 6
Area of the triangle is 9.921567
Program 6: Write a C program to display prime numbers between two intervals?
#include<stdio.h>
int main()
{
int low, high, i, flag;
printf("Enter two numbers(intervals): ");
scanf("%d%d", &low, &high);
printf("Prime numbers between %d and %d are: ", low, high);
while(low<high)
{
flag=0;
for(i=2; i<=low/2; ++i)
{
if(low%i==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("%d", low);
++low;
}
return 0;
}
Output: Enter two numbers(intervals): 1
20
Prime numbers between 1 and 20 are: 1235711131719
Exercise 3
Exercise on constants and variables
Program 7: Write a C program to print constant and variable value given by user
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
const int x = 10 ;
scanf("%d", &i);
//x = 100 ; // creates an error
printf("i = %d\nx = %d", i, x ) ;
}
Output: Enter i variable value: 8
i=8
x = 10
Program 8: Write a C program to find the circumference and area of a circle, from its
radius.
#include<stdio.h>
#define PI 3.14159
main()
{
float r, area, circle;
printf("Enter radius:");
scanf("%f", &r);
area=PI*r*r;
circle=2*PI*r;
printf("Area is %f \n Circumference is %f", area, circle);
}
Output: Enter radius:3
Area is 28.274309
Circumference is 18.849541
Exercise 4
Execution of simple C program
Aim: Executing a C program
Theory
To execute a C program, software is required and there are several software available in
the market like TURBO C++, DEV C, etc. now a days we execute any programming languages
by using online browser or any app in smartphone.
Step 1:
Open the Turbo C++ from the windows.
If it is not available, you can easily download and install from the net.
An empty window is opened as shown in the figure.
Step 2:
To create a new file/program, click on file and select NEW so that a new workspace with
blue background is appeared.