Jump to content

C lesson #2-part 2-Sum


Recommended Posts

i expect you have learned what i taught in previous class SO answer this

Q:what will be output when i have this replced in printf

printf("sum=%d",c);

Answer:: Think before you answer what i taught is %d replaces so output would be

sum=40

**************************************************************************************

Forward to todays's class now this aint a calculator indeed so if we want user to input we'll use another function

scanf which will scan what user entered and will take that to complete program//!

#include <stdio.h>

#include<conio.h>

void main()

{

int a,b,c;

clrscr();

C=a+b;

printf("enter first no.=");

scanf("%d", &a);

printf(2nd no.=");

scanf("%d", &B);

printf("Sum=%d",C);

getch();

}

here in program scanf function is used to scan what user entered firstly program will print enter first no.=

than after that we will enter the no. and scanf function will detect what we have entered

you might be asking all fine that % would be repalced by a but why & is used?

Reason:its used to address something in program..!

now it will print 2nd no.= we will enter the no. and it will be replaced by B than it will print C that is mentioned above that c would be equal to a+b..

hence all fine i think..!

REvise practise

i'll be asking questions 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.

Guest
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.

Loading...
×
×
  • Create New...