CrazyEngineers Anniversary Celebrations

The CrazyEngineers Anniversary Celebration Week concludes on November 28th. Do not miss out on a chance to participate in the ongoing contests and win grand prizes!


Creative Writing (Live) | Deadline: 10:00 PM (IST) [Update: Over]


Engineering Life Photo Contest (Live) | Deadline: 11:00 PM (IST) Today


Mega Contest: Engineering For Change In India, Project Report Contest (Live) | Deadline: 11:59 AM (IST), Tomorrow


Beginners Tutorial : The C-language.

Discussion in 'Computer Science | IT | Networking' started by simplycoder, Aug 19, 2011.

  1. SamiZzY

    SamiZzY Apprentice

    Engineering Discipline:
    Electronics & Telecommunications
    i replaced the l.h.s index with original index int the last line(is that what you meant?:confused: ) , and the output was 24 and 81. pretty strange because index changes from 100 to 999 but thankyou for the reply mr.jeffrey :)
     
    #61
  2. Jeffrey Samuel

    Engineering Discipline:
    Electronics
    Code:
    for(index2=1;index2<=3;index2++)
    {
    digit=index%10;// Replace this index
    final_ans=final_ans+pow(digit,3);
    index=index/10;// and also here both the index has to be varied
    }
    Cos your program is having a logical error since you are manipulating the the control variable of the outer loop in the inner most loops So you are getting an error here
     
    • Like Like x 1
    #62
  3. SamiZzY

    SamiZzY Apprentice

    Engineering Discipline:
    Electronics & Telecommunications
    thankyou sir.! noting what you said , replaced all the var index with original index in the 2nd loop
    and at the bottom if condition replaced original index with var index and by god's grace it worked .!
    thankyou again.
     
    #63
  4. Jeffrey Samuel

    Engineering Discipline:
    Electronics
    It is my pleasure to help you Pls avoid Siring me I ama student just like you

    We are all are here to help you and learn from you
     
    • Like Like x 1
    #64
  5. Ashish Saklani

    Ashish Saklani Certified CEan

    Engineering Discipline:
    Computer Science
    thank u simplycoder this tutorials will help me in programming.
     
    #65
  6. simplycoder

    Engineering Discipline:
    Electronics & Communications
    Its glad to hear.
     
    #66
  7. lit-857

    lit-857 Apprentice

    Engineering Discipline:
    IT
    sir u should give the ans of exersies
     
    #67
  8. simplycoder

    Engineering Discipline:
    Electronics & Communications
    The best part about programming is that you know the correct answer.
    If you follow the tutorial throughout then I think you wouldn't find it difficult(challenging has a different meaning.)

    Still if you don't get the output, show your work and then we can debug it or see where it goes wrong.

    Tip:The best way to solve is to execute it by hand for small input.
     
    #68
  9. lit-857

    lit-857 Apprentice

    Engineering Discipline:
    IT
    what d/f b/w float and double datatype
     
    #69
  10. Jeffrey Samuel

    Engineering Discipline:
    Electronics
    float datatype allows only 4 bytes of memory Whereas the double type allows 8 bytes

    Only the range of these two differs not their other types
     
    #70
  11. lit-857

    lit-857 Apprentice

    Engineering Discipline:
    IT
    i know very well but i want to get understend with exmple
     
    #71
  12. Ganesh MSD

    Ganesh MSD Apprentice

    Engineering Discipline:
    Computer Science
    Nice article...!! This is simply awesome. So useful.
     
    #72
  13. Neeraj Sharma

    Engineering Discipline:
    Computer Science
    As already stated before, the main difference lies in the range. Float is single precision and double is double precision floating number. It is called double precision as it is twice of a normal float variable.

    As per your request here is an example:

    Suppose ABC person is very rich and has a huge amount of money (so much that it cant be represented in a single precision number). If you want to store that amount of money in a float variable, then it will truncate the double precision number to single precision which in turn will reduce the amount of money that the person holds. Isn't it a problem? Yes it is. That is the main reason for existence of double precision data types i.e. to store huge values.

    The example that I gave is quite vague but I think it will help you in understanding the difference clearly..
     
    • Like Like x 2
    #73
  14. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science
    try coding this!!! A good question!

    Write a C program to Remove even numbers and fill it with zeros.
    Note: You can use only one loop for your logic.
    Two variables apart from the array.
    Input array 1,2,3,4,5,6
    Output 1,3,5,0,0,0
     
    #74
  15. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science

    no one is answering to this?
     
    #75
  16. Nayan Goenka

    Engineering Discipline:
    IT

    I didnt read this. I will post my code soon enough. Give me some time to code. By the way, you want the complete code or just function?
     
    #76
  17. Nayan Goenka

    Engineering Discipline:
    IT
    Here is my code. :D Its quite tricky to get the output as you wanted. Odds first then 0's :p Anyways it was good exercise with C++ for me.

    Code:
    #include<iostream.h>
    #include<conio.h>
    void main()
      {
        clrscr();
        int input[6],output[6],i,j=0;
        cout<<"\n Enter the Inputs :";
     
     
        while (j>=0)
          {
        for(i=0;i<6;i++)
          {
            cin>>input[i];
            if( input[i] % 2 != 0)
              {
            output[j] = input[i];
            j++;                                                              }
          }
        break;
        }
     
     
        for(j;j<6;j++)
          {
        output[j]=0;
          }
     
        cout<<"\n The output is: ";
     
        for(j=0;j<6;j++)
          cout<<" "<<output[j];
     
        getch();
        }
    
     
    #77
  18. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science
    Was I not clear??? read the question! just 1 loop and 2 variables apart from array!
     
    #78
  19. Nayan Goenka

    Engineering Discipline:
    IT


    Meh, Put the for loop outside while, inside. It will work that way too. And if you are using 2 arrays, you have to use two loops atleast.

    If you want ONE loop then the output you will get will be 103050 and not 135000
     
    • Disagree Disagree x 1
    #79
  20. Vishal0203

    Vishal0203 Maniac

    Engineering Discipline:
    Computer Science
    hahahahahahha... :D
    that's the challenge bro don't tell me that it cant be done. It can be done! try!
    one loop.. one array.. 2 supporting variables
     
    #80

Share This Page