Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
29 views6 pages

Lab Assignment 2

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)
29 views6 pages

Lab Assignment 2

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/ 6

Name - Tanmay Shrivastava

Course-BTech(CSE)
Roll No.-24155589

Day 4(Lab Assignments)


Question 1)WAP to convert given second into its equivalent hour, minute and
second as per the following format.

#include <stdio.h> INPUT:


int main() Enter the given
{ seconds=7560
int s,m,h;
printf("Enter the given seconds");
scanf("%d",&s);
h=s/3600;
m=s%3600/60; OUTPUT:
s=(s%3600)%60; Hours=2
printf("Hours=%d,Minutes=%d,Seconds=%d",h,m,s); Minutes=27
return 0; Seconds=40
}
Question 2)WAP to convert a distance in meter entered through keyboard into its equivalent kilometer
and meter as per the following format.

#include <stdio.h> INPUT:


int main() Enter the distance in
{
metres: 2430 meters.
int m,k;
printf("Enter the distance in metres");
scanf("%d",&m);
k=m/1000; OUTPUT:
m=m%1000; Kilometres=2
printf("Kilometres=%d,Metres=%d",k,m);
return 0;
Metres=430
}
Question 3)WAP to find the sum of 1st and last of a six-digit number. Number must be a user input.

#include <stdio.h>
int main() INPUT:
{
Enter a six digit
int a,f,l,s;
printf("Enter a six digit number:"); number:234459
scanf("%d",&a);
f=a/100000;
l=a%10;
s=f+l; OUTPUT:
printf("First digit=%d,Last First digit=2
digit=%d,Sum=%d",f,l,s);
Last digit=9
return 0;
} Sum=11
Question 4)WAP to find the sum of all digits of a three-digit number. Number must be a user input.

#include <stdio.h>
int main()
{ INPUT:
int a,f,s,l,t;
Enter the three digit number=354
printf("Enter the three digit number=");
scanf("%d",&a);
f=a/100;
s=a%100/10;
l=a%10;
t=f+s+l;
printf("First digit=%d,Second digit=%d,Third OUTPUT:
digit=%d,Sum=%d",f,s,l,t); First digit=3
return 0; Second digit=5
} Third Digit=4
Sum=12
Question 5)The buying price, the marker price and discount are entered through the keyboard.
Sometimes the seller gets profit or sometimes loss depending upon the discount. WAP to determine
whether the seller has made profit or incurred loss. Also determine how much profit he made or loss
he incurred
#include <stdio.h>
int main() INPUT:
{
int b,m; Enter the buying price=80
int disc;
printf("Enter the buying price \t");
Enter the market price=100
scanf("%d",&b); Enter the discount=25
printf("Enter the market price \t");
scanf("%d",&m);
printf("Enter the discount \t");
scanf("%d",&disc);
float s=m-((m*disc)/100.0);
if(s>b) OUTPUT:
{
float profit=((s-b)/b)*100.0; Seller made a loss of 6.25
printf("Seller made a profit of %f \t",profit);
}
else
{
float loss=((b-s)/b)*100.0;
printf("Seller made a loss of %f \t",loss);
}
return 0;
}

You might also like