Question:5
Write a C program to take input for distance in meters convert it into kilometers(km) and meters(m).
Sol:
#include<stdio.h>
int main()
{
int km,m;
printf("Enter total meters ");
scanf("%d",&m);
km=m/1000;
m=m%1000;
printf("km %d m %d",km,m);
return 0;
}
/* Output */ Enter total meters 1500 km 1 m 500 Enter total meters 2500 km 2 m 500
Question:6
Write a C program to take input for distance in cm convert it into m and cm.
Sol:
#include<stdio.h>
int main()
{
int m,cm;
printf("Enter total cm ");
scanf("%d",&cm);
m=cm/100;
cm=cm%100;
printf("m %d cm %d",m,cm);
return 0;
}
/* Output */ Enter total cm 105 m 1 cm 5 Enter total cm 253 m 2 cm 53
Question:7
Write a C program to take input for distance in mm convert it into cm and mm.
Sol:
#include<stdio.h>
int main()
{
int cm,mm;
printf("Enter total mm ");
scanf("%d",&mm);
cm=mm/10;
mm=mm%10;
printf("cm %d mm %d",cm,mm);
return 0;
}
/* Output */ Enter total mm 125 cm 12 mm 5 Enter total mm 35 cm 3 mm 5
Question:8
Write a C program to take input for total days convert in into years, months, weeks, and days.
Sol:
#include<stdio.h>
int main()
{
int y,m,w,d;
printf("Enter total days ");
scanf("%d",&d);
y=d/365;
d=d%365;
m=d/30;
d=d%30;
w=d/7;
d=d%7;
printf("years %d months %d weeks %d days %d",y,m,w,d);
return 0;
}
/* Output */ Enter total days 366 years 1 months 0 weeks 0 days 1 Enter total days 403 years 1 months 1 weeks 1 days 1
Question:9
Write a C program to take input for total seconds convert in into hours, minutes, weeks, and days.
Sol:
#include<stdio.h>
int main()
{
int h,m,s;
printf("Enter total time in seconds ");
scanf("%d",&s);
h=s/3600;
s=s%3600;
m=s/60;
s=s%60;
printf("hours %d mimutes %d seconds %d ",h,m,s);
return 0;
}
/* Output */ Enter total time in seconds 3601 hours 1 minutes 0 seconds 1 Enter total time in seconds 65 hours 0 minutes 1 seconds 5




