C Practicing Questions

C Practicing Questions




1. Write a program to find the difference between the sum of the squares and the square of the sum of the first n natural numbers.
For Example if n is 10,you have to find
(1^2+2^2+3^2+....9^2+10^2)-
(1+2+3+4+5...+9+10)^2

2. Write a program to check if a number is an increasing number. A number is said to be an increasing number if no digit is exceeded by the digit to its left.
For Example : 134468 is an increasing number

3. Write a programm to check if a number is an increasing number.
A number is said to be an increasing number if no
digit is exceeded by the digit to its left.
For Example : 134468 is an increasing number

4.  Write a programm which accepts an integer array, reverse the numbers in the array and returns the resulting array in sorted order.
Ex: {12,23,96,45}
Step 1: Reverse numbers
{21,32,69,54}
Step2: Sort it
{21,32,54,69}

5.  Programm to sort the first half of the array in ascending order and second half in descending order.

6. Programm to merge two arrays without duplicate.

7. Programm to count the occurrence of each and every number from an array.

8. Programm to interchange with first and last element from an array.

9. Programm to find the repeated element count.

10. Programm to calculate which element is maximum repeated.

11. Write a c program which display non fibonacci series upto n term.

12. Write a c program which display Lucas number upto nth term.

13.  Write a c program which display prime and composite number upto to nth term.

14. Write a c program which will take n numbers in an array. If any element is an armstrong no store the summation of all the digit in another array. If the element is a prime no store the element as reverse order in the destination array. Otherwise store the factorial of the element into the array.

15. write a c program which will take n numbers in an array. Split the array from the third highest no position and store the both half as reverse order in two different array.

16. Given a array as input1 which contains rack number as 1st element and product id as 2nd element and so on. Integer input2 as size as array and a integer input3 which is the id of a product. Write code to return the rack numbers which contains the product as specified in the input3.

Example :
            int input1[]={100,30,200,40,300,30,400,20,500,30}
            int input2=10;
            int input3=30;
            int output1[]={100,300,500}

17. Given a array as input1 which contains user id as 1st element and date of birth as 2nd element. Write code to generate password for each user. Store the generated password in a output1[]. The password generation logic : XXYYYZZZZ, where XX-month of birth, YYY-last three character of id and ZZZZ year of birth.

Note: Format of Date of birth :MMDDYYYY
Example :
            long input1[]={234321,24101977,278762,01041997,909808,16112000}
            int input2=6
            int output[]={103211977,047621997,118082000}

18. Given a array as input1 which contains some employee id. The format of the ID ZZYYZZ, where ZZ is manager id,YY is employee and ZZ is department id. Write code to count how many employees are there in each end every department and store in output1[]. In output1[] department id will be store in 1st element and no of employee in that department will be store in 2nd element and so on.

Example :
            int input1[]={105070,105180,205270,305360,305470,205580}
            int input2=6
            int output[]={70,3,80,2,60,1}

19. Given a array as input1 which contains some employee id. The format of the ID ZZYYZZ, where ZZ is manager id,YY is employee and ZZ is department id. Write code to count how many department are there. Store the result in output1.

Example :
            int input1[]={105070,105180,205270,305360,305470,205580}
            int input2=6
            int output1=3

20. Given a array as input1 which contains student registration number as element. The format of the registration number is XXXYYZZZZ, where XXX is a integer student id, YY is the stream and ZZZZ is the registration year. According to the rule only candidate from IT and CS is eligible for the campus interview. Write a code to return a new array of all the eligible candidate's ids.

Note: Possible value for YY:
            10->IT
            20->ECE
            30->ME
            40->CS
 
Example :
            int input1[]={987102012,787202013,123402012,234402013}

            int output1[]={987,123,234}

21. C program to check perfect number.
Perfect number is a positive number which sum of all positive divisors excluding that number is equal to that number. For example 6 is perfect number since divisor of 6 are 1, 2 and 3.  Sum of its divisor is
1 + 2+ 3 =6

Note: 6 is the smallest perfect number.

Next perfect number is 28 since 1+ 2 + 4 + 7 + 14 = 28
Some more perfect numbers: 496, 8128


22. Write a c program to check whether a number is strong or not
Definition of strong number:

A number is called strong number if sum of the factorial of its digit is equal to number itself. For example: 145 since
1! + 4! + 5! = 1 + 24 + 120 = 145

23. Take n number as input in an array. All the odd numbers willl be replaces by the factorial of that number. All the even number will be replace by the cube of the number.If any number is negative, return -1. Finally, display the content of the array

24. Take n number as input in an array. Find the sum of cube of the prime numbers. If any number is negative, return -1. Finally, display the result.

25. Take n number as input in an array. Interchange all the elements of the first half with the second half. If any number is negative, return -1.Finally, display the content of the array.

26. In a given input array elements are given in this Format PPPII where PPP represents the Project Code and II represents id . find out the employee Ids  who are working in given Project code (input3) .Consider input2 as size of the array.
Note : please follow the order in the output shown in the example
    Example :
             input1 :  {12345,12334,23457,23478,12546}
             input2 :  5
             input3 : 123
             output1 : {45, 34}

27. In a given array find out  odd entries and calculate the multiplication of individual digit of each odd entry.
Note : please follow the order in the output shown in the example 
Example :-
 Input1 : {12,34,45,56,22,19,21,93}
odd numbers [45,19,21]
 output1 : {20,9,2,27}

27. Write a program to find out the Next Prime  which is next closest prime number to the given input. 
input1:  9
output1: 11

28. In a Give  input1 array First index  Represents  RollNo second index represents  Mark and so on. Find out how many students are cleared the Exam.
Note :: If marks >=70 then He /she Cleared the exam.
Example:
input1 : { 1,70,2,55,3,75,4,80}
input2 :  8
output1 : 3 

29. In a Given  input1 as Integer array. Find the average of the numbers located on the Prime Indexes of the Array.  Consider 0 index as 1 and 1 index is 2 and so on……
Note :Consider 1 is not a prime number

Example:
input1: {2,4,5,1,9,3,8}
 output1    =(4+5+9+8)/4 =6

30. In a game show everybody got one coupon with some code. They need to sum the digit which is less than 5 and send SMS the output. Find the answer and store it in the variable output1. If number  doesnot contain any digit  less than 5 store 1 variable
Example1 :
Input1 = 4359
Output1 = 7
Example2 :
input1 :6677
output1 :1

31. In Given input Integer array,  Find the difference in the adjacent elements and store the largest difference  in output1 variable.

Example:
input1: {2,4,5,1,9,3,8}
 
output1: 8 (The AdjecentElement Diff are :2,1,4,8,6,5 and Maximum diff is 8) [2-4 =2, 4-5=1,5- 1 =4, 1-9=8,9-3=6,3-8 =5)

32. Write a program to generate new number  of given input on  following conditions.
conditions.

(i) Even digit should be replaced by next Even digit.
(ii)  Odd digit should be replaced with next Odd digit
        Example:
          input1:  123
         Output1: 345

Post a Comment

Post a Comment (0)

Previous Post Next Post