Finding the day of 1 Jan of any year from 2001 : C Program

According to Gregorian Calender, it was Monday on the date 01/01/2001. If any year is input through the keyboard write a program to find out what is the day on 1st January of this year.


There are also many other ways do to it but now I am sharing the first one that I find, I will share you another algo’s for it in upcoming posts.

Solution : C Program


#include <stdio.h>

int main()
{
    int year, days, leap_year, year_diff, day;
   
    printf(“Enter year:”);
    scanf(“%d”, &year);
   
    year_diff = (year – 2001);
    leap_year = (year_diff/4);
   
    day = (2 + year_diff + leap_year);
    day = (day % 7);
   
    if (day == 1)
       printf(“It will be Sunday on 1 Jan of %d”, year);
    
    else if (day == 2)
       printf(“It will be Monday on 1 Jan of %d”, year);
      
    else if (day == 3)
       printf(“It will be Tuesday on 1 Jan of %d”, year);
     
    else if (day == 4)
       printf(“It will be Wednesday on 1 Jan of %d”, year);
      
    else if (day == 5)
       printf(“It will be Thursday on 1 Jan of %d”, year);
      
    else if (day == 6)
       printf(“It will be Friday on 1 Jan of %d”, year);
      
    else if (day == 7)
       printf(“It will be Saturday of 1 Jan of %d”, year);
     
    else
       printf(“I think there is some error. Please try again!”);
      
      
    return 0;
   
}

Calculation of finding distance between two place in nautical miles : C Program

Write a program to receive values of latitude(L1, L2) and longitude(G1, G2), in degrees, of two places on the earth and output the distance (D) between them in nautical miles. The formula for distance in nautical miles is:

D = 3963 cos^-1( sin L1 sin L1 + cos L1 cos L1 * cos( G2- G1))


C Program : Solution


#include <stdio.h>
#include <math.h>
int main()
{
    float L1,L2,G1,G2,distance,a;
    const float PI = 3.14;
   
    printf(“Enter the Latitude and Longitude of first place(L1,G1):”);
    scanf(“%f%f”,&L1,&G1);
   
    printf(“Enter the Latitude and Longitude of second place(L2,G2):”);
    scanf(“%f%f”,&L2,&G2);
   
    /* Conversion from degree to radians */
    L1 = L1 * (PI/180);
    L2 = L2 * (PI/180);
    G1 = G1 * (PI/180);
    G2 = G2 * (PI/180);
   
    a = (sin(L1)*sin(L2)+cos(L1)*cos(L2)*cos(G1-G2));
   
    distance = (3963 * acos(a));
   
    printf(“The distance between the places is:%f”,distance);
   
    return 0;
   
}

If you have any suggestions, kindly share with me.

Program to Check Wind Chill Factor : C Program

Wind Chill Factor is the felt air temperature on exposed skin due to wind. The wind chill temperature is always lower than the air temperature, and is calculated as per the following formula:

wcf = 35.74 + 0.6215t + (0.4275-35.75)*v^0.16

where t is the temperature and v is the wind velocity . Write a program to receive value of t and v and calculate wind chill factor(wcf).


C Program : Solution


#include <stdio.h>

int main()
{
    float temp,velocity,wcf;
   
    printf(“Enter the temperature(C) and velocity(m/s) of wind:”);
    scanf(“%f%f”,&temp,&velocity);
   
    wcf = 35.74 + 0.6215*temp+(0.4275*temp-35.75)*pow(velocity,0.16);
   
    printf(“The wind chill factor is:%0.2f”,wcf);
   
    return 0;
   
}

Finding Sum of the digits a 5-digit number entered by user

We are going to find the solution of the given problem in C language syntax :-

In this solution we will use Modulus Operator(%) which returns the remainder after dividing the number.


Algorithm of the Solution

1. Ask for the user to input the 5-digit number.

2. Declare variables for the number , all its digits and sum.

3. Stepwise division of all the digits using Modulus Operator and save it in the variables.

4. Save sum in a variable of all the digits.

5. Display Sum of all the digits


/* Sum of the digits of 5-digit number */

#include <stdio.h>
int main()
{
     int number , a1, a2, a3, a4, a5 , sum;
   
     printf(“Enter the 5-digit number:”);
     scanf(“%d”, &number);
    
      a1 = number %10;
      number = number /10;

a2 = number %10;
      number = number /10;

      a3 = number %10;
      number = number /10;

      a4 = number %10;
      number = number /10;

       a5 = number %10;
      number = number /10;

      sum = a1+a2+a3+a4+a5;

       printf(“Sum of the digits of 5-digit number:%d” , sum);
       
       return 0;

}
    
     


    

Design a site like this with WordPress.com
Get started