Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following programs using \"C\" language 1.Write a program using functi

ID: 3675570 • Letter: W

Question

Write the following programs using "C" language

1.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

2.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

3.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 out put 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

#include <stdio.h>

main()

{

   float number,number1,n;

//enter and reading number of float type

printf("Enter number ");

   scanf("%f",&number);

value(number);

printf("number1:%f ", &number1);

return 0;

}

float value(float n)

{

number2= roundf(number * 1000) / 1000;

//roundf() function rounds the value

//here we multiply the number to 1000 rounds the number and divide by 1000 to get

//nearest round value up to 3 precisions.

return number2;

}

2)

#include<stdio.h>

int main(){

    int year,r,sum;

print("Enter the year: ");

    scanf("%d",&year);

    if(((year%4==0)&&(year%100!=0))||(year%400==0))

{

         print(" %d is a leap year",year);//print for printing out in same line

//calculating sum digits in year using while loop

while(year){

      r=year%10;

      year=year/10;

      sum=sum+r;

}

print("and Sum of digits is:%d",sum);

}

    else

         print("%d is not a leap year",year);

  

   return 0;

}

3)

#include<stdio.h>

int main(){

    int a,b,sum,temp,c;

//entering and reading a,b nmbers

printf("Enter number for a");

    scanf("%d",&a);

printf("Enter number for b");

    scanf("%d",&b);

if(a>b)

{

print("%d>%d               ",&a,&b);

    temp = a;

     a = b;

     b = temp;

print("a=%d              b=%d ",&a,&b);

}

elseIf(a<b)

{

c=b-a;

printf("%d<%d               c=b-a              c=%d ",&a,&b,&c);

}

else

{

C=b+a;

printf("%d==%d               c=b+a              c=%d ",&a,&b,&c);

}

return 0;

}//main