اذهب إلى المحتوى
  • 0

لغة c++

Jamal Alqarni

السؤال

Recommended Posts

  • 0
بتاريخ 27 دقائق مضت قال Jamal Alqarni:

1- اكتب برنامج لطباعه السلسة التالية

233........1,2,3,5,8,13

هي Fibonacci مكرره 14 مرة، يمكن كتابة البرنامج بعدة طرق منها التالي

#include <iostream>

using namespace std;

int main()
{
    int t1 = 0, t2 = 1, nextTerm = 0, num_terms=14;

    
    cout << "Fibonacci Series: ";

    for (int i = 1; i <= num_terms; ++i)
    {
        // Prints the first two terms.
        if(i == 1)
        {
            cout << " " << t1;
            continue;
        }
        if(i == 2)
        {
            cout << t2 << " ";
            continue;
        }
        nextTerm = t1 + t2;
        t1 = t2;
        t2 = nextTerm;
        
        cout << nextTerm << " ";
    }
    return 0;

}

 

بتاريخ 29 دقائق مضت قال Jamal Alqarni:

2- اكتب برنامج لادخال معلومات Nمن الطلاب حيث معلومات كل طالب هي(اسمة وعمره وتخصصة) 

الفكرة أن في البداية تطلب من المستخدم إدخال عدد الطلاب (نعتبره num) ثم بناء علية تنشئ array of structures ثم تدخل البيانات من خلال loop طولة num التي أدخلها المستخدم والتي هي نفسها طوال ال array of structures

#include <iostream>
using namespace std;

int main()
{
    int num;
    cout << "Enter number of students: ";
        cin >> num;
        
    struct student {
            char name[50];
            int age;
            char spicalization[50];
    } s[num]; 
    
    // storing information
    for(int i = 0; i < num; ++i)
    {
        cout << "For roll number" << i+1 << "," << endl;
        cout << "Enter name: ";
        cin >> s[i].name;
        cout << "Enter age: ";
        cin >> s[i].age;
        cout << "Enter spicalization: ";
        cin >> s[i].spicalization;
        cout << endl;

    }
    cout << "Displaying Information: " << endl;
    // Displaying information
    for(int i = 0; i < 10; ++i)
    {
        cout << "Name: " << s[i].name << endl;
        cout << "age: " << s[i].age << endl;
        cout << "spicalization: " << s[i].spicalization << endl;

    }
    return 0;
}

يوجد حلول أخرى أيضًا لهذا السؤال ممكن أن تترجمه بالإنجليزية وتبحث عنه في Google

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...