Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> सी प्रोग्रामिंग

C प्रोग्राम: वर्तमान तारीख और जन्म तारीख से उम्र की गणना करें

वर्तमान तारीख और जन्म तारीख दी गई है, कार्य व्यक्ति की वर्तमान उम्र निकालना है।

उदाहरण

इनपुट: वर्तमान तारीख = 21/9/2019, जन्म तारीख = 25/9/1996
आउटपुट: Present Age Years: 22 Months: 11 Days: 26

दृष्टिकोण

  • वर्तमान और जन्म तारीख इनपुट लें।
  • यदि वर्तमान महीना जन्म महीने से कम है, तो वर्तमान वर्ष पूरा नहीं हुआ मानकर 12 जोड़ें और वर्ष घटाएं।
  • यदि वर्तमान दिन जन्म दिन से कम है, तो उस महीने के दिनों की संख्या जोड़ें और महीना घटाएं।
  • अंत में दिन, महीना, वर्ष घटाकर उम्र निकालें।

एल्गोरिदम

START
फंक्शन age(present_date, present_month, present_year, birth_date, birth_month, birth_year)
  month[] = {31,28,31,30,31,30,31,31,30,31,30,31}
  यदि birth_date > present_date तो
    present_date += month[birth_month - 1]
    present_month--
  यदि birth_month > present_month तो
    present_year--
    present_month += 12
  final_date = present_date - birth_date
  final_month = present_month - birth_month
  final_year = present_year - birth_year
  प्रिंट करें
मुख्य फंक्शन
  तारीखें सेट करें
  age() कॉल करें
STOP

C कोड उदाहरण

#include <stdio.h>
#include <stdlib.h>

void age(int present_date, int present_month, int present_year,
         int birth_date, int birth_month, int birth_year) {
    int month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
    if(birth_date > present_date) {
        present_date += month[birth_month - 1];
        present_month--;
    }
    if(birth_month > present_month) {
        present_year--;
        present_month += 12;
    }
    int final_date = present_date - birth_date;
    int final_month = present_month - birth_month;
    int final_year = present_year - birth_year;
    printf("Present Age Years: %d Months: %d Days: %d", final_year, final_month, final_date);
}

int main() {
    int present_date = 21, present_month = 9, present_year = 2019;
    int birth_date = 25, birth_month = 9, birth_year = 1996;
    age(present_date, present_month, present_year, birth_date, birth_month, birth_year);
    return 0;
}

आउटपुट

Present Age Years: 22 Months: 11 Days: 26
  1. C प्रोग्राम: मैट्रिक्स घटाव C प्रोग्राम: मैट्रिक्स घटाव

    मैट्रिक्स घटाव दो मैट्रिक्स MAT1 और MAT2 को घटाने के लिए, दोनों का आकार समान होना चाहिए (समान पंक्तियां और स्तंभ)। परिणाम[i][j] = MAT1[i][j] - MAT2[i][j] उदाहरण MAT1 = [1 2 3] MAT2 = [9 8 7] परिणाम = [-8 -6 -4] [4 5 6] [6 5 4] [-2 0 2] [7 8 9] [3 2

  1. C प्रोग्राम: आर्मस्ट्रांग नंबर्स (Armstrong Numbers) C प्रोग्राम: आर्मस्ट्रांग नंबर्स (Armstrong Numbers)

    हमें उपयोगकर्ता द्वारा दर्ज संख्या n की जांच करनी है कि यह आर्मस्ट्रांग संख्या है या नहीं। एक आर्मस्ट्रांग संख्या वह है जिसके अंकों को अंकों की संख्या (क्रम) की घात तक बढ़ाकर उनका योग करने पर मूल संख्या प्राप्त होती है। सूत्र: wxyz... = wⁿ + xⁿ + yⁿ + zⁿ + ... एल्गोरिदम START फंक्शन power(a, b): a^b

  1. C प्रोग्राम: डेकागन (Decagon) का परिमाप C प्रोग्राम: डेकागन (Decagon) का परिमाप

    डेकागन क्या है? भुजा दी गई है, कार्य डेकागन का परिमाप निकालना है। डेकागन एक प्रकार का बहुभुज है जिसमें 10 भुजाएं होती हैं, इसलिए इसे 10-गॉन बहुभुज भी कहा जाता है। इसमें 10 शीर्ष और किनारे होते हैं। एक नियमित डेकागन की भुजाएं समान लंबाई की होती हैं और प्रत्येक आंतरिक कोण 144° होता है। परिमाप का सूत्र