Search
 
SCRIPT & CODE EXAMPLE
 

C

recursive in c

#include <stdio.h>
int sum(int n);

int main() {
    int number, result;

    printf("Enter a positive integer: ");
    scanf("%d", &number);

    result = sum(number);

    printf("sum = %d", result);
    return 0;
}

int sum(int n) {
    if (n != 0)
        // sum() function calls itself
        return n + sum(n-1); 
    else
        return n;
}
Comment

PREVIOUS NEXT
Code Example
C :: print an int c 
C :: pid of a process in c 
C :: #define f_cpu 
C :: sockaddr_in c 
C :: best approach c menu terminal 
C :: iterate through enum in qt 
C :: binary tree count number of leaves in c 
C :: adding a node in the front on a linked list 
C :: c check if character is upper case 
C :: refresh a chromebook terminal 
C :: Write a C program to multiply two integers using pointers. 
C :: time include c 
C :: c comment 
C :: c check if character is lower case 
C :: Increment & Decrement Operator in C language 
C :: how to input a string into a char array cpp 
C :: insse suprafata arabila pe ani 
C :: gcc compiler for windows 10 
C :: C/c drop mime 
C :: run steam as root 
C :: error: argument 1 range [18446744071562067968, 18446744073709551615] exceeds maximum object size 9223372036854775807 [-werror=alloc-size-larger-than=] 
C :: C access global variable same name 
C :: Parsing using strtok 
C :: c program to take array input from user 
C :: brew autoremove 
C :: cut first part of string c 
C :: bash sed crop cut file line number 
C :: c multithreading sum from 0 to 1000 
C :: exponent calculator 
C :: sdl_rect 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =