Learnem Educational
May 18, 2012, 01:30:37 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: unit 1 exercises  (Read 1572 times)
adypoly
Newbie
*
Posts: 1


View Profile WWW
« on: September 30, 2002, 04:56:43 PM »

Respected sir,

   My name is sooraj, i hereby send u my 1st exersice,plz grade it.

regards
Sooraj

[i:1cr6dwhp]Exercise 1:
What is the exact output result of this code.
[/i:1cr6dwhp]

[code:1cr6dwhp]
#include <stdio.h>

main()

{

printf("Hi\nthere\nWhat is the output\n?");

}
[/code:1cr6dwhp]
Ans:
OUTPUT:


Hi
there
What is the output
?
----------------------------------------------------------------------------------------------

[i:1cr6dwhp]Exercise 2:
Write a program that declares two floating numbers. Initialize them with float values. Then print their sum and multiplication in two separate lines.
[/i:1cr6dwhp]
[code:1cr6dwhp]
#include<stdio.h>
void main(){
   /*Declaring two decimal variables (floats)*/
   float x,y;
   /*Intialising the variables*/
   x=233.55;
   y=566.22;
   /*Printing the sum of the variables*/
   printf("The sum of %f and %f is %f\n",x,y,x+y);
   printf("The product of %f and %f is %f",x,y,x*y);
}
[/code:1cr6dwhp]
----------------------------------------------------------------------------------------------

[i:1cr6dwhp]Exersise 3 :
Write the output result of multiple function example in this lesson.
[/i:1cr6dwhp]
[code:1cr6dwhp]
#include<stdio.h>

main()

{

printf("I am going inside test function now\n");

test();

printf("\nNow I am back from test function\n");

}

test()

{

int a,b;

a=1;

b=a+100;

printf("a is %d and b is %d",a,b);

}
[/code:1cr6dwhp]
Ans:
OUTPUT

I am going inside test function now
a is 1 and b is 101
Now I am back from test function
----------------------------------------------------------------------------------------------

[i:1cr6dwhp]Exercise 4: Why these variable names are not valid ? [/i:1cr6dwhp]



test$var - $ symbol is not allowed in variable declaration, You can use letters, digits and underscore (_) character to make your variable names.

my  counter - " "(blank space) is also taken as a character which is also not allowed in variable declaration

9count - First character in a variable name must be a letter or an underscore (_) character.

float - A variable name cannot be a C programming language-reserved word (i.e. Commands and pre defined function names etc)
« Last Edit: January 01, 1970, 12:00:00 AM by adypoly » Logged

JAngS
MrDeed
Newbie
*
Posts: 8


View Profile
« Reply #1 on: September 30, 2002, 05:14:28 PM »

Hello Sooraj

You have done everything right the only thing I can complain about is that you do not return a value from main which is according to the C standard.

Otherwise...nice =)
« Last Edit: January 01, 1970, 12:00:00 AM by MrDeed » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!