Pattern 1

/*Take Input (Number Of Terms) From User And Print The Pattern 1 2 4 7 11 16 22 29 ........... */
mail@pastecode.io avatar
unknown
c_cpp
a month ago
371 B
7
Indexable
Never
/*Print The Pattern 1 2 4 7 11 16 22 29 ........... */

#include <stdio.h>

int main()
{

    int input;
    printf("Enter The Number Of Terms \n");
    scanf("%d", &input);

printf("1 ");
    int prev = 1;
    for (int i = 1; i <input; i++)
    {
        int result = i + prev;
        printf("%d ", result);
        prev = result;
        }
        
        return 0;
}
Leave a Comment