0% found this document useful (0 votes)
14 views10 pages

5 Experiments

The document contains a series of C programming exercises, including programs to print messages, perform arithmetic operations, and calculate geometric properties. It also provides instructions for executing C programs using software like Turbo C++. Additionally, the document covers concepts related to keywords, identifiers, constants, variables, and operators in C programming.

Uploaded by

geriwe2004
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)
14 views10 pages

5 Experiments

The document contains a series of C programming exercises, including programs to print messages, perform arithmetic operations, and calculate geometric properties. It also provides instructions for executing C programs using software like Turbo C++. Additionally, the document covers concepts related to keywords, identifiers, constants, variables, and operators in C programming.

Uploaded by

geriwe2004
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/ 10

Experiment 1

Exercise on structure of C program

Program 1: write a C program to print Hello World?

#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()

int dividend, divisor, quotient, remainder;

printf("Enter dividend: ");

scanf("%d", &dividend);

printf("Enter divisor: ");

scanf("%d", &divisor);

quotient=dividend/divisor;

remainder=dividend % divisor;

printf("Quotient = %d\n", quotient);

printf("Remainder = %d", remainder);

return 0;

Output: Enter dividend: 60

Enter divisor: 11

Quotient = 5

Remainder = 5
Experiment 2

Exercise on Keywords and identifiers

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.

Type the required program in the workspace.


Step 3:
After completion of the program, it has to be saved. It is done by pressing SAVE from
the FILE menu or else by simply pressing F2 function key on the keyboard.
Step 5:
Before execution of program, it has to be compiled first so that whatever the program is
written is converted to the computer language.
In this process called compiling, we also come to know about the errors in the program.
those errors are rectified.
To compile a program, COMPILE, from the menu bar is clicked or simply by pressing
Alt+F9 on the keyboard.
A small new window is obtained displaying the errors in the program. Rectify them.
Step 5:
After compilation, the program must be executed and for that click on RUN button on the
menu bar or by simply typing Ctrl+F9 on the keyboard.
A new screen with black background is opened and the program is being executed.
Experiment 5
Exercise on operators and expressions
Program 9: Write a C program to perform all arithmetic operators by given
numbers.
#include <stdio.h>
int main()
{
int a,b, add,sub,mul,div,mod;
printf("Enter a and b values: ");
scanf("%d%d", &a, &b);
add = a+b;
sub = a-b;
mul = a*b;
div = a/b;
mod = a%b;
printf("Addition of a, b is : %d\n", add);
printf("Subtraction of a, b is : %d\n", sub);
printf("Multiplication of a, b is : %d\n", mul);
printf("Division of a, b is : %d\n", div);
printf("Modulus of a, b is : %d\n", mod);
}
Output:
Enter a and b values: 40 20
Addition of a, b is : 60
Subtraction of a, b is : 20
Multiplication of a, b is : 800
Division of a, b is : 2
Modulus of a, b is : 0
Program 10: write a C program by perform relational operator.
#include <stdio.h>
int main()
{
int m=40,n=20;
if (m == n)
{
printf("m and n are equal");
}
else
{
printf("m and n are not equal");
}
}
Output: m and n are not equal
Program 11: write a C program by using Logical Operators
#include <stdio.h>
int main()
{
int m=40,n=20;
int o=20,p=30;
if (m>n && m !=0)
{
printf("&& Operator : Both conditions are true\n");
}
if (o>p || p!=20)
{
printf("|| Operator : Only one condition is true\n");
}
if (!(m>n && m !=0))
{
printf("! Operator : Both conditions are true\n");
}
else
{
printf("! Operator : Both conditions are true. " \
"But, status is inverted as false\n");
}
}
Output:
&& Operator : Both conditions are true
|| Operator : Only one condition is true
! Operator : Both conditions are true. But, status is inverted as false
Program 12: Write a C Program to find the biggest of three given numbers
#include <stdio.h>
void main()
{
int a, b, c;
printf("Enter the values of a, b and c: ");
scanf("%d%d%d", &a, &b, &c);
printf("a=%d\t b=%d\t c=%d\n", a, b, c);
if(a>b)

You might also like