الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

بليزززززز ابي مسساعدتكم الله لايهينكم

بدأه جريح الذكريآت في 8 مايو 2011 · 1 رد · 336 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السسسلام عليكم ..

صبــآح و مسسسـآء الخير...

ما جيت لهالمنتدى الا و انا عارف اني ابلقى ضالتي فيه..

بغيت مسساعدتكم ي شباب في هـ البرنامج مو راضي يزبط معي

Write a program that reads the following data from a file “data.txt” and prints the sum of all odd number and even number individually. You must use one function with parameters and the function should return the two values: two sums (see below). The prototype of the function should be

void function_name( input parameters including pointers).

You read each of the value from the datafile in main function and pass this value to the function, then the function will check if the value is odd or even and update the corresponding sum variable.

11

29

12

30

40

89

90

67

50

31

The output will be as follows:

The sum of all odd numbers : 227

The sum of all even numbers : 289

وهـآذي محاولتي فيه بس مو راضي يشتغل البرنامج في الـ C++

>>

#include <stdio.h>

void read_num( int num, int *sum1, int *sum2);

int main(void)

{ int num, i;

int sum1, sum2;

FILE *infile;

infile = fopen("data.txt","r");

/*if (infile==NULL)

{printf("Error openning file\n");

system("pause");

exit (1);}*/

for(i=0; i != NULL ;i++)

fscanf(infile, "%d", &num);

read_num(num, &sum1, &sum2);

printf("The sum of all even numbers : %d\n", sum1);

printf("The sum of all odd numbers : %d\n", sum2);

fclose(infile);

system("pause");

return (0);

}

void read_num( int num, int* sum1, int* sum2){

*sum1=0, *sum2=0;

int i;

for(i=0 ; i != NULL; i++){

if(num/2 == 0)

*sum1 = *sum1 + num;

else

*sum2 = *sum2 + num;

}

}

تكفووون مسسـآعدتكم ي اعضاء المنتدى لاهنتوآآ

#2
جريح الذكريآت كتب:

وهـآذي محاولتي فيه بس مو راضي يشتغل البرنامج في الـ C++

السلام عليكم

البرنامج محاولتك مكتوبة بلغة C وليست ++C

يعني بتبني البرنامج بأوامر وأدوات لغة C

موفق

[وسط]

♥ Countess ♥

57899411.gif

♥

[/وسط]

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…