Basic Programming C Examples

WAP in C to print the total seconds in a given time (hrs, min, sec)

The Program in C that prints the total seconds in a given time (hrs, min, sec) is given below:

#include <stdio.h>

int main() {
    int hours, minutes, seconds, total_seconds;
    printf("Enter the number of hours: ");
    scanf("%d", &hours);
    printf("Enter the number of minutes: ");
    scanf("%d", &minutes);
    printf("Enter the number of seconds: ");
    scanf("%d", &seconds);
    total_seconds = (hours * 3600) + (minutes * 60) + seconds; //calculating total seconds
    printf("The total number of seconds in %d hours, %d minutes, and %d seconds is %d",
           hours, minutes, seconds, total_seconds);
    return 0;
}

Output:

Enter the number of hours: 12
Enter the number of minutes: 12
Enter the number of seconds: 12
The total number of seconds in 12 hours, 12 minutes, and 12 seconds is 43932

Pro-Tips💡

This program takes input of hours, minutes, and seconds and then it calculates the total seconds by multiplying hours by 3600 (the number of seconds in an hour),

minutes with 60 (number of seconds in a minute) and then adding the seconds.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X