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

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

HW 2

Uploaded by

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

HW 2

Uploaded by

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

1.

WAP to convert given second into its equivalent hour, minute


and second as per the following format.
Enter the time:7560 seconds.
7560 second = 2 Hour, 27 Minute and 40 Second

SOURCE CODE:-
#include <stdio.h>

int main(void)
{
int a;
printf("a: ");
scanf("%d", &a);
int hr = a / 3600;
int min = (a%3600) / 60;
int seconds = (a-(hr*3600+min*60));
printf("%d hour %d min %d sec\n", hr, min, seconds);
return 0;
}

Output:-
a: 7560
2 hour 6 min 0 sec
2.WAP to convert a distance in meter entered through
keyboard into its equivalent kilometer and meter as per the
following format.
Enter the distance: 2430 meters.
2430 meters = 2 Km and 430 meters.
Source code:-
#include <stdio.h>

int main(void)
{
int a;
printf("a: ");
scanf("%d",&a);
int km=a/1000;
int m=a%1000;
printf("%d km and %d meters\n",km,m);
}

Output:-

a: 2430
2 km and 430 meters
3.WAP to find the sum of 1st and last of a six-digit
number. Number must be a user input.
Enter the number: 234459
Sum of digits is: 11.

Source code:-
#include <stdio.h>

int main(void)
{
int a;
printf("a: ");
scanf("%d",&a);
if(a<=99999)
{
printf("enter 6 digit no\n");
return 0;
}
int m=a/100000;
int n=a%10;
printf("sum of digits %d\n",m+n);
}

Output:-
a: 234459
sum of digits 11
4.WAP to find the sum of all digits of a three-digit
number. Number must be a user input.
Enter the number: 354
Sum of digits is: 12

Source code:-
#include <stdio.h>

int main(void)
{
int a;
printf("Enter the number: ");
scanf("%d",&a);
int m=a/100;
int b=a%10;
int c=((a%100)-b)/10;
printf("Sum of digits is: %d\n",m+b+c);
}
Output:-

Enter the number: 354


Sum of digits is: 1
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.
INPUT:

Source code:-
#include <stdio.h>

int main(void)
{
int mp,bp,dp;
printf("Enter the buying price: ");
scanf("%d",&bp);
printf("Enter the marker price: ");
scanf("%d",&mp);
printf("Enter the discount: ");
scanf("%d",&dp);

float m=(mp-((float)dp/100)*(float)mp);
float n=m-bp;
if(n>0)
{
printf("Seller made a profit of %f\n",((float)n/bp)*100);
}
if(n<0)
{
printf("Seller made a loss of %f\n",-1*((float)n/bp)*100);
}
}
Output;-
Enter the buying price: 80
Enter the marker price: 100
Enter the discount: 25
Seller made a loss of 6.250000

You might also like