solve it with turbo c

Discuss Computer Science and Programming related problems

Moderators:Labib, bristy1588

Hasib
Posts:238
Joined:Fri Dec 10, 2010 11:29 am
Location:খুলনা, বাংলাদেশ
Contact:
Re: solve it with turbo c

Unread post by Hasib » Tue Jan 04, 2011 12:17 pm

Mohaimin wrote:
hasib.mo wrote: Let, u r told to sum out the serius $1+2+3+....+n$ we can easily give an assignment
int s=(n(n+1))/2
but, i wanna do this with for loop like:
int s=0;
for(int i=1;i<=n;i++)
{
s=s+i;
}

i wanna do that one in this way. Please, write down the prgrm fully what u say.:)
Do you mean it should be exactly one loop? No nested loops? That can be a logical constraint.
it may be more than one loop.
mohaimin wrote:
hasib.mo wrote: I am just new to turbo c
Being new in turbo C makes no sense. Are you new in C?
yaeh. I am new in C.
A man is not finished when he's defeated, he's finished when he quits.

User avatar
Moon
Site Admin
Posts:751
Joined:Tue Nov 02, 2010 7:52 pm
Location:Dhaka, Bangladesh
Contact:

Re: solve it with turbo c

Unread post by Moon » Tue Jan 04, 2011 12:20 pm

HandaramTheGreat wrote:
Moon wrote:...অবশ্য সরাসরি exponent লিখা যায় না, সুতরাং একটা nested loop চালাইলেই তো হয়।
exponent এর ব্যাপারে আরো জানতে: http://www.dreamincode.net/forums/topic ... c-program/
:?

Code: Select all

#include<stdio.h>
#include<math.h>

int main()
{
    int i, k, c;
    scanf("%d %d", &i, &k);
    c=pow(i, k);
    printf("%d\n", c);
    return 0;
}
হা হা...আমি আগেই বলছি এই ক্ষেত্রে আমার জ্ঞান অতি সীমিত। তবে আমি ভাবছিলাম যে সে math.h ব্যবহার না করেই এইটা করতে চায়। সেইকারণে এই জবাব দিসিলাম। :)
"Inspiration is needed in geometry, just as much as in poetry." -- Aleksandr Pushkin

Please install LaTeX fonts in your PC for better looking equations,
learn how to write equations, and don't forget to read Forum Guide and Rules.

Hasib
Posts:238
Joined:Fri Dec 10, 2010 11:29 am
Location:খুলনা, বাংলাদেশ
Contact:

Re: solve it with turbo c

Unread post by Hasib » Tue Jan 04, 2011 1:54 pm

hehehehehe. I am not bitten by a mad. Lolllzz


i must use math.h

please write down the full programme plz
A man is not finished when he's defeated, he's finished when he quits.

User avatar
Zzzz
Posts:172
Joined:Tue Dec 07, 2010 6:28 am
Location:22° 48' 0" N / 89° 33' 0" E

Re: solve it with turbo c

Unread post by Zzzz » Tue Jan 04, 2011 2:28 pm

@হাসিব
মুন ভাইয়া $S= \sum_{i=1}^{n} (n-i+1)\cdot i^k$ দিয়ে একটা for loop ই বুঝাইছে। loop টা এরকমঃ

scanf("%d %d",&n,&k);
sum=0;
for(i=1;i<=n;i++)
sum=sum+ (n+i-1) * pow(i,k);
Every logical solution to a problem has its own beauty.
(Important: Please make sure that you have read about the Rules, Posting Permissions and Forum Language)

Hasib
Posts:238
Joined:Fri Dec 10, 2010 11:29 am
Location:খুলনা, বাংলাদেশ
Contact:

Re: solve it with turbo c

Unread post by Hasib » Tue Jan 04, 2011 5:17 pm

please, write the full prgrm plz :cry: :cry:
A man is not finished when he's defeated, he's finished when he quits.

User avatar
Zzzz
Posts:172
Joined:Tue Dec 07, 2010 6:28 am
Location:22° 48' 0" N / 89° 33' 0" E

Re: solve it with turbo c

Unread post by Zzzz » Tue Jan 04, 2011 5:39 pm

#ইঞ্চলুদে<স্তদিও।হ>
#ইঞ্চলুদে<মাথ।হ>

আমি অভ্র চালু করে লেখা শুরু করছিলাম, খেয়াল করি নাই। মনিটরে তাকায়ে বেশ মজা লাগলো। তাই আর কাটলাম না :P

Here is the code:

#include<stdio.h>
#include<math.h>

int main()
{
int i,n,k,sum;
scanf("%d %d",&n,&k);
sum=0;
for(i=1;i<=n;i++)
sum=sum+ (n+i-1) * pow(i,k);
printf("%d",sum);
return 0;
}

ok ?
Every logical solution to a problem has its own beauty.
(Important: Please make sure that you have read about the Rules, Posting Permissions and Forum Language)

Hasib
Posts:238
Joined:Fri Dec 10, 2010 11:29 am
Location:খুলনা, বাংলাদেশ
Contact:

Re: solve it with turbo c

Unread post by Hasib » Tue Jan 04, 2011 8:45 pm

hahahahaha.great fun. Now gonna to mail it to sarfaraz bro :P
A man is not finished when he's defeated, he's finished when he quits.

HandaramTheGreat
Posts:135
Joined:Thu Dec 09, 2010 12:10 pm

Re: solve it with turbo c

Unread post by HandaramTheGreat » Wed Jan 05, 2011 3:19 pm

Zzzz wrote:#ইঞ্চলুদে<স্তদিও।হ>
#ইঞ্চলুদে<মাথ।হ>...
আমি প্রথমে ভাবসিলাম জুবায়ের বুঝি হাসিবকে গালি দেওয়া শুরু করল... :lol:

User avatar
Zzzz
Posts:172
Joined:Tue Dec 07, 2010 6:28 am
Location:22° 48' 0" N / 89° 33' 0" E

Re: solve it with turbo c

Unread post by Zzzz » Wed Jan 05, 2011 5:11 pm

HandaramTheGreat wrote:
Zzzz wrote:#ইঞ্চলুদে<স্তদিও।হ>
#ইঞ্চলুদে<মাথ।হ>...
আমি প্রথমে ভাবসিলাম জুবায়ের বুঝি হাসিবকে গালি দেওয়া শুরু করল... :lol:
:lol:
Every logical solution to a problem has its own beauty.
(Important: Please make sure that you have read about the Rules, Posting Permissions and Forum Language)

Hasib
Posts:238
Joined:Fri Dec 10, 2010 11:29 am
Location:খুলনা, বাংলাদেশ
Contact:

Re: solve it with turbo c

Unread post by Hasib » Wed Jan 05, 2011 7:56 pm

HandaramTheGreat wrote:
Zzzz wrote:#ইঞ্চলুদে<স্তদিও।হ>
#ইঞ্চলুদে<মাথ।হ>...
আমি প্রথমে ভাবসিলাম জুবায়ের বুঝি হাসিবকে গালি দেওয়া শুরু করল... :lol:
hahahahahahahaha
A man is not finished when he's defeated, he's finished when he quits.

Post Reply