Sunday 27 March 2016

Solution of URI 1143 :: Squared and Cubic


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int a,b,c,d,e,f;
    scanf("%d", &a);
    for(b=1; b<=a; b++)
    {
        c=b*b;
        d=b*b*b;
        printf("%d %d %d\n",b,c,d);
    }
    return 0;
}

4 comments:

  1. // sir why did doesn't work
    #include
    #include
    using namespace std;

    int main ()
    {
    int n , k = 1;
    cin >> n;
    for (int i = 1 ; i<=n ; ++i)
    {
    k = 1;
    for(int j = 1 ; j <= 3 ; ++j)
    {
    cout << i*k << " ";
    k*=i;
    }
    cout << endl;
    }
    cout << endl;
    }

    ReplyDelete
    Replies
    1. Because of an extra space count end of the line. I faced the same problem... When i debug it i can fix it...

      Delete
  2. /* Why it is showing Presentation Error */


    #include
    #include

    int main()
    {
    int n,m=1,i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=3;j++)
    {
    m=m*i;
    printf("%d ",m);
    }
    printf("\n");
    m=1;
    }
    return 0;
    }

    ReplyDelete
  3. /* Why dosen't this working ,sir ? */

    #include

    int main()
    {
    int i,j,a,e;
    scanf("%d",&a);
    for(i=1;i<=a;i++)
    {
    for(j=1;j<=3;j++)
    {
    e = pow(i,j);
    printf("%d ",e);
    }
    printf("\n");
    }
    return 0;
    }

    ReplyDelete

Note: only a member of this blog may post a comment.