Jump to content

C lesson #2-Sum

Recommended Posts

Hope you revised the previous lesson..!

if yes you could write a program like this..!

Q: Write a program to print My first C program in screen.

Ok forward to today's lesson we will today use some variables and data types..!

I'll not a teacher to teach you with definations but i'll do my best so a variable can hold differnt values u'll understand what i meant to say till the end of the post..!

now there are different data types like int ,char ,float,long,double

Int      %d

CHar  %ld

Float    %f 

Double  %lf

Char      %c

you might be thinking whats that % % thingy?thats we use where we want to use that data type u'll understand that too till post end..

Now currently therz a lot confsion going on your mind to clear them lets go to programming..!

we learnt till yet how to print things now we will calculate sun of things..!

#include <stdio.h>


void main()


int a,b,c;





printf("%d", c);



Read the program once again now..! here int is the data type we choose

REASON:Because it supports numeric data we could choose float double and long too //

Now than we took 3 variables in int thats a, and c..

The value of each variable is written downwards thats a=10 and b=30 and the other variable c=a+b(means their sun..!

Note: ; is also placed after every line see..

Now going furthur to printf function now as i told you %d is donated for int data type so we wrote


here %d would be replaced by the value of C thats a+b everytym to replace some values we place ,(comma) after the end now simply we meant say in simple words

print that %d in output screen and %d is replaced by C that is sum of a+b..

Out put will be simply 40 in screen //!

Have fun in next class we'll learn about taking sum multiply etc by the values of a and b user input..!

Revise what i taught i'll be asking questions too in next class.!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...