[My site ]
Main » 2013 » December » 11 » C Programming - exam 2013
3:53 AM
C Programming - exam 2013

حل إمتحان البرمجة


Q 1 :

write a program to add N terms of the following series, and print out the value of y. Use for statement.


Y = 1 + 1/2! + 2/3! + 3/4! + .........


sol :-




#include"stdio.h"


main()

{

   float y, i, fact, n;

   

   printf("Enter N = ");

   scanf("%d", &n);

   

   for(y=1, fact=1, i=2 ;i<=n;){

      fact*=i;

      y+= (i-1)/fact;

      i++;

   }

printf("y = %.2f", y);


getch();

}



Q 2 :

write a program print out the following :


1 + 1 = 2

2 + 1 = 3

3 + 2 = 5

5 + 3 = 8

8 + 5 = 13


sol :-


#include"stdio.h"


main()

{

int x, y, z, i;


for(x=1, y=1, i=1 ;i<=5;){

z = x + y ;

printf("%d + %d = %d", x, y, z);

y=x;

x=z;

i++;

}


getch();

}

Category: C Programming - 1 | Views: 340 | Added by: ahansaary | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Sign Up | Login ]