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:
solve it with turbo c

Unread post by Hasib » Sun Jan 02, 2011 10:58 pm

$S=1^k+(1^k+2^k)+(1^k+2^k+3^k)+.....(1^k+2^k+3^k+....+n^k)$


u have to take input $n\, and\, k$ from user and ur programme will give the result $S$
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 » Mon Jan 03, 2011 9:36 am

আমি প্রোগ্রামিং পারি না তেমন তবে এইটাকে লিখা যায়, \
এখন এইটা করার জন্য তো কিছুই দরকার হওয়ার কথা না!
"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 » Mon Jan 03, 2011 6:04 pm

hehe. U r not allowed to use theorem. Thats the problem :( we have to do it with for loop.
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 » Mon Jan 03, 2011 8:07 pm

আমি তো এইখানে কোন সূত্র ব্যবহার করি নাই।
কেন তুমি যদি লুপ দিয়ে ১ থেকে $n$ পর্যন্ত যোগফল নির্ণয় করতে পার এইটাতে সমস্যা কি?
$S=S+(n-i+1)\cdot i^k$ ব্যবহার কর তাহলেই তো হয়। অবশ্য সরাসরি exponent লিখা যায় না, সুতরাং একটা nested loop চালাইলেই তো হয়।
exponent এর ব্যাপারে আরো জানতে: http://www.dreamincode.net/forums/topic ... c-program/
"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.

sakib
Posts:20
Joined:Tue Dec 07, 2010 3:33 pm

Re: solve it with turbo c

Unread post by sakib » Tue Jan 04, 2011 1:57 am

আসলে হাসিবের প্রশ্নটাইতো পরিষ্কার না।কোন থিওরেম ব্যবহার করা যাবে না মানেকি??প্রোগ্রামিং সমস্যায় সূত্র ব্যবহার না করা মানে তো অনেকটা কাগজে দাগ দেয়া ছাড়া রচনা লেখার মত।এরকম সমস্যায় তুমি এটা বলতে পার যে সমস্যাটা কত complexity তে সমাধান করতে হবে।complexity কি?? মনে কর একটা প্রোগ্রাম-

for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
operation();
}
}

এই প্রোগ্রামে দেখ কতবার অপারেশন করে?? n*n বা n^2 বার।তার মানে এর complexity n^2 বা O(n^2).কম্পিউটার সাধারণত ১ সেকেন্ডে 10^7 টার মত অপারেশন করতে পারে।তো n এর মান যদি 10000 হয় তাহলে মনে কর এই সমস্যাটা ১ সেকেন্ডে হয়ত সমাধান হবেনা।

তো তুমি একটা সমস্যা দিলে এটা বলতে পার এটা কি complexity তে করতে হবে বা অন্যকিছু।কিন্তু এটা বলা তো অপরাধ যে কোন সূত্র ব্যবহার করা যাবেনা।

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 10:43 am

@Sakib vai:: oh, i am explain what i wanted to say.

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. I am just new to turbo c :)
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 » Tue Jan 04, 2011 11:27 am

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;
}

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:06 pm

HandaramTheGreat wrote: :?

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;
}


is it my solution?
A man is not finished when he's defeated, he's finished when he quits.

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:07 pm

HandaramTheGreat wrote: :?

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;
}


is it my solution?
A man is not finished when he's defeated, he's finished when he quits.

User avatar
Mohaimin
Posts:38
Joined:Thu Dec 09, 2010 7:38 pm
Location:Dhaka
Contact:

Re: solve it with turbo c

Unread post by Mohaimin » Tue Jan 04, 2011 12:10 pm

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.
hasib.mo wrote: I am just new to turbo c
Being new in turbo C makes no sense. Are you new in C?

Post Reply