Results 1 to 7 of 7

Thread: slove this program...

  1. #1
    dani.awan631's Avatar
    dani.awan631 is offline Senior Member+
    Last Online
    26th April 2016 @ 04:47 PM
    Join Date
    06 Feb 2016
    Age
    27
    Gender
    Male
    Posts
    157
    Threads
    14
    Credits
    20
    Thanked
    2

    Question slove this program...

    creat a sum function using recursion
    sum=10+9+8+7+6+5+4+3+2+1=55..............
    اردو۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔
    ایک جمع کا فنکشن بنائیں جس میں ریکریژن استعمال ہو۔۔

  2. #2
    Join Date
    28 Apr 2015
    Location
    Sindh
    Gender
    Male
    Posts
    386
    Threads
    81
    Credits
    1,802
    Thanked
    38

    Default

    Quote dani.awan631 said: View Post
    creat a sum function using recursion
    sum=10+9+8+7+6+5+4+3+2+1=55..............
    اردو۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔
    ایک جمع کا فنکشن بنائیں جس میں ریکریژن استعمال ہو۔۔
    Bro Visit www.Cprogramming.com

  3. #3
    Join Date
    28 Apr 2015
    Location
    Sindh
    Gender
    Male
    Posts
    386
    Threads
    81
    Credits
    1,802
    Thanked
    38

    Default use this code

    Quote dani.awan631 said: View Post
    creat a sum function using recursion
    sum=10+9+8+7+6+5+4+3+2+1=55..............
    اردو۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔
    ایک جمع کا فنکشن بنائیں جس میں ریکریژن استعمال ہو۔۔
    Try it bro
    Code:
     #include<stdio.h>
    int add(int n);
    int main()
    {
    int n;
    printf("Enter an positive integer: ");
    scanf("%d",&n);
    printf("Sum = %d",add(n));
    return 0;
    }
    int add(int n)
    {
    if(n!=0)
    return n+add(n-1); /* recursive call */
    }

  4. #4
    dani.awan631's Avatar
    dani.awan631 is offline Senior Member+
    Last Online
    26th April 2016 @ 04:47 PM
    Join Date
    06 Feb 2016
    Age
    27
    Gender
    Male
    Posts
    157
    Threads
    14
    Credits
    20
    Thanked
    2

    Default

    sum ni kar rha .... bahi

    - - - Updated - - -

    ma ny tuesday ko is ke assignment submit karani ha

  5. #5
    Z.Programmer is offline Member
    Last Online
    11th October 2016 @ 10:38 AM
    Join Date
    06 Feb 2016
    Gender
    Male
    Posts
    158
    Threads
    13
    Thanked
    5

    Arrow

    Quote dani.awan631 said: View Post
    creat a sum function using recursion
    sum=10+9+8+7+6+5+4+3+2+1=55..............
    اردو۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔۔
    ایک جمع کا فنکشن بنائیں جس میں ریکریژن استعمال ہو۔۔
    This seems your homework, so now for last time I am solving your homework problem but next time solve your homework with your own ability. Yes, I will help you if you are trying to code and stuck at a problem then upload your coding I will try to find errors and then I will tell you that where you are making mistake.

    So this is for last time.

    Here is coding:

    Code:
    #include<iostream>
    using namespace std;
    int n = 0;
    int Sum(int s)
    {
    	int result;
    	if( s == n )
    		return n;
    	else
    	{
    		result = Sum(s+1) + s;
    		return result;
    	}
    
    }
    int main()
    {
    
    	cout<<"Enter a number to which you want sum: ";
    	cin>>n;
    
    	cout<<"The sum of numbers up to "<<n<<" is "<<Sum(1);
    	cin.ignore();
    	cin.get();
    }
    Screen Shot


  6. #6
    dani.awan631's Avatar
    dani.awan631 is offline Senior Member+
    Last Online
    26th April 2016 @ 04:47 PM
    Join Date
    06 Feb 2016
    Age
    27
    Gender
    Male
    Posts
    157
    Threads
    14
    Credits
    20
    Thanked
    2

    Default

    thanks .......
    Thats the real answer

  7. #7
    Rehman shar's Avatar
    Rehman shar is offline Advance Member
    Last Online
    3rd September 2022 @ 06:32 PM
    Join Date
    22 Feb 2012
    Location
    MirPur Khas
    Age
    32
    Gender
    Male
    Posts
    765
    Threads
    68
    Credits
    1,011
    Thanked
    47

Similar Threads

  1. slove this
    By sender in forum Ask an Expert
    Replies: 5
    Last Post: 26th January 2014, 01:40 PM
  2. plz slove itt!!!
    By hafizhingora in forum Ask an Expert
    Replies: 4
    Last Post: 20th April 2013, 05:12 PM
  3. pls slove that problem
    By sizs in forum Ask an Expert
    Replies: 2
    Last Post: 15th May 2010, 10:32 AM
  4. Slove my problem Plz
    By arsal1 in forum Help/Request (PC Games)
    Replies: 4
    Last Post: 3rd January 2010, 03:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •