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(); }
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"
{ int x, y, z, i;
z = x + y ; printf("%d + %d = %d", x, y, z); y=x; x=z; i++; }
} |
|
Total comments: 0 | |