12‏/12‏/2017

كتب برنامج لإيجاد الجذور الحقيقية

كتب برنامج لإيجاد الجذور الحقيقية لمعادلة من الدرجة الثانية بمعلومية 
ax2 + bx +c = 0
وباستخدام الصيغة
** البرنامج **
كود:
# include <stdio.h>
# include < math.h>
/* real roots of a quadratic equation */
main( )
{
float a,b,c,d,x1,x2;
/* read input data */
printf(“a= “ );
scanf(“%f”,&a);
printf(“b= “ );
scanf(“%f”,&b);
printf(“c= “ );
scanf(“%f”,&c);
/* carry out the calculations */
d=sqrt(b*b – 4*a*c);
x1=(-b+d)/(2*a);
x2=(-b-d)/(2*a);
/* write output */
printf(“x1= “,%e      x2=%e “,x1,x2);
}
ملاحظة : %e : تستخدم للعد الحقيقى بالصور الأسية
3- اكتب برنامج لتقويم كثيرة الحدود
كود:
# include<stdio.h>
# include<math.h>
main( )
{
float u,x,y;
/* read input data */
printf (“ x = “ );
scanf(“ %f “,&x );
/* carry out the calculations */
u= (x –1)/x;
y=u+pow(u,2.)/2+pow(u,3.)/3+poe(u,4.)/4+pow(u,5.)/5;
printf(“x= “,%f        y =”%f “, x,y );
}
4- برنامج لإدخال كلمة سر
كود:
# include<stdio.h>
# include<conio.h>
main( )
{
char pass[10];
do
{
 printf(“\n enter password: “ );
 scanf(“%s”,pass);
          }
while(strcmp(pass,”dahe”)!=0);
}

ملاحظات:
· هنا كلمة السر سوف تظهر أثناء الكتابة
· الدالة strcmp( ) : تقوم بمقارنه متغيرين من نوع عبارة حرفية string فإذا كان المتغيرين متطابقين كان الفرق بينهما صفر

تعديل لبرنامج كلمة السر 
عدم ظهور كلمة السر التى يكتبها المستخدم على الشاشة )
كود:
# include<stdio.h>
# include<conio.h>
main( )
{
chat ch;
char pass[10];
do
{
textcolor(WHITE);
textbackground(BLUE);
cprintf(“\n enter password: “ );
textbackgrounf(WHITE);
cscanf(“%s”,pass);
          }
while(strcmp(pass,”dahe”)!=0);
}
 اكتب برنامج
لطباعة عبارة حرفية تم ادخالها مع بيان عدد حروفها وعدد الكلمات
كود:
/* count characters and word in a phrase عبارة typed in */
# include <stdio.h>
main( )
{
int charcnt=0;
int wordcnt=0;
char ch;
printf(“ type in a phrase : \n “);
/* read characters and quit loop on [ return ] */
while((ch=getche())!=’\r’);
{
charcnt ++   /* count character */
if(ch==’ ‘ );   /* space ? */
wordcnt++;
}
printf(“\n character count is %d “,charcnt );
printf(“\n word count is %d “ , wordcnt );
}






مصدر