M3-R4: January 2015 (O-Level)
Q. 5(a):
A lucas sequence is given below:
1, 3, 4, 7, 11, 18, 29
The third number is sum of previous two numbers. Write a program to print first 10 numbers of lucas sequence.
Ans:
To print first 10 numbers of the given lucas sequence:
#include <stdio.h>
#include <conio.h>
void main(){
int first=1, second=3, third, i;
printf("\nNumber 1: %d", first);
printf("\nNumber 2: %d", second);
for(i=3; i<=10; i++){
third = first + second;
printf("\nNumber %d: %d", i, third);
first = second;
second = third;
}
getch();
}
Q. 5(a):
A lucas sequence is given below:
1, 3, 4, 7, 11, 18, 29
The third number is sum of previous two numbers. Write a program to print first 10 numbers of lucas sequence.
Ans:
To print first 10 numbers of the given lucas sequence:
#include <stdio.h>
#include <conio.h>
void main(){
int first=1, second=3, third, i;
printf("\nNumber 1: %d", first);
printf("\nNumber 2: %d", second);
for(i=3; i<=10; i++){
third = first + second;
printf("\nNumber %d: %d", i, third);
first = second;
second = third;
}
getch();
}
No comments:
Post a Comment