Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Programming

Assignment No 1

Due Date: March 16, 2021/Tuesday

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

26. Write a program to determine color of chess square.


27. Determine the hierarchy of operations and evaluate the following expression:
3+4 x 10 ( y−5 ) ( a+b+ c ) 4 9+ x
a) − +9 ( + )
5 x x y
b) 5.5* ((r +2.5)2.5+t )
4 3+d (2+ a)
c) −9( a+bc)+
3(t+ 34) a+bd
28. Using precedence rules, evaluate the following expressions and determine the value of the variables
(without running the code). Also rewrite them using parenthesis to make the order explicit.
a) Assume (x=0xFF33,MASK=0xFF00).Expression: c=x & MASK ==0;

b) Assume (x=10,y=2,z=2;).Expression: z=y=x++ + ++y∗2;

c) Assume (x=10,y=4,z=1;).Expression: y>>= x&0x2 && z

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;

printf ("%+8d%n", n);

o) Double pi= 3.142;


printf ("%.3f%n", pi);
printf ("%10.3f%n", pi);
p) int x=6, y =12, z;

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";

     printf("%20s\n", str);


     printf("%-20s\n", str);
    printf("%20.5s\n", str);
     printf("%-20.5s\n", str);
    

x) int a = 0;

    scanf("%d", &a); // input is 45


      printf("%d\n", a);
    
y) int a = 0;
     scanf("%i", &a);
     printf("%d\n", a);
     scanf("%i", &a);
     printf("%d\n", a);

z) char name[20] = "Bob";


int age = 21;
printf("Hello %s, you are %d years old\n", name, age);

You might also like