0% found this document useful (0 votes)
18 views11 pages

21bee069 Lab2

The document contains code snippets written in C programming language for various problems involving arithmetic operations, temperature conversion, distance calculation, payroll calculation, separating currency denominations, and finding the greatest of three numbers. The problems cover concepts like data types, input/output functions, arithmetic operators, conditional statements, functions and more.

Uploaded by

PRAJAPATI KIRTAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views11 pages

21bee069 Lab2

The document contains code snippets written in C programming language for various problems involving arithmetic operations, temperature conversion, distance calculation, payroll calculation, separating currency denominations, and finding the greatest of three numbers. The problems cover concepts like data types, input/output functions, arithmetic operators, conditional statements, functions and more.

Uploaded by

PRAJAPATI KIRTAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 11

Name: kirtan prajapati

Roll no: 21BEE069

Lab-2

(a) To scan two numbers and display result of

different arithmetic

operator.(“+”,”-”,”*”,”/”,”%”)

#include <stdio.h>

int main()

int a,b,c,d,reversed ;

printf("Enter a three digit number to be reversed\n");

scanf("%d" , &a);

b = a%10 ;

a = a/10 ;

c = a%10 ;

d = a/10 ;

reversed = (b*100)+(c*10)+d ;

printf("Reversed Number = %d " , reversed) ;

printf("\n------------------------------");

return 0;

}
--------------------------------------------------------------------------

C. The driver is driving a car from city Ahmedabad to city

Mumbai, in Ahmedabad temperature displays in Celsius while

in Mumbai the temperature displayed in Fahrenheit, a driver

wants to find the difference between the temperatures of two

Cities in Celsius.

#include<stdio.h>

int main( )

float x,y,c,d;

printf("the temprature of ahmedabad in deegre cecious is",x);

scanf("%f",&x);

printf("¥n the temprature of mumbai in deegre fehrenhit is",y);

scanf("%f",&y);

c=0.56*(y-32);

printf("¥n the temperatur in mumbai in deegre cecious is ",c);

d=c-x;

printf("¥n the diference in temperature is %f ",d);


return 0;

E. A boy was punished and asked to cover 5 rounds of the circular

ground. Area of the ground is 32000 sq mtr. Calculate how many

kilometres the boy has covered.

#include <stdio.h>

#include <math.h>

int main()

float area , radius , x , cf ;

printf("Area Of the Ground is: 32000 sq.m");

printf("\n--------------------------------------");

area = 32000 ;

x = area/3.14 ;

radius = sqrt(x);

cf = (2*3.14*radius*5)/1000 ;

printf("\nRadius of The circle is: %f" ,radius);

printf("\nThus,The Distance Covered By The Boy in km Is: %f",cf);


printf("\n----------------------------------------------");

return 0;

-----------------------------------------------------------------------------------------------------

(g) To swap the value of two numbers

(i)Using a temporary variable

#include <stdio.h>

#include <stdlib.h>

Int main()

Int a,b,temp;

Printf(“Enter the value of a : “);

Scanf(“%d”,&a);

Printf(“Enter the value of b : “);

Scanf(“%d”,&b);

Temp = b;

B = a;

A = temp;

Printf(“Value of a = %d¥nValue of b = %d”,a,b);


Return 0;

(ii)Without using temporary variable

#include <stdio.h>

#include <stdlib.h>

Int main()

Int a,b;

Printf(“Enter the value of a :¥n”);

Scanf(“%d”,&a);

Printf(“Enter the value of b :¥n”);

Scanf(“%d”,&b);

A = a+b;

B = a-b;

A = a-b;

Printf(“Value of a = %d¥nValue of b = %d”,a,b);

Return 0;

}
(b) A company has following scheme for payment to their staff.

• Net salary = Gross salary – Deduction

• Gross salary = Basic + DA + HRA + Medical

• Deduction = Insurance + PF

• DA (Dearness allowance) = 50% of Basic

• HRA (House rent allowance) = 10% of Basic

• Medical = 4% of Basic

• PF (Provident Fund) = 5% of Gross

• Insurance = 7% of Gross

#include<stdio.h>

#include<conio.h>

int main()

float basic, da, hra, medical, gross_salary, pf,

insurance, deduction, net_salary;

printf("Enter The Basic of an Employee :¥n");

scanf("%f", &basic);

da=0.5*basic;
printf("¥nThe Dearness Allowance (DA)= %f¥n",da);

hra=0.1*basic;

printf("The House Rent Allowance (HRA)= %f¥n",hra);

medical=0.04*basic;

printf("The Medical= %f¥n", medical);

gross_salary=basic+da+hra+medical;

printf("The Gross Salary=%f¥n", gross_salary);

pf=0.05*gross_salary;

printf("The Provident Fund (PF)=%f¥n", pf);

insurance=0.07*gross_salary;

printf("The Insurance=%f¥n", insurance);

deduction=insurance+pf;

printf("The Deduction=%f¥n¥n", deduction);

net_salary=gross_salary-deduction;

printf("The Net Salary Of The Employee=%f",net_salary);

return 0;

}
------------------------------------------------------------------------------------------------------

(f) Read the price of item in decimal form. For

example, 12.52 and separate rupee and paise from

the given value. For example, 12 rupees and 52

paise.

#include<stdio.h>

#include<stdlib.h>

int main()

float x;

int r,p;

printf("Enter the price : ¥n");

scanf("%f",&x);

r = (int)x;

p = 100*(x-r);

printf("Rupees = %d¥nPaise = %d",r,p);

return 0;

(h) To find greatest of two and three numbers


using the ternary operator.

#include<stdio.h>

int main()

int a,b,c;

printf("enter the value of a");

scanf("%d",&a);

printf("enter the value of b");

scanf("%d",&b);

if(a>b)

{ printf("the value of a is greater than b");

else{printf("the value of a is less than b");}

return 0;

2.

#include <stdio.h>

Int main() {

Greater than both n2 and n3, n1 is the largest

If (n1 >= n2 && n1 >= n3)

Printf(“%.f is the largest number.”, n1);


Double n1, n2, n3;

Printf(“Enter three different numbers: “n”)

Scanf(“%f %f %f”, &n1, &n2, &n3);

// if n1 is

// if n2 is greater than both n1 and n3, n2 is the largest

If (n2 >= n1 && n2 >= n3)

Printf(“%.f is the largest number.”,number)

// if n3 is greater than both n1 and n2, n3 is the largest

If (n3 >= n1 && n3 >= n2)

Printf(“%.f is the largest number.”, n3);

Return 0;

-----------------------------------------------------------------------------------------------------------------------

(d) To calculate simple interest.

#include<stdio.h>

#include<conio.h>

Int main()

Float p, r, t, si;

Printf(“Enter The Principal Amount:¥n “);


Scanf(“%f”, &p);

Printf(“Enter The Rate Of Interest:¥n”);

Scanf(“%f”, &r);

Printf(“Enter The Time In Years:¥n”);

Scanf(“%f”, &t);

Si=(p*r*t)/100;

Printf(“¥nYour Simple Interest(SI) Amount is:%f¥n”, si);

Return 0;

* Thank you *

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy