1.
Compute area of a rectangle.
Make two integers- length and width. Take the values of them from the user.
Show the area of the rectangle.
2.
Compute the volume of a
cylinder. Ask the user to input the radius (r). Assign the value 3.14 to a
variable called pie. (hint: volume of a cylinder=4/3*pie*r*r*r). Take all the
variables as float.
3. Modify the above program. a and b will be input by the user. Declare
four more variables and take a-b, a*b, a/b and a%b into them. Show all of the
four variables as well.
4.
Compute Jovian years. Jupiter
rounds the sun in 10 hours. It will be interesting to know if the Earth passes
X years, how many years Jupiter will pass. Ask the user to put the years the
Earth passes. Make appropriate calculations with arithmetic operators and show
how many years Jupiter passes by that time.
5.
Write a program that shows the
volume of a cube. Ask the user to input three dimensions of the cube- length,
width and height.
6.
Swapping values of variables.
Check the following program. It takes two integers- a and b. Then, with the
help of another integer variable c (we call it temporary variable), we swapped
the values (value of a goes to b and vice versa).
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter a , b: ");
scanf("%d%d",&a,&b);
printf("Before Swapping a: %d b: %d ",a,b);
c=b; // taking b to c, b is empty now
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter a , b: ");
scanf("%d%d",&a,&b);
printf("Before Swapping a: %d b: %d ",a,b);
c=b; // taking b to c, b is empty now
b=a;
// taking a to b, b contains a
a=c;
// taking c to b, a contains previous value of b
printf("After Swapping a: %d b: %d",a,b);
getch();
}
printf("After Swapping a: %d b: %d",a,b);
getch();
}
Swap the values
of two numbers without using temporary variable.
7. Write a program that takes an integer from the user and can tell if
the integer is odd or even. (hint: if you divide an integer with 2 and there is
reminder- that integer is odd, else it is even).
8.
The Grade conversion. Ask the
user to input his marks. Then convert the marks into letter grades and provide
it to the user. The grade conversion chart is given here-
Marks
|
Grade
|
Marks
|
Grade
|
160 or more
|
A+
|
150-159
|
A
|
140-149
|
A-
|
130-139
|
B+
|
120-129
|
B
|
110-119
|
B-
|
100-109
|
C+
|
90-99
|
C
|
80-89
|
D
|
Less than 80
|
F
|
9.
A company insures its drivers
in the following cases-
1. If the driver
is married
2. If the driver
is unmarried, male & above 30 years of age
3. If the driver
is unmarried, female & above 25 years of age
In all other
cases, the drivers are not insured. Write a program that takes input marital
status, sex and age of the driver. Determine whether the driver is insured or
not.
10. Enter a character from the keyboard. Write a program to determine
whether the character is a capital letter, a small case letter, a digit or a
special symbol. [Hint: you can directly compare a character with an integer
value]. Use the following table for the comparison.
Characters
|
ASCII Values
|
A-Z
|
65-90
|
a-z
|
97-122
|
0-9
|
48-57
|
Special
symbols
|
0-47, 58-64,
91-96, 123-127
|
11. Write a program that prints the following (Hint: Use nested while repetition)-
1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 6 9 12 15 18 21 24 27 30 33 36
4 8 12 16 20 24 28 32 36 40 44 48
5 10 15 20 25 30 35 40 45 50 55 60
6 12 18 24 30 36 42 48 54 60 66 72
7 14 21 28 35 42 49 56 63 70 77 84
8 16 24 32 40 48 56 64 72 80 88 96
9 18 27 36 45 54 63 72 81 90 99 108
10 20 30 40 50 60 70 80 90 100 110 120
11 22 33 44 55 66 77 88 99 110 121 132
12 24 36 48 60 72 84 96 108 120 132 144
12. Take a number from the user. Calculate its factorial. (useful hint: take
the type of the variable long).
n.b. A factorial of a number 5 is as
follows-
5X4X3X2X1=120
13. Write a program to print all prime numbers from 1 to 300.
14. According to a study, the approximate level of intelligence of a
person can be calculated using the following formula: i = 2 + ( y + 0.5 x ). Write
a program, which will produce a table of values of i, y and x, where y varies
from 1 to 6, and, for each value of y, x varies from 5.5 to 12.5 in steps of
0.5.
15.
Write a menu driven program
which has following options:
1. Factorial of a number.
2. Prime or not
3. Odd or even
(hint: Use switch
statement for taking the choice and inside of 3 cases, just put the code you
did for factorial of a number, determining prime number and program you wrote
to find out odd or even)
16. Ask the user to put an integer. Using a do-while loop, find its
triangular number. For example, the triangular number of 7 is 7+6+5+4+3+2+1=28.
Write a program to determine
whether a number is prime or not using for loop.
17. Write a menu driven program with switch statement. In this case,
user will give two integers and a choice.
Choice=1: add the integers and
show the answer
Choice=2: subtract the integers
and show the answer
Choice=3: multiply the integers and
show the answer
Choice=4: divide the integers and
show the answer
Default: show error message
18. Write a function power ( a, b), to calculate the value of a raised
to b. (hint: do not use the pow() built in function of C).
19. Write a function gcd (a,b) that returns the Greatest Common Divisor
of a and b.
(hint: gcd of 12 and 18 is= 6;
18/12,
division 1, remainder 6
12/6,
division 2, remainder 0
therefore,
the gcd is 6)
you should have a SWAPPING
mechanism in your program, i.e., 18/12 is possible but not 12/18. In that case
your program will swap the values
20. Write a program using appropriate user defined functions that
returns the Least Common Multiple of a and b.
21. A positive integer is entered through key-board. Write a function to
obtain the prime factors of this number.
(hint: prime factors of 24 are
2,2,2 and 3. prime factors of 35 are 5 and 7).
22.
Write a program that will ask 10 values
from the user. And for those 10 values, draw the histogram.
23. In wars, there are certain codes. These codes are exchanged between
two soldiers of the same army. The opponent army mostly tries to capture the
code to get valuable information. Therefore, two soldiers while exchanging
their information introduce cryptography. For example, Iamdoingfine
can be encrypted as Jbnepjohgjof. How? Simply turning a letter to
its following letter: iàj, aàb, màn and so on.
24. Write a program that will take such string from the user and will
convert that string into such encrypted message.
25. Initialize a multidimensional array (10X3) so that the first element
of each row contains a number, the second element contains its square and the
third element gets its cube. Stop at 10.
1 1 1
2 4 8
3 9 27
……….
……….
10 100 1000
Now, ask the
user to put the cube. Look up this value in the multidimensional array and
print its cube’s root and root’s square.
26. Make two arrays of dimension 3X3. Think of these two arrays as two
matrices. Multiply the matrices using the matrix multiplication procedure. Show
the result in matrix format.
27. Create an integer array of 20 elements. Ask the user to put 20
numbers (similar numbers can be given). Determine their frequency. For example,
if the user puts 10,11,1,1,2,10,10,11,2,2- then the frequency will be-
10: 3 times
11: 2 times
1: 2 times
2: 3 times
28. Write a program that will take an array of values and sort them
according to bubble sort procedure.
1 comments:
Awesome blog.aircon chemical overhaul
Post a Comment