So i have to make 3 different programs using c (not c++) using stdio.h, stdlib.h
ID: 3675511 • Letter: S
Question
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<b then subtract two numbers
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
//Program one.
program1:-
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
float val;
printf("enter the float value");
scanf("%f",&val);
printf("near float is %0.3f",val);
return 0;
}
//--------------------Program 2---------------------
program2:-
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
int y,sum=0;
printf("enter the year");
scanf("%d",&y);
if (y%4 == 0) {
if (y%100 == 0) {
if (y%400 == 0) {
printf("%d is a leap year",y);
}
else {
printf("%d is not a leap year",y);
}
}
else {
printf("%d is a leap year",y);
}
}
else {
printf("%d is not a leap year",y);
}
while(y!= 0)
{
sum = sum + y % 10;
y = y / 10;
}
printf("sum of digits is %d",sum);
return 0;
}
//--------------------Program 3---------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
int a,b,temp;
printf("Enter a");
scanf("%d",&a);
printf("Enter b");
scanf("%d",&b);
if(a>b)
{
temp=a;
a=b;
b=temp;
printf("%d > %d a=%d b=%d",a,b,a,b);
}
if(a<b)
{
temp=b-a;
printf("%d < %d c=b-a c=%d",a,b,temp);
}
if(a==b)
{
temp=b+a;
printf("%d == %d c=b+a c=%d",a,b,temp);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.