Assignment 1 - C
Assignment 1 - C
Assignment 1 - C
Assignment No 1
1. Amicable numbers are found in pairs. A given pair of numbers is Amicable if the sum of the proper
divisors (not including itself) of one number is equal to the other number and vice – versa.
For example, 220 & 284 are amicable numbers First we find the proper divisors of 220:
220:1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110
1+ 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110 = 284
Now, 284: 1, 2, 4, 71, 142
1 + 2 + 4 + 71 + 142 = 220
Write a C program to check that the input pair of numbers is amicable.
2. Write a C program to check if a number has three consecutive 5s. If yes, print YES, else print NO.
Example:
Number: 1353554
Result: NO
Number: 345559
Result: YES
3. Write a C program, that reads list of n integer and print sum of product of consecutive numbers.
4. Write a C++ program to roll a six-sided die 100 times.
5. Write a program in C to find the pivot element of a sorted and rotated array using binary search
6. Write a c program which reads a paragraph from user and count number of words in a paragraph.
7. Write a c program which reads values of array and print array in reverse order.
8. Write a program in C to merge one sorted array into another sorted array.
9. Write a C program to find and remove duplicate elements of array.
10. Write a C program to find the sum of First, Third and Last element of array and then replace the zero index
with sum. Then find the product of second and fourth element and place it at index 1 of array. Then sort the
values of array in descending order to print array. Also show stack trace for this program.
11. Write a C program which read an upper-case character array from user and replace each character with
lower case ascii value of same character.
12. Write a C program to find the missing character in an array.
13. Write a C program to find whether one array is subset of other array or both arrays are mirror image of one
another.
14. Write a program in C to find the sumof (productsof) lower and upper triangular elements of a matrix.
15. Write a program in C to find the ceil & floor of any element in an array.
16. Determine the size, minimum and maximum value following data types. Please specify if your machine is
32 bit or 64 bits in the answer.
a) Char
b) Short
c) Unsigned char
d) Unsigned int
e) Int
f) Unsigned long
g) Float
17. Swap two numbers in C using addition, subtraction, and assignment operators: Logic.
18. Write a C program to reverse the sum of consecutive numbers.
19. Write a C program to compare two numbers without IF statement.
20. Write a C program to find all roots of a quadratic equation.
21. Write a program in C++ to check overflow/underflow during various arithmetical operation
22. Write a C program that prints pyramid and half pyramid.
23. Write a C program to check whether a character is an alphabet, digit, or special character.
24. Display Armstrong number between intervals
25. Write a C++ program to isolate rightmost zero bit of a number.
Output:
original number before isolating rightmost 0 bit: 11
new number after isolating rightmost 0 bit: 4
29. Write a C program to find the eligibility of admission for a professional course based on the
following criteria:
Eligibility Criteria : Marks in Maths >=65 and Marks in Phy >=55 and Marks in Chem>=50 and Total in all
three subject >=190 or Total in Maths and Physics >=140 ------------------------------------- Input the marks
obtained in Physics :65 Input the marks obtained in Chemistry :51 Input the marks obtained in Mathematics
:72 Total marks of Maths, Physics and Chemistry : 188 Total marks of Maths and Physics : 137 The
candidate is not eligible.
30. Write a program in C which is a Menu-Driven Program to compute the area of the various
geometrical shape.
31. Write a program in C which is a Menu-Driven Program to do all arithmetic operations. Make sure
there is different function for each individual arithmetic operation. Values for arithmetic
operations should be read from the user. Program will only exit from the last available choice of
menu available in your program (exit). Your program must contain data validation checks on
every input from the keyboard.
32.
33. Fix the errors and write output of following statements:
a) printf ("TRUE %nOR %nFALSE");
b) printf ("10 %% 4 = 2");
c) println("Hello! \f How are you all? ");
d) println("\\- this is a backslash. ");
e) println("Good Morning\t Geeks! ");
f) println("Hi Learners, welcome to \"CUI\".");
g) printf( "%s\n%s\n%s\n", "*", "***", "*****" );
h) printf(“%+d”, 2502);
i) printf ("|%-20.4f|", 1234.1234);
j) printf ("10 %% 4 = 2");
k) printf ( "%E", 123.1234);
l) e= 123.1234;
println("UpperCase Scientific Notation" + " using %E: " + e);
m) Int x=1245;
printf("Number: %o\n", x);
n) Long n= 461012;
z=x*y;
s=x+y;
println("Product= " + z + “and” +" Sum= "+ s +".");
q) Int i=88;
printf ("%010d", i);
println ("value in 10 digits: + i);
r) println (%.10s", "12345678901234567890");
s) String firstname= Sara;
String lastname= Khan;
println("First Name: " + firstname + " Last Name: "+ lastname +".");
println ("First Name: %s", firstname);
println ("Last Name: %s", lastname);
t) printf("%s\n%s\n”, “Welcome to” , “ C programming”);
u) int a=6, b=12, c=12;
sum= a+b+c;
printf(“Sum is %d\n”, sum);
v) int num1=5;
int num2=6;
if (num1 !=num2)
printf(“%d != %d \n”, num1, num2 );
w) char str[] = "cprogrammingexercise";
x) int a = 0;