Thursday, November 29, 2012

Exercises (arrays, pointers, functions).

Exercises (arrays, pointers, functions).


1. Write a program to update the value of the double variable flt_num from 123.45 to 543.21 by
using a double pointer.

2. Given a character variable ch and ch = ‘A’, write a program to update the value of ch to
character 'a' by using a pointer.

3. Given an integer array initialized as (int niceArray[]={23,4,4,56,45,5,6,1,34,787};), write a
program to increase each array element by 1000 using a nother pointer.

4. Write a function to calculate a factorial value. Then use that function to calculate 6C2 (possible
combinations in selecting 2 out of 6) and display the value.
(Hint: int factorial(int f1); combinations=factorial(6)/(factorial(2)*factorial(4)); )

5. Write seperate functions,
1. to read an integer value from the keyboard, (int readNumber(); )
2. to display two integer values, (void display(int a,int b); )
3. to swap two integer values, (void swap(int *c,int *d); )
Write a program to read two integer values to two variables, display them
before their values are swaped between them then swap those values and
finally display the two variables. (Hint: Use above functions)

Thursday, November 22, 2012

Loop Assignment Answers

Loop Assignment Answers


1) Write a program to display numbers from 1 to 250.

2) Write a program to calculate the sum of all the numbers less than a given number n.
ex: output
Enter number : 3
6
Enter number : 5
15




3) Write a program to display “hello world” for every time we enter the character 'y' and stop the
program when we enter the character 'n'. For any other character program should not stop or
display anything.

4) Write a program to calculate the factorial value for a given number N.

5) Write a program to calculate number of possible combinations that we can have when we
selecting r number of elements from n number of different elements. This can be calculated by
calculating the value n!/(r!*(n-r)!).

Thursday, November 15, 2012

Assignment Answers

Assignment Answers

1) Write a program to check the given number is positive or negative.


2) Write a program to Add two numbers if the first one is greater than the second number if not
display an error message.


3) Write a program to display the grade (A, B, C or D) according to the given mark.
hint: A(between 100 and 75)/ B(between 74 and 65)/ C(between 64 and 55)/ D(between 54 and
0)

4) Write a program to read a two characters and display them if both are not equal.
5) Write a program to input a temperature reading in either Celsius (c) or Fahrenheit (f)scale and
convert it to the other scale. The temperature reading consists of a decimal integer followed by
letter “F” or “f” if the temperature is in Fahrenheit scale or letter “C” or “c” if it is in Celsius
scale. You may use a similar format for the output of the program.