Please do not use iostream C not C++ So i have to make 3 different programs usin
ID: 3675561 • Letter: P
Question
Please do not use iostream
C not C++
So i have to make 3 different programs using c (not c++) using stdio.h, stdlib.h, and also time.h:
Thank you guys so much
Write a program using function(use return in each function and the variable be used as parameters):
---To round the floating point number to 3 digits.eg if input is 3456.7856 output should be 3456.786
Write a program to show whether the year is a leap year or not .If it is then add the digits of the year and write the sum
Format of output should be:
Enter the Year 2016
2016 is a leap year and sum of digits is 9
Write a program
If a>b then swap two numbers
If a
If two numbers are equal then add the numbers
The output should be displayed this way
5>3 a=3 b=5
3<5 c=b-a c=2
5==5 c=b+a c=10
Explanation / Answer
Please find the required codes below :
1)
#include <stdio.h>
#include <stdlib.h>
float getNumber(){
float input;
printf("Enter a floating point number: ");
scanf("%f",&input);
return input;
}
int main()
{
float input = getNumber();
printf("converted value is %0.3f ",input);
return 0;
}
2)
#include <stdio.h>
int isLeapYear(int year){
int ret = 0;
if(year%4 == 0)
{
if( year%100 == 0) /* Checking for a century year */
{
if ( year%400 == 0)
ret=1;
}
else
ret=1;
}
return ret;
}
int main(){
int year, t, sum = 0, remainder;
printf("Enter a year: ");
scanf("%d",&year);
int isLeap = isLeapYear(year);
if(isLeap==1){
t = year;
while (t != 0)
{
remainder = t % 10;
sum = sum + remainder;
t = t / 10;
}
printf("%d is a leap year and sum of digits is %d ", year, sum);
}
return 0;
}
3)
#include <stdio.h>
int getResult(int a,int b){
int c = 0;
if(a<b){
c = b-a;
}
if(a==b){
c = b+a;
}
return c;
}
int main(){
int a,b;
printf("Enter two numbers a and b: ");
scanf("%d",&a);
scanf("%d",&b);
if(a>b){
int t = a, d=b;
a = b;
b = t;
printf("%d > %d a=%d b=%d ",t,d,a,b);
}else{
int c = getResult(a,b);
if(a<b){
printf("%d<%d c=b-a c=%d ",b,a,c);
}else if(b==a){
printf("%d==%d c=b+a c=%d ",b,a,c);
}
}
return 0;
}