> C programing help please?

C programing help please?

Posted at: 2014-12-18 
Before you begin writing code, you must have a clear idea of the steps required to perform the task.

This is formally done by creating a logic flowchart, but you can also just write the steps down on paper in sentences.

For instance, the first step is to provide a variable in which to store your number.

The next step is to assign a value to the variable.

That might be a direct assignment in code, or it might require some interaction by the user.

So you have to decide how you are going to interact with the user, and how the user's input will be assigned to the variable.

In the function to add the digits, you have to determine how the function will receive it's data.

How many parameters will it take?

What will it do with the data?

In this function you will have to dissect the number into digits.

So how will you pull the digits apart one-by-one?

When you write code like this, test each line at a time to make sure it works as you expect before writing more code.

Solving problems like this requires reducing the problem down to its simplest parts, and reconstructing it step by step.

Even after you finish the whole semester, I wouldn't expect you to "fully understand". Someone isn't generally considered an expert until they've worked 5 years full-time as a programmer.

Anyways, this seems to be a very strange assignment to give after only 2 days When you say you have "a basic knowledge" what is that supposed to mean? Is that supposed to be the amount you have learned in only 2 days, or was there a prerequisite course?

Why were you asking questions about C 6 days ago if the course only started 2 days ago?

It seems that you are attempting to get through this course without doing any of the homework yourself. You seem to be forgetting that there will also be exams. How will you get help during the exams.

#include

int sumdig(int);

int main()

{

printf("%d\n",sumdig(123));

return 0;

}

int sumdig(int n){

int sum=0;

while(n){

sum+=n%10;

n/=10;

}

return sum;

}

i would go on you tube that's how im learning to program in c

Hi , You can use codecademy its a good site for all that stuff!

codecademy.com

I started a c languge class and the teacher has given us an assignment already. I have a basic knowledge of c but don't fully understand how to write a full code yet

here is our assignment

Write a function that takes an integer as its parameters and returns sum of digits.

Example 1234 as input should return 10. Have main function test your function.

now I know its easy to do (he kept repeating that) but I cant visualize what to write. our class started two days ago so my knowledge of c isn't to great

if you could tell me what to write or write the program and explain to me what each part means that would be greatly appreciated

this is what I got so far which is just the skeleton

#include

int main()

{

return 0;

}