Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 147.55 KB | None | 0 0
  1. 1.account number
  2. #include<stdio.h>
  3. #include<conio.h>
  4. int reg(int n, int a[], int c);
  5. int main(){
  6. int n=0,num,a[30],i,flag=0,bcode=0;
  7. clrscr();
  8. printf("\nEnter the number of array elements:");
  9. scanf("%d",&n);
  10. if(n<0){
  11. printf("\nInvalid array size");
  12. }
  13. printf("\nenter the elements:");
  14. for(i=0;i<n;i++){
  15. scanf("%d",&a[i]);
  16. if(a[i]<0)
  17. flag=1;
  18. }
  19. if(flag==1){
  20. printf("\nInvalid account number");
  21.  
  22. }
  23. printf("\nenter the branch code to be verified");
  24. scanf("%d",&bcode);
  25. if(bcode<0){
  26. printf("\nInvalid branch code");
  27. }
  28. num=reg(n,a,bcode);
  29. printf("\nThe number of account numbers in that branch are%d",num);
  30. getch();
  31. return 0;
  32. }
  33. int reg(int n, int a[], int c){
  34. int i,temp,bcode=0,count=0;
  35. for(i=0;i<n;i++){
  36. temp=a[i];
  37. bcode=temp/100;
  38. if(bcode==c)
  39. count++;
  40. }
  41. return count;
  42. }
  43. 2.average odd key values
  44. #include<stdio.h>
  45. #include<conio.h>
  46. int avgoddkeyvalues(int a[],int n)
  47. {
  48. int count=0,sum=0,avg;
  49. for(i=0;i<n;i+=2)
  50. {
  51. if(a[i]%2!=0)
  52. {
  53. sum=sum+(a[i+1]);
  54. count++;
  55. }
  56. }
  57. avg=sum/count;
  58. return avg;
  59. }
  60. main()
  61. {
  62. int i,n,a[100],counter;
  63. clrscr();
  64. printf("\nenter the total num of values");
  65. scanf("%d",&n);
  66. printf("\nenter the array values:");
  67. for(i=0;i<n;i++)
  68. scanf("%d",&a[i]);
  69. counter=avgoddkeyvalues(int a[],int n);
  70. printf("the average odd key values are %d",counter);
  71. getch();
  72. return 0;
  73. }
  74. 3.product of maximum and minimum
  75. #include<stdio.h>
  76. #include<conio.h>
  77. int promaxmin(int a[],int n)
  78. {
  79. int i,j,maxmin,temp;
  80. for(i=0;i<n;i++)
  81. {
  82. for(j=0;j<n;j++)
  83. {
  84. if(a[j]>a[j+1])
  85. {
  86. temp=a[j];
  87. a[j]=a[j+1];
  88. a[j+1]=temp;
  89. }
  90. }
  91. }
  92. maxmin=a[0]*a[n-1];
  93. return maxmin;
  94. }
  95. main()
  96. {
  97. int n,a[100],i,pro;
  98. clrscr();
  99. printf("\nenter the number of inputs:");
  100. scanf("%d",&n);
  101. printf("\nenter the values one by one:");
  102. for(i=0;i<n;i++)
  103. scanf("%d",&a[i]);
  104. pro=promaxmin(a,n);
  105. printf("\n%d is the values",pro);
  106. getch();
  107. return 0;
  108. }
  109. 4.sum of prime numbers in the array
  110. #include<stdio.h>
  111. #include<conio.h>
  112. void main()
  113. {
  114. int a[100],i,n,j,counter,sum=0;
  115. clrscr();
  116. printf("\nenter the no of elements:");
  117. scanf("%d",&n);
  118. for(i=0;i<n;i++)
  119. scanf("%d",&a[i]);
  120. for(i=0;i<n;i++)
  121. {
  122. counter=0;
  123. for(j=2;j<a[i];j++)
  124. {
  125. if(a[i]%j==0)
  126. {
  127. counter=1;
  128. break;
  129. }
  130. }
  131. if(counter==0)
  132. {
  133. sum=sum+a[i];
  134. }
  135. }
  136. printf("\n the sum of the prime numbers in the array is %d",sum);
  137. getch();
  138. }
  139. 5.average of prime index sum
  140. #include<stdio.h>
  141. #include<conio.h>
  142. prime(int a[],int n)
  143. {
  144. int temp=0,counter=0,sum=0,i,j,avg;
  145. for(i=2;i<=n;i++)
  146. {
  147. counter=0;
  148. for(j=1;j<=i;j++)
  149. {
  150. if(i%j==0)
  151. counter++;
  152. }
  153. if(counter==2)
  154. {
  155. sum=sum+a[i];
  156. temp++;
  157. }
  158. else
  159. continue;
  160. }
  161. avg=sum/temp;
  162. return avg;
  163. }
  164.  
  165. main()
  166. {
  167. int n,a[100],avg,i;
  168. clrscr();
  169. printf("\nenter the number of elements");
  170. scanf("%d",&n);
  171. printf("\nenter the number of elements one by one");
  172. for(i=1;i<=n;i++)
  173. {
  174. scanf("%d",&a[i]);
  175. }
  176. avg=prime(a,n);
  177. printf("\nthe prime index sum average is %d",avg);
  178. getch();
  179. return 0;
  180. }
  181. 31.sumPrimeArray
  182. Read the question carefully and follow the input and output format.
  183.  
  184. John is working in a bank. He has created account details transaction in a file and protected it with a password. He sent the file to his manager for review. The file is protected with a password. The password is the sum of Prime numbers. Write a function to generate the password.
  185.  
  186. Input and Output Format:
  187. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of an integer, which is the sum.
  188.  
  189. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program.
  190. 2) Print "Invalid input" when there is any negative number available in the input array and terminate the program.
  191. 3) Print 0, when there are no prime numbers in a given input array.
  192.  
  193. Include a function named sumPrimeArray(int array[], int size) whose return type is an integer, which is the prime sum.
  194.  
  195. Sample Input 1:
  196. 5
  197. 1
  198. 2
  199. 3
  200. 4
  201. 5
  202.  
  203. Sample Output 1:
  204. 10
  205.  
  206. Sample Input 2:
  207. 3
  208. 4
  209. 8
  210. 9
  211.  
  212. Sample Output 2:
  213. 0
  214. #include<stdio.h>
  215. #include<stdlib.h>
  216. int sumPrimeArray(int array[], int size);
  217. int main(){
  218. int n=0,flag=0,i,input[20],sum=0;
  219. scanf("%d",&n);
  220. if(n<0){
  221. printf("Invalid Input");
  222. getchar();
  223. getchar();
  224. exit(0);
  225. }
  226. for(i=0;i<n;i++){
  227. scanf("%d",&input[i]);
  228. if(input[i]<0)
  229. flag=1;
  230. }
  231.  
  232. if(flag==1){
  233. printf("Invalid Input");
  234. getchar();
  235. getchar();
  236. exit(0);
  237. }
  238. sum = sumPrimeArray(input,n);
  239. printf("%d",sum);
  240. getchar();
  241. getchar();
  242. return 0;
  243. }
  244. int sumPrimeArray(int array[],int n){
  245. int sum=0,i=0,j,count=0;
  246. for(i=0;i<n;i++){
  247. count=0;
  248. for(j=1;j<=array[i];j++){
  249. if(array[i]%j==0)
  250. count++;
  251. }
  252. if(count==2)
  253. sum=sum+(array[i]);
  254. }
  255. return sum;
  256. }
  257. 32. avgOddKeyValues
  258. Read the question carefully and follow the input and output format.
  259.  
  260.  
  261. Given an input array, First index represents key and second index represents the value and so on... Write code to find out the average of all values whose keys are odd numbers.
  262.  
  263. Input and Output Format :
  264. First line of input consists of n, the next n lines correspond to the elements of the array. Output consist of the an integer.
  265.  
  266. Print "Invalid array size" when size of the array is a negative number and terminate the program.
  267. Print "Invalid input" when there is any negative number available in the input array and terminate the program.
  268.  
  269. Include a function named avgOddKeyValues(int numbers[], int size) whose return type is an integer.
  270.  
  271. Sample Input 1:
  272. 8
  273. 1
  274. 3
  275. 2
  276. 4
  277. 3
  278. 16
  279. 4
  280. 25
  281. Sample Output 1:
  282. 9
  283.  
  284. Sample Input 2:
  285. -3
  286. Sample Output 2:
  287. Invalid array size
  288. #include<stdio.h>
  289. #include<stdlib.h>
  290.  
  291. int avgOddKeyValues(int numbers[], int size);
  292. int main(){
  293. int n=0,avg=0,input[30],i,flag=0;
  294. scanf("%d",&n);
  295. if(n<0){
  296. printf("Invalid array size");
  297. getchar();
  298. getchar();
  299. exit(0);
  300. }
  301. for(i=0;i<n;i++){
  302. scanf("%d",&input[i]);
  303. if(input[i]<0)
  304. flag=1;
  305. }
  306. if(flag==1){
  307. printf("Invalid Input");
  308. getchar();
  309. getchar();
  310. exit(0);
  311. }
  312. avg = avgOddKeyValues(input,n);
  313. printf("%d",avg);
  314. getchar();
  315. getchar();
  316. return 0;
  317. }
  318. int avgOddKeyValues(int numbers[], int size){
  319. int i,j=0,avg=0,sum=0;
  320. for(i=0;i<size;i=i+2){
  321. if(numbers[i]%2!=0){
  322. sum=sum+numbers[i+1];
  323. j++;
  324. }
  325. }
  326. avg = sum/j;
  327. return avg;
  328. }
  329. 33.Product of MaxMin Element
  330.  
  331. Write a program to find the product of the maximum and minimum element in a given input array.
  332.  
  333. Include a function named productOfMaxMin that accepts 2 arguments and returns an int. The first argument is the input array and the second argument is an int that corresponds to the size of the array. The function returns an int that corresponds to the product of maximum and minimum element.
  334.  
  335. If the size of the array is negative or if any element in the array is negative, print “Invalid Input” and terminate the program.
  336.  
  337. Input and Output Format:
  338. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  339. Output consists of an integer that corresponds to the product of maximum and minimum element in the array.
  340. Assume that the maximum number of elements in the array is 20.
  341.  
  342. Sample Input 1:
  343. 8
  344. 2
  345. 12
  346. 3
  347. 4
  348. 6
  349. 8
  350. 10
  351. 9
  352.  
  353. Sample Output 1:
  354. 24
  355.  
  356. Sample Input 2:
  357. -5
  358.  
  359. Sample Output 2:
  360. Invalid Input
  361.  
  362. Sample Input 3:
  363. 5
  364. 23
  365. 2
  366. -200
  367.  
  368. Sample Output 3:
  369. Invalid Input
  370.  
  371. #include<stdio.h>
  372. #include<stdlib.h>
  373.  
  374. int productOfMaxMin(int numbers[], int size);
  375. int main(){
  376. int n=0,product=0,input[30],i,flag=0;
  377. scanf("%d",&n);
  378. if(n<0){
  379. printf("Invalid input");
  380. getchar();
  381. getchar();
  382. exit(0);
  383. }
  384. for(i=0;i<n;i++){
  385. scanf("%d",&input[i]);
  386. if(input[i]<0)
  387. flag=1;
  388. }
  389. if(flag==1){
  390. printf("Invalid Input");
  391. getchar();
  392. getchar();
  393. exit(0);
  394. }
  395. product = productOfMaxMin(input,n);
  396. printf("%d",product);
  397. getchar();
  398. getchar();
  399. return 0;
  400. }
  401. int productOfMaxMin(int numbers[], int size){
  402. int i,j=0,prod=0,temp=0;
  403. for(i=0;i<size;i++){
  404. for(j=i+1;j<size;j++){
  405. if(numbers[i]<numbers[j]){
  406. temp = numbers[j];
  407. numbers[j] = numbers[i];
  408. numbers[i] = temp;
  409. }
  410. }
  411. }
  412. prod = numbers[0] * numbers[size-1];
  413. return prod;
  414. }
  415. 34.registerAccountNumbers
  416.  
  417. Read the question carefully and follow the input and output format.
  418.  
  419. Given an array in which the elements are in xxxyy format, where first xxx digits represent the Branch code and the yy represents the account
  420. id. Find out the No of accounts in the given branch code
  421.  
  422. Input and Output Format :
  423. The first input n corresponds to the size of the array, the next n lines correspond to the elements of the array and the last line of the input corresponds to the branch code.
  424. Output corresponds to the number of accounts in the given branch code
  425. If the given branch code is not available, print 0.
  426.  
  427. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program
  428. 2) Print "Invalid account Number" when there is any negative number available in the input array and terminate the program
  429. 3) Print "Invalid branch code" when branch code is negative number and terminate the program
  430.  
  431. Include a function named registerAccountNumbers (int size, int account_numbers[], int branch_code) that returns the no of accounts
  432.  
  433. Sample Input 1 :
  434. 6
  435. 12345
  436. 12370
  437. 12324
  438. 13355
  439. 13333
  440. 14575
  441. 123
  442.  
  443. Sample Output 1 :
  444. 3
  445.  
  446. Sample Input 2 :
  447. -6
  448.  
  449. Sample Output 2:
  450. Invalid array size
  451. #include<stdio.h>
  452. #include<stdlib.h>
  453. int registerAccountNumbers (int size, int account_numbers[], int branch_code);
  454. int main(){
  455. int n=0,no_of_acc=0,input[30],i,flag=0,bcode=0;
  456. scanf("%d",&n);
  457. if(n<0){
  458. printf("Invalid array size");
  459. getchar();
  460. getchar();
  461. exit(0);
  462. }
  463. for(i=0;i<n;i++){
  464. scanf("%d",&input[i]);
  465. if(input[i]<0)
  466. flag=1;
  467. }
  468. if(flag==1){
  469. printf("Invalid account number");
  470. getchar();
  471. getchar();
  472. exit(0);
  473. }
  474. scanf("%d",&bcode);
  475. if(bcode<0){
  476. printf("Invalid branch code");
  477. getchar();
  478. getchar();
  479. exit(0);
  480. }
  481. no_of_acc=registerAccountNumbers(n,input,bcode);
  482. printf("%d",no_of_acc);
  483. getchar();
  484. getchar();
  485. return 0;
  486. }
  487. int registerAccountNumbers(int size, int account_numbers[], int branch_code){
  488. int count=0,i,rem,temp=0,k=1,bcode=0,x=1;
  489. for(i=0;i<size;i++){
  490. temp=account_numbers[i];
  491. bcode=temp/100;
  492. if(bcode==branch_code)
  493. count++;
  494. }
  495. return count;
  496. }
  497. 35.newArraySum
  498. Read the question carefully and follow the input and output format.
  499.  
  500. Given an input array which contains age of some employees, write a program t fund the sum of ages of employees greater than 18.
  501.  
  502. Input and Output Format :
  503. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of an integer, which is the sum.
  504.  
  505. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program.
  506. 2) Print "Invalid input" when there is any negative number available in the input array and terminate the program.
  507.  
  508. Include a function named newArraySum(int age[],int size) whose return type is an integer, which is the sum.
  509.  
  510. Sample Input 1:
  511. 5
  512. 21
  513. 22
  514. 17
  515. 10
  516. 25
  517. Sample Output 1:
  518. 68
  519.  
  520. Sample Input 2:
  521. 6
  522. 50
  523. -36
  524.  
  525. Sample Output 2:
  526. Invalid input
  527. #include<stdio.h>
  528. #include<stdlib.h>
  529. int newArraySum(int age[],int size);
  530. int main(){
  531. int n=0,sum=0,input[30],i,flag=0;
  532. scanf("%d",&n);
  533. if(n<0){
  534. printf("Invalid array size");
  535. getchar();
  536. getchar();
  537. exit(0);
  538. }
  539. for(i=0;i<n;i++){
  540. scanf("%d",&input[i]);
  541. if(input[i]<0)
  542. flag=1;
  543. }
  544. if(flag==1){
  545. printf("Invalid Input");
  546. getchar();
  547. getchar();
  548. exit(0);
  549. }
  550. sum = newArraySum(input,n);
  551. printf("%d",sum);
  552. getchar();
  553. getchar();
  554. return 0;
  555. }
  556. int newArraySum(int age[],int size) {
  557. int i=0,sum=0;
  558. for(i=0;i<size;i++){
  559. if(age[i]>18)
  560. sum=sum+age[i];
  561. }
  562. return sum;
  563. }
  564. 36.Array Product
  565.  
  566. Write a program to find the product of posive/nonnegative elements in a given array.
  567.  
  568. Include a function named calculateProduct that accepts 2 arguments and returns an int. The first argument is the input array and the second argument is an int that corresponds to the size of the array. The function returns an int that corresponds to the product.
  569.  
  570. If the size of the array is negative or if it is greater than 10 or if any element in the array is more than 2 digits, print “Invalid Input” and terminate the program.
  571.  
  572. Input and Output Format:
  573. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  574. Output consists of an integer that corresponds to the product of positive numbers in the array.
  575.  
  576. Sample Input 1:
  577. 8
  578. 1
  579. -2
  580. 3
  581. 4
  582. -6
  583. 8
  584. 10
  585. -6
  586.  
  587. Sample Output 1:
  588. 960
  589.  
  590. Sample Input 2:
  591. -5
  592.  
  593. Sample Output 2:
  594. Invalid Input
  595.  
  596. Sample Input 3:
  597. 5
  598. 23
  599. 2
  600. 200
  601.  
  602. Sample Output 3:
  603. Invalid Input
  604.  
  605. #include<stdio.h>
  606. #include<stdlib.h>
  607. int calculateProduct(int[],int);
  608. int main(){
  609. int n=0,prod=0,input[30],i,flag=0;
  610. scanf("%d",&n);
  611. if(n<0 || n>10 ){
  612. printf("Invalid Input");
  613. getchar();
  614. getchar();
  615. exit(0);
  616. }
  617. for(i=0;i<n;i++){
  618. scanf("%d",&input[i]);
  619. if(input[i]>=100 || input[i]<=-100)
  620. flag=1;
  621. }
  622. if(flag==1){
  623. printf("Invalid Input");
  624. getchar();
  625. getchar();
  626. exit(0);
  627. }
  628. prod = calculateProduct(input,n);
  629. printf("%d",prod);
  630. getchar();
  631. getchar();
  632. return 0;
  633. }
  634. int calculateProduct(int number[],int size) {
  635. int i=0,prod=1;
  636. for(i=0;i<size;i++){
  637. if(number[i]>0)
  638. prod=prod*number[i];
  639. }
  640. return prod;
  641. }
  642.  
  643.  
  644.  
  645.  
  646. 37.Perfect Number
  647.  
  648. Write a program to find whether the given number is a perfect Number.
  649.  
  650. A number is a perfect number if the sum of the proper divisors of the number is equal to the number itself.
  651.  
  652. Include a function named findPerfect that accepts an integer argument and returns an integer. The function returns
  653. 1. 1 if the input is a Perfect Number
  654. 2. 0 if the input is not a Perfect Number
  655. 3. -1 if the input is a negative number or if it is greater than 32767
  656.  
  657. Input and Output Format:
  658. Input consists of a single integer.
  659. Output consists of a string.
  660. Refer sample output for formatting specifications.
  661.  
  662.  
  663. Sample Input 1:
  664. 6
  665.  
  666. Sample Output 1:
  667. yes
  668.  
  669. Sample Input 2:
  670. 241
  671.  
  672. Sample Output 2:
  673. no
  674.  
  675. Sample Input 3:
  676. -9
  677.  
  678. Sample Output 3:
  679. Invalid Input
  680.  
  681. #include<stdio.h>
  682. #include<stdlib.h>
  683. int findPerfect(int);
  684. int main(){
  685. int number,result=0;
  686. scanf("%d",&number);
  687. result = findPerfect(number);
  688. if(result==1)
  689. printf("yes");
  690. else if(result==0)
  691. printf("no");
  692. else
  693. printf("Invalid input");
  694. getchar();
  695. getchar();
  696. return 0;
  697. }
  698.  
  699. int findPerfect(int n){
  700. int res=0,i,sum=0;
  701. if(n<0 || n>32767)
  702. res = -1;
  703. else{
  704. for(i=1;i<n;i++){
  705. if(n%i==0)
  706. sum=sum+i;
  707. }
  708. if(sum==n)
  709. res = 1;
  710. else
  711. res=0;
  712. }
  713. return res;
  714. }
  715.  
  716. 38.Squares of Even Digits
  717.  
  718. Write a program to find the sum of the squares of even digits in a number.
  719.  
  720. Include a function named sumSquareEven that accepts an integer argument and returns an integer . The function returns -1 if the number is less than zero or if the number is greater than 32767.
  721.  
  722. Print Invalid Input if the function returns -1.
  723.  
  724. Input and Output Format:
  725.  
  726. Input consists of an integer.
  727. Output consists of an integer.
  728. Refer sample output for formatting specifications.
  729.  
  730. Sample Input 1:
  731. 3487
  732.  
  733. Sample Ouput 1:
  734. 80
  735.  
  736. Sample Input 2:
  737. -8
  738.  
  739. Sample Output 2:
  740. Invalid Input
  741.  
  742. #include<stdio.h>
  743. #include<stdlib.h>
  744. int sumSquareEven(int);
  745. int main(){
  746. int number,result=0;
  747. scanf("%d",&number);
  748. result = sumSquareEven(number);
  749. if(result==-1)
  750. printf("Invalid input");
  751. else
  752. printf("%d",result);
  753. getchar();
  754. getchar();
  755. return 0;
  756. }
  757.  
  758. int sumSquareEven(int n){
  759. int res=0,i,rem=0;
  760. if(n<0 || n>32767)
  761. res = -1;
  762. else{
  763. while(n!=0){
  764. rem=n%10;
  765. if(rem%2==0)
  766. res=res+(rem*rem);
  767. n=n/10;
  768. }
  769. }
  770. return res;
  771. }
  772. 39.sumPrimeArray
  773. Read the question carefully and follow the input and output format.
  774.  
  775. John is working in a bank. He has created account details transaction in a file and protected it with a password. He sent the file to his manager for review. The file is protected with a password. The password is the sum of Prime numbers. Write a function to generate the password.
  776.  
  777. Input and Output Format:
  778. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of an integer, which is the sum.
  779.  
  780. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program.
  781. 2) Print "Invalid input" when there is any negative number available in the input array and terminate the program.
  782. 3) Print 0, when there are no prime numbers in a given input array.
  783.  
  784. Include a function named sumPrimeArray(int array[], int size) whose return type is an integer, which is the prime sum.
  785.  
  786. Sample Input 1:
  787. 5
  788. 1
  789. 2
  790. 3
  791. 4
  792. 5
  793.  
  794. Sample Output 1:
  795. 10
  796.  
  797. Sample Input 2:
  798. 3
  799. 4
  800. 8
  801. 9
  802.  
  803. Sample Output 2:
  804. 0
  805.  
  806. #include<stdio.h>
  807. #include<stdlib.h>
  808. int sumPrimeArray(int array[], int size);
  809. int main(){
  810. int n=0,flag=0,i,input[20],sum=0;
  811. scanf("%d",&n);
  812. if(n<0){
  813. printf("Invalid Input");
  814. getchar();
  815. getchar();
  816. exit(0);
  817. }
  818. for(i=0;i<n;i++){
  819. scanf("%d",&input[i]);
  820. if(input[i]<0)
  821. flag=1;
  822. }
  823.  
  824. if(flag==1){
  825. printf("Invalid Input");
  826. getchar();
  827. getchar();
  828. exit(0);
  829. }
  830. sum = sumPrimeArray(input,n);
  831. printf("%d",sum);
  832. getchar();
  833. getchar();
  834. return 0;
  835. }
  836. int sumPrimeArray(int array[],int n){
  837. int sum=0,i=0,j,count=0;
  838. for(i=0;i<n;i++){
  839. count=0;
  840. for(j=1;j<=array[i];j++){
  841. if(array[i]%j==0)
  842. count++;
  843. }
  844. if(count==2)
  845. sum=sum+(array[i]);
  846. }
  847. return sum;
  848. }
  849. 40. Array Multiplication in Reverse
  850.  
  851. A company wanted to know the reward points of the employee so that at the end of every month they will credit some amount along with their salary. Each employee has 2 separate lists, in first list records will be sorted in employee’s employee number in ascending order. Second list records will be sorted in employee’s employee number in descending order. Hence the management has decided to multiply both the reward points and credit the amount based on the points. Here they followed the formula for multiplying the first entry value in the first list with the last entry value in the second list and second entry from the first list with the second last record from the second list. Repeat the same for all the entries in the lists.
  852.  
  853. Include a function named arrayProduct that accepts 3 arguments and ints return type is void. The first argument is the input array 1, the second argument is the input array 2 and the third argument is an int that corresponds to the size of the array. The output array is stored in a global variable named output1.
  854.  
  855. If the size of the array is negative or if any element in any of the array is negative , print “Invalid Input” and terminate the program.
  856.  
  857. Input and Output Format:
  858. Input consists of utmost 2n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the first array. The last 'n' integers correspond to the elements in the second array. If any of the inputs are invalid, then terminate the program.
  859.  
  860. Output consists of n integers that correspond to the elements in the result array.
  861.  
  862. Assume that the maximum size of the array is 20.
  863.  
  864. Sample Input 1 :
  865. 5
  866. 23
  867. 2
  868. 5
  869. 32
  870. 76
  871. 2
  872. 2
  873. 21
  874. 42
  875. 4
  876.  
  877. Sample Output 1 :
  878. 92
  879. 84
  880. 105
  881. 64
  882. 152
  883.  
  884. Sample Input 2:
  885. -5
  886.  
  887. Sample Output 2:
  888. Invalid Input
  889.  
  890. Sample Input 3:
  891. 5
  892. 23
  893. 2
  894. -5
  895.  
  896. Sample Output 3:
  897. Invalid Input
  898.  
  899. #include<stdio.h>
  900. #include<stdlib.h>
  901. int output1[20];
  902. void arrayProduct(int[],int[],int);
  903. int main(){
  904. int size=0,input1[20],input2[20],i=0;
  905. int flag1=0,flag2=0;
  906. scanf("%d",&size);
  907. if(size<0){
  908. printf("Invalid Input");
  909. getchar();
  910. getchar();
  911. exit(0);
  912. }
  913. for(i=0;i<size;i++){
  914. scanf("%d",&input1[i]);
  915. if(input1[i]<0)
  916. flag1=1;
  917. }
  918. for(i=0;i<size;i++){
  919. scanf("%d",&input2[i]);
  920. if(input2[i]<0)
  921. flag2=1;
  922. }
  923. if(flag1==1 || flag2==1){
  924. printf("Invalid Input");
  925. getchar();
  926. getchar();
  927. exit(0);
  928. }
  929. arrayProduct(input1,input2,size);
  930.  
  931. return 0;
  932. }
  933. void arrayProduct(int ar1[],int ar2[],int size){
  934. int i=0,j=0,k=0;
  935. for(i=0,j=size-1;i<size&&j>=0;i++,j--){
  936. output1[i] = ar1[i]*ar2[j];
  937. printf("%d\n",output1[i]);
  938. }
  939. getchar();
  940. getchar();
  941. }
  942. 41.University Type
  943.  
  944. Write a program to find if the student is eligible for first, second or third grade universities by finding the average of their marks given in the input integer array.
  945.  
  946. Grade should be calculated as given below :
  947. Average >80 First Grade University
  948. Average >60 Second Grade University
  949. Otherwise Third Grade University
  950.  
  951. Include a function named calculateGrade that accepts 2 arguments and returns an integer. The first argument is the input array and the second argument is an int that corresponds to the size of the array. The function returns an integer that corresponds to the university type. The function returns 1 if the student is eligible for First Grade univesity, returns 2 if the student is eligible for Second Grade University, returns 3 if the student is eligible for Third Grade University and returns -1 if the average is greater than 99.
  952.  
  953. If the size of the array is negative or if any element in the array is negative or if the average marks scored by the student is greater than 99 , print “Invalid Input” and terminate the program.
  954.  
  955. Input and Output Format:
  956. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  957. Output consists of a string --- “First Grade University” or “Second Grade University” or “Third Grade University” or “Invalid Input”.
  958. Assume that the maximum size of the array is 20.
  959.  
  960. Sample Input 1:
  961. 5
  962. 92
  963. 87
  964. 78
  965. 74
  966. 80
  967.  
  968. Sample Output 1:
  969. First Grade University
  970.  
  971. Sample Input 2:
  972. -5
  973.  
  974. Sample Output 2:
  975. Invalid Input
  976.  
  977. Sample Input 3:
  978. 5
  979. 23
  980. 2
  981. -5
  982.  
  983. Sample Output 3:
  984. Invalid Input
  985.  
  986.  
  987. #include<stdio.h>
  988. #include<stdlib.h>
  989. int calculateGrade(int[],int);
  990. int main(){
  991. int n=0,input[30],i,flag=0,grade=0;
  992. scanf("%d",&n);
  993. if(n<0){
  994. printf("Invalid Input");
  995. getchar();
  996. getchar();
  997. exit(0);
  998. }
  999. for(i=0;i<n;i++){
  1000. scanf("%d",&input[i]);
  1001. if(input[i]<0)
  1002. flag=1;
  1003. }
  1004. if(flag==1){
  1005. printf("Invalid Input");
  1006. getchar();
  1007. getchar();
  1008. exit(0);
  1009. }
  1010. grade=calculateGrade(input,n);
  1011. if(grade==-1)
  1012. printf("Invalid Input");
  1013. else if(grade==1)
  1014. printf("First Grade University");
  1015. else if(grade==2)
  1016. printf("Second Grade University");
  1017. else if(grade==3)
  1018. printf("Third Grade University");
  1019. else
  1020. ;
  1021. getchar();
  1022. getchar();
  1023. return 0;
  1024. }
  1025.  
  1026. int calculateGrade(int array[],int n){
  1027. int grade=0,i,sum=0,avg=0;
  1028. for(i=0;i<n;i++)
  1029. sum=sum+array[i];
  1030. avg=sum/n;
  1031. if(avg>99)
  1032. grade=-1;
  1033. else if(avg>80)
  1034. grade=1;
  1035. else if(avg>60)
  1036. grade=2;
  1037. else
  1038. grade=3;
  1039. return grade;
  1040. }
  1041. 42.Interchange Array
  1042.  
  1043. Write a program to interchange the first element in the array with the last element in the array. Repeat the process till the middle of the array.
  1044.  
  1045. Include a function named interchangeArray that accepts 2 arguments and its return type is void. The first argument is the input array and the second argument is an int that corresponds to the size of the array.
  1046.  
  1047. If the size of the array is negative or if any element in the array is negative, print “Invalid Input” and terminate the program.
  1048.  
  1049. Input and Output Format:
  1050. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  1051. Output consists of the interchanged array.
  1052. Assume that the maximum number of elements in the array is 20.
  1053.  
  1054. Sample Input 1:
  1055. 4
  1056. 2
  1057. 1
  1058. 3
  1059. 4
  1060.  
  1061. Sample Output 1:
  1062. 4
  1063. 3
  1064. 1
  1065. 2
  1066.  
  1067. Sample Input 2:
  1068. -5
  1069.  
  1070. Sample Output 2:
  1071. Invalid Input
  1072.  
  1073. Sample Input 3:
  1074. 5
  1075. 23
  1076. 2
  1077. -200
  1078.  
  1079. Sample Output 3:
  1080. Invalid Input
  1081.  
  1082.  
  1083. #include<stdio.h>
  1084. #include<stdlib.h>
  1085. void interchangeArray(int[],int);
  1086. int main(){
  1087. int n=0,input[30],i,flag=0;
  1088. scanf("%d",&n);
  1089. if(n<0){
  1090. printf("Invalid Input");
  1091. getchar();
  1092. getchar();
  1093. exit(0);
  1094. }
  1095. for(i=0;i<n;i++){
  1096. scanf("%d",&input[i]);
  1097. if(input[i]<0)
  1098. flag=1;
  1099. }
  1100. if(flag==1){
  1101. printf("Invalid Input");
  1102. getchar();
  1103. getchar();
  1104. exit(0);
  1105. }
  1106. interchangeArray(input,n);
  1107. return 0;
  1108. }
  1109.  
  1110. void interchangeArray(int array[],int n){
  1111. int i=0,temp=0,j;
  1112. for(i=0,j=n-1;i<n/2;i++,j--){
  1113. temp = array[i];
  1114. array[i] = array[j];
  1115. array[j] = temp;
  1116. }
  1117. for(i=0;i<n;i++)
  1118. printf("%d\n",array[i]);
  1119. getchar();
  1120. getchar();
  1121. }
  1122. 43.Armstrong Number
  1123.  
  1124. Write a program to find whether the given input number is an Armstrong Number.
  1125.  
  1126. Include a function named checkArmstrong that accepts an integer and returns an integer. The function returns
  1127. 1. yes if the input is an Armstrong number
  1128. 2. no if the input is not an Arnstrong number
  1129. 3. Invalid Input if the input is a negative number or if the input is not a 3-digit number.
  1130.  
  1131. Print Invalid Input if the function returns -1.
  1132.  
  1133. Input and Output Format:
  1134. Input consists of a single integer.
  1135. Refer sample output for formatting specifications.
  1136.  
  1137.  
  1138. Sample Input 1:
  1139. 153
  1140.  
  1141. Sample Output 1:
  1142. yes
  1143.  
  1144. Sample Input 2:
  1145. 161
  1146.  
  1147. Sample Output 2:
  1148. no
  1149.  
  1150. Sample Input 3:
  1151. 2345
  1152.  
  1153. Sample Output 3:
  1154. Invalid Input
  1155.  
  1156. #include<stdio.h>
  1157. #include<stdlib.h>
  1158. int checkArmstrong(int);
  1159. int main(){
  1160. int number=0,result;
  1161. scanf("%d",&number);
  1162. result = checkArmstrong(number);
  1163. if(result==1)
  1164. printf("yes");
  1165. else if(result==0)
  1166. printf("no");
  1167. else
  1168. printf("Invalid input");
  1169. getchar();
  1170. getchar();
  1171. return 0;
  1172. }
  1173.  
  1174. int checkArmstrong(int n){
  1175. int res=0,temp=0,rem=0,sum=0;
  1176. if(n<0 || n>999)
  1177. res=-1;
  1178. else{
  1179. temp = n;
  1180. while (temp != 0) {
  1181. rem = temp%10;
  1182. sum = sum + (rem*rem*rem);
  1183. temp = temp/10;
  1184. }
  1185. if (n == sum)
  1186. res=1;
  1187. else
  1188. res=0;
  1189. }
  1190. return res;
  1191. }
  1192.  
  1193. 44.Factorial
  1194.  
  1195. Write a program to find the factorial of a given number.
  1196.  
  1197. Include a function named findFactorial that accepts an integer argument and returns an integer that corresponds to factorial. If the input value is negative or greater than 10, the function returns -1.
  1198.  
  1199. If the function returns -1, print Invalid Input.
  1200.  
  1201. Input and Output Format:
  1202. Input consists of a single integer.
  1203. Output consists of an integer.
  1204. Refer sample output for formatting specifications.
  1205.  
  1206.  
  1207. Sample Input 1:
  1208. 4
  1209.  
  1210. Sample Output 1:
  1211. 24
  1212.  
  1213. Sample Input 2:
  1214. -67
  1215.  
  1216. Sample Output 2:
  1217. Invalid Input
  1218.  
  1219.  
  1220. #include<stdio.h>
  1221. #include<stdlib.h>
  1222. int findFactorial(int);
  1223. int main(){
  1224. int number=0,result;
  1225. scanf("%d",&number);
  1226. result = findFactorial(number);
  1227. if(result==-1)
  1228. printf("Invalid input");
  1229. else
  1230. printf("%d",result);
  1231. getchar();
  1232. getchar();
  1233. return 0;
  1234. }
  1235.  
  1236. int findFactorial(int n){
  1237. int res=1,i;
  1238. if(n<0 && n>10)
  1239. res=-1;
  1240. else{
  1241. for(i=1;i<=n;i++)
  1242. res = res * i;
  1243. }
  1244. return res;
  1245. }
  1246. 45.Salary Calculation
  1247. Jim got his salary. His salary calculations are as follows.
  1248. From his Basic amount he gets 50% of his basic for house Rent allowances and 75% of his basic as special allowances . If the number of days he worked is 31 he gets 500 extra. Write a program to calculate his gross salary after calculating all his salary split up.
  1249.  
  1250. Include a function named calculateGross that accepts 2 integer arguments and returns a float. The first integer corresponds to Jim's basic salary and the second integer corresponds to the number of days Jim has worked. The function returns a float that corresponds to the gross salary.
  1251.  
  1252. Print Invalid Input and terminate the program in the following cases:
  1253. 1. Basic salary is greater than 10000
  1254. 2. Number of working days is greater than 31
  1255. 3. Basic salary is negative
  1256. 4. Number of working days is 0 or negative
  1257.  
  1258. Input and Output Format:
  1259. Input consists of 2 integers. The first integer corresponds to Jim's basic salary and the second integer corresponds to the number of days he has worked.
  1260. Output consists of a single float that corresponds to Jim's gross salary. The gross salary is displayed correct to 2 decimal places.
  1261.  
  1262. Sample Input 1:
  1263. 5000
  1264. 30
  1265.  
  1266. Sample Output 1:
  1267. 11250 .00
  1268.  
  1269.  
  1270. Sample Input 2:
  1271. 5000
  1272. 0
  1273.  
  1274. Sample Output 2:
  1275. Invalid Input
  1276.  
  1277. #include<stdio.h>
  1278. #include<stdlib.h>
  1279. float calculateGross(int,int);
  1280. int main(){
  1281. int basic=0,days=0;
  1282. float gross=0.0f;
  1283. scanf("%d%d",&basic,&days);
  1284. if(basic>10000 || days>31 || basic<0 || days==0 || days<0){
  1285. printf("Invalid input");
  1286. getchar();
  1287. getchar();
  1288. exit(0);
  1289. }
  1290. gross = calculateGross(basic,days);
  1291. printf("%0.2f",gross);
  1292. getchar();
  1293. getchar();
  1294. return 0;
  1295. }
  1296.  
  1297. float calculateGross(int basic,int days){
  1298. float salary=0.0f;
  1299. if(days==31)
  1300. salary=(float)(basic*50)/100+(float)(basic*75)/100+basic+500;
  1301. else
  1302. salary=(float)(basic*50)/100+(float)(basic*75)/100+basic;
  1303. return salary;
  1304. }
  1305. 46.Perfect Square
  1306.  
  1307. Write a program to find whether the given input number is a perfect square without using sqrt function.
  1308.  
  1309. Include a function named checkPerfectSquare that accepts an integer and returns an integer. The function returns
  1310. 1. 1 if the input is a perfect square
  1311. 2. 0 if the input is not a perfect square
  1312. 3. -1 if the input is a negative number
  1313.  
  1314. Print Invalid Input if the function returns -1.
  1315.  
  1316. Input and Output Format:
  1317. Input consists of a single integer.
  1318. Refer sample output for formatting specifications.
  1319.  
  1320.  
  1321. Sample Input 1:
  1322. 36
  1323.  
  1324. Sample Output 1:
  1325. yes
  1326.  
  1327. Sample Input 2:
  1328. 40
  1329.  
  1330. Sample Output 2:
  1331. no
  1332.  
  1333. Sample Input 3:
  1334. -2345
  1335.  
  1336. Sample Output 3:
  1337. Invalid Input
  1338.  
  1339.  
  1340. #include<stdio.h>
  1341. #include<stdlib.h>
  1342. int checkPerfectSquare(int);
  1343. int main(){
  1344. int number=0,res=0;
  1345. scanf("%d",&number);
  1346. res = checkPerfectSquare(number);
  1347. if(res==1)
  1348. printf("yes");
  1349. else if(res==0)
  1350. printf("no");
  1351. else
  1352. printf("invalid Input");
  1353. getchar();
  1354. getchar();
  1355. return 0;
  1356. }
  1357.  
  1358. int checkPerfectSquare(int n){
  1359. if(n<0)
  1360. return -1;
  1361. else{
  1362. while (((n % 2) == 0) && n > 1)
  1363. n /= 2;
  1364. return (n == 1);
  1365. }
  1366. }
  1367. 47.Find Index
  1368.  
  1369. Write a program to find the index of a particular number in a given input array.
  1370.  
  1371. Include a function named findIndex that accepts 3 arguments and returns an int. The first argument is the input array, the second argument is an int that corresponds to the size of the array and the third argument is the element to be searched for. The function returns the corresponding index if the search element is present in the array and returns -1 if the search element is not present in the array.
  1372.  
  1373. If the size of the array is negative or if any element in the array is negative, print “Invalid Input” and terminate the program.
  1374.  
  1375.  
  1376. Input and Output Format:
  1377. Input consists of n+2 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array. The last integer corresponds to the element whose count needs to be found.
  1378. Output consists of an integer that corresponds to the index of the search element if it is present.
  1379. Else, print 'not found'.
  1380.  
  1381. Refer sample output for formatting specifications.
  1382.  
  1383. Assume that the maximum number of elements in the array is 20 and that all elements in the array are unique.
  1384.  
  1385. Sample Input 1:
  1386. 8
  1387. 2
  1388. 1
  1389. 3
  1390. 8
  1391. 6
  1392. 12
  1393. 10
  1394. 19
  1395. 8
  1396.  
  1397. Sample Output 1:
  1398. 3
  1399.  
  1400. Sample Input 2:
  1401. 8
  1402. 2
  1403. 1
  1404. 3
  1405. 8
  1406. 6
  1407. 12
  1408. 10
  1409. 19
  1410. 80
  1411.  
  1412. Sample Output 2:
  1413. not found
  1414.  
  1415. Sample Input 3:
  1416. -5
  1417.  
  1418. Sample Output 3:
  1419. Invalid Input
  1420.  
  1421. Sample Input 4:
  1422. 5
  1423. 23
  1424. 2
  1425. -200
  1426.  
  1427. Sample Output 4:
  1428. Invalid Input
  1429.  
  1430. #include<stdio.h>
  1431. #include<stdlib.h>
  1432. int cricketer[20];
  1433. int findIndex(int,int[],int);
  1434. int main(){
  1435. int n=0,index=0,input[30],i,search_element=0;
  1436. scanf("%d",&n);
  1437. if(n<0){
  1438. printf("Invalid Input");
  1439. getchar();
  1440. getchar();
  1441. exit(0);
  1442. }
  1443. for(i=0;i<n;i++){
  1444. scanf("%d",&input[i]);
  1445. if(input[i]<0){
  1446. printf("Invalid Input");
  1447. getchar();
  1448. getchar();
  1449. exit(0);
  1450. }
  1451. }
  1452. scanf("%d",&search_element);
  1453. index = findIndex(n,input,search_element);
  1454. if(index==-1)
  1455. printf("not found");
  1456. else
  1457. printf("%d",index);
  1458. getchar();
  1459. getchar();
  1460. return 0;
  1461. }
  1462. int findIndex( int size,int array[], int search){
  1463. int index,i,f=0;
  1464. for(i=1 ; i<size ; i=i+2)
  1465. {
  1466. if(array[i]==search){
  1467. f=1;
  1468. index = array[i-1];
  1469. break;
  1470. }
  1471. }
  1472. if(f==1)
  1473. return index;
  1474. else
  1475. return -1;
  1476. }
  1477. 48.Descending Order Sort
  1478.  
  1479. Write a program to sort the given array in descending order.
  1480.  
  1481. Include a function named sortArray that accepts 2 arguments and its return type is void. The first argument is the input array and the second argument is an int that corresponds to the size of the array .
  1482.  
  1483. If the size of the array is negative or if any of the elements in the array are negative , print “Invalid Input” and terminate the program.
  1484.  
  1485. Input and Output Format:
  1486. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  1487. Output consists of an integer array.
  1488. Refer sample output for formatting specifications.
  1489.  
  1490. Assume that the maximum number of elements in the array is 20.
  1491.  
  1492. Sample Input 1:
  1493. 8
  1494. 1
  1495. 6
  1496. 3
  1497. 5
  1498. 8
  1499. 10
  1500. 4
  1501. 9
  1502.  
  1503.  
  1504. Sample Output 1:
  1505. 10
  1506. 9
  1507. 8
  1508. 6
  1509. 5
  1510. 4
  1511. 3
  1512. 1
  1513.  
  1514. Sample Input 2:
  1515. -5
  1516.  
  1517. Sample Output 2:
  1518. Invalid Input
  1519.  
  1520. #include<stdio.h>
  1521. #include<stdlib.h>
  1522.  
  1523. void sortArray(int numbers[], int size);
  1524. int main(){
  1525. int n=0,input[20],i;
  1526. scanf("%d",&n);
  1527. if(n<0){
  1528. printf("Invalid input");
  1529. getchar();
  1530. getchar();
  1531. exit(0);
  1532. }
  1533. for(i=0;i<n;i++){
  1534. scanf("%d",&input[i]);
  1535. if(input[i]<0){
  1536. printf("Invalid Input");
  1537. getchar();
  1538. getchar();
  1539. exit(0);
  1540. }
  1541. }
  1542.  
  1543. sortArray(input,n);
  1544. return 0;
  1545. }
  1546. void sortArray(int numbers[], int size){
  1547. int i,j,temp=0;
  1548. for(i=0 ; i<size ; i++){
  1549. for(j=i+1 ; j<size ; j++){
  1550. if(numbers[i]<numbers[j]){
  1551. temp = numbers[i];
  1552. numbers[i] = numbers[j];
  1553. numbers[j] = temp;
  1554. }
  1555. }
  1556. }
  1557. for(i=0 ; i<size ; i++)
  1558. printf("%d\n",numbers[i]);
  1559. getchar();
  1560. getchar();
  1561.  
  1562. }
  1563. 49.endWithThree
  1564.  
  1565. Read the question carefully and follow the input and output format.
  1566.  
  1567. Given an input array, Find out the count of numbers that ends with 3.
  1568.  
  1569. Input and Output Format :
  1570. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of the count of numbers that ends with 3.
  1571.  
  1572. Print "Invalid array size" when size of the array is a negative number and terminate the program
  1573. Print "Invalid input" when there is any negative number available in the input array and terminate the program.
  1574.  
  1575. Include a function named endWithThree(int numbers[], int size) whose return type is integer.
  1576.  
  1577. Sample Input 1:
  1578. 5
  1579. 23
  1580. 353
  1581. 33
  1582. 12
  1583. 14
  1584. Sample Output 1:
  1585. 3
  1586.  
  1587. Sample Input 2:
  1588. 5
  1589. 1
  1590. 7
  1591. 3
  1592. -8
  1593. Sample Output 2:
  1594. Invalid input
  1595.  
  1596. #include<stdio.h>
  1597. #include<stdlib.h>
  1598.  
  1599. int endWithThree(int numbers[], int size);
  1600. int main(){
  1601. int n=0,input[20],i,count=0;
  1602. scanf("%d",&n);
  1603. if(n<0){
  1604. printf("Invalid array size");
  1605. getchar();
  1606. getchar();
  1607. exit(0);
  1608. }
  1609. for(i=0;i<n;i++){
  1610. scanf("%d",&input[i]);
  1611. if(input[i]<0){
  1612. printf("Invalid Input");
  1613. getchar();
  1614. getchar();
  1615. exit(0);
  1616. }
  1617. }
  1618.  
  1619. count = endWithThree(input,n);
  1620. printf("%d",count);
  1621. getchar();
  1622. getchar();
  1623. return 0;
  1624. }
  1625. int endWithThree(int numbers[], int size){
  1626. int count=0,i,temp,rem=0;
  1627. for(i=0 ; i<size ; i++){
  1628. temp = numbers[i];
  1629. rem = temp%10;
  1630. if(rem==3)
  1631. count++;
  1632. }
  1633. return count;
  1634.  
  1635. }
  1636. 50.feeCalculation
  1637. Read the question carefully and follow the input and output format.
  1638.  
  1639. Student Fees is calculated according to the student's 10th marks. The student will get discount in fees as follows :
  1640.  
  1641. Marks discount(%)
  1642. >90 - 50%
  1643. 81-90 - 25%
  1644. 70-80 - 10%
  1645. <70 - 0%
  1646. Calculate the fees according to above table.
  1647.  
  1648. Note:
  1649. Formula : fees - (fees* discount(%))
  1650.  
  1651. Include a function named feeCalculation(int fee,int marks) that returns an integer that corresponds to the fee to be paid.
  1652.  
  1653.  
  1654. Print "Invalid mark" if the mark is greater than 100
  1655. Print "Invalid fee" if the fee is greater than 32767
  1656. Print "Invalid input" if any of the input is negative
  1657.  
  1658. Input and Output Format :
  1659. First line of input represents the fee, second line of input represents the marks of student.
  1660.  
  1661. Sample Input 1:
  1662. 10000
  1663. 95
  1664. Sample Output 1:
  1665. 5000
  1666.  
  1667. Sample Input 2:
  1668. 15896
  1669. 101
  1670. Sample Output 2:
  1671. Invalid mark
  1672.  
  1673. #include<stdio.h>
  1674. #include<stdlib.h>
  1675.  
  1676. int feeCalculation(int fee,int marks);
  1677. int main(){
  1678. int fees,mark,final_fee=0;
  1679. scanf("%d",&fees);
  1680. scanf("%d",&mark);
  1681. if(mark>100)
  1682. printf("Invalid mark");
  1683. else if(fees>32767)
  1684. printf("Invalid fees");
  1685. else if(mark<0 || fees<0)
  1686. printf("Invalid input");
  1687. else{
  1688. final_fee = feeCalculation(fees,mark);
  1689. printf("%d",final_fee);
  1690. }
  1691. getchar();
  1692. getchar();
  1693. return 0;
  1694. }
  1695. int feeCalculation(int fee,int marks){
  1696. int fee_final=0;
  1697. float discount=0.0f;
  1698. if(marks>90)
  1699. discount = .50;
  1700. else if(marks>80 && marks<=90)
  1701. discount = .25;
  1702. else if(marks>=70 && marks<=80)
  1703. discount = .10;
  1704. else
  1705. discount = 0;
  1706. fee_final = fee-(fee*discount);
  1707. return fee_final;
  1708. }
  1709. 51.sumTwoFive
  1710. Read the question carefully and follow the input and output format.
  1711.  
  1712. Given an integer array find the sum of elements which end with 2 or 5.
  1713.  
  1714. Input and Output Format:
  1715. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of an integer, the sum.
  1716.  
  1717. 1) Print "Invalid array size" when size of the array is negative .
  1718. 2) Print "Invalid input" when there is any negative number available in the input array and terminate the program.
  1719.  
  1720. Include a function named sumTwoFive(int array[], int size) whose return type is an integer, the sum
  1721.  
  1722. Sample Input 1:
  1723. 5
  1724. 22
  1725. 35
  1726. 5
  1727. 2
  1728. 10
  1729.  
  1730. Sample Output 1:
  1731. 64
  1732.  
  1733. Sample Input 2:
  1734. -6
  1735.  
  1736. Sample Output 2:
  1737. Invalid array size
  1738.  
  1739.  
  1740. #include<stdio.h>
  1741. #include<stdlib.h>
  1742.  
  1743. int sumTwoFive(int array[], int size);
  1744. int main(){
  1745. int n=0,input[20],i,sum=0;
  1746. scanf("%d",&n);
  1747. if(n<0){
  1748. printf("Invalid array size");
  1749. getchar();
  1750. getchar();
  1751. exit(0);
  1752. }
  1753. for(i=0;i<n;i++){
  1754. scanf("%d",&input[i]);
  1755. if(input[i]<0){
  1756. printf("Invalid Input");
  1757. getchar();
  1758. getchar();
  1759. exit(0);
  1760. }
  1761. }
  1762.  
  1763. sum = sumTwoFive(input,n);
  1764. printf("%d",sum);
  1765. getchar();
  1766. getchar();
  1767. return 0;
  1768. }
  1769. int sumTwoFive(int array[], int size){
  1770. int i,rem,temp,sum=0;
  1771. for(i=0;i<size;i++){
  1772. temp = array[i];
  1773. rem = temp % 10;
  1774. if(rem==2 || rem==5)
  1775. sum = sum+array[i];
  1776. }
  1777. return sum;
  1778. }
  1779. 52.Sum of Odd Digits
  1780.  
  1781. Write a program to find the sum of the odd digits in a number.
  1782.  
  1783. Include a function named sumOddDigits that accepts an integer argument and returns an integer that corresponds to the sum of the odd digits. The function returns -1 if the input is less than zero or if it is greater than 32767.
  1784.  
  1785. If the function returns -1, print “Invalid Input”.
  1786.  
  1787. Input and Output Format:
  1788.  
  1789. The input consists of an integer.
  1790. The output consists of an integer that corresponds to the sum of the odd digits in the number.
  1791.  
  1792. Sample Input 1:
  1793. 3487
  1794.  
  1795. Sample Ouput 1:
  1796. 10
  1797.  
  1798. Sample Input 2:
  1799. -8
  1800.  
  1801. Sample Output 2:
  1802. Invalid Input
  1803.  
  1804. #include<stdio.h>
  1805. #include<stdlib.h>
  1806. int sumOddDigits(int);
  1807. int main(){
  1808. int num=0,res=0;
  1809. scanf("%d",&num);
  1810. res = sumOddDigits(num);
  1811. if(res==-1)
  1812. printf("Invalid input");
  1813. else
  1814. printf("%d",res);
  1815. getchar();
  1816. getchar();
  1817. return 0;
  1818. }
  1819. int sumOddDigits(int number){
  1820. int sum=0,rem=0;
  1821. if(number<0 || number>32767)
  1822. sum=-1;
  1823. else{
  1824. while(number!=0){
  1825. rem=number%10;
  1826. if(rem%2!=0)
  1827. sum=sum+rem;
  1828. number=number/10;
  1829. }
  1830. }
  1831. return sum;
  1832. }
  1833.  
  1834.  
  1835. 53.LCM
  1836.  
  1837. Write a program to calculate the LCM of the 2 given integers.
  1838.  
  1839. Include a function named calculateLCM that accepts 2 integer arguments and returns an int that corresponds to the LCM of the 2 numbers.
  1840.  
  1841. Print Invalid Input and terminate the program in the following cases:
  1842. 1. Any of the 2 inputs is greater than 1000
  1843. 2. Any of the 2 inputs is negative
  1844.  
  1845.  
  1846. Input and Output Format:
  1847. Input consists of 2 integers.
  1848. Output consists of a single integer that corresponds to the LCM.
  1849.  
  1850. Sample Input 1:
  1851. 10
  1852. 8
  1853.  
  1854. Sample Output 1:
  1855. 40
  1856.  
  1857.  
  1858. Sample Input 2:
  1859. 50000
  1860.  
  1861.  
  1862. Sample Output 2:
  1863. Invalid Input
  1864.  
  1865. #include<stdio.h>
  1866. #include<stdlib.h>
  1867. #include<string>
  1868. int calculateLCM(int,int);
  1869. int main(){
  1870. int a,b,res=0;
  1871. scanf("%d%d",&a,&b);
  1872. if(a>1000 || b>1000 || a<0 || b<0)
  1873. {
  1874. printf("Invalid input");
  1875. exit(0);
  1876. getchar();
  1877. getchar();
  1878.  
  1879. }
  1880. res=calculateLCM(a,b);
  1881. printf("%d",res);
  1882. getchar();
  1883. getchar();
  1884. return 0;
  1885. }
  1886. int calculateLCM(int num1,int num2){
  1887. int max=0;
  1888. max=(num1>num2) ? num1 : num2;
  1889. while(1){
  1890. if(max%num1==0 && max%num2==0){
  1891. break;
  1892. }
  1893. ++max;
  1894. }
  1895.  
  1896. return max;
  1897. }
  1898.  
  1899.  
  1900. 54.Product of Prime Digits
  1901.  
  1902. Write a program to find the product of the prime digits in the given input number.
  1903.  
  1904. Include a function named productPrimeDigits that accepts an integer argument and returns an integer that corresponds to the product of the prime digits in the integer.
  1905. The function returns -1 if the input number is negative or greater than 32767.
  1906.  
  1907. If the function returns -1, print Invalid Input.
  1908.  
  1909. Please note that 1 and 0 are neiher prime nor composite.
  1910.  
  1911. Input and Output Format:
  1912. Input consists of an integer.
  1913. Output consists of an integer.
  1914. Refer sample output for formatting specifications.
  1915.  
  1916.  
  1917. Sample Input 1:
  1918. 324
  1919.  
  1920.  
  1921. Sample Output 1:
  1922. 6
  1923.  
  1924. Sample Input 2:
  1925. -67
  1926.  
  1927. Sample Output 2:
  1928. Invalid Input
  1929.  
  1930.  
  1931. #include<stdio.h>
  1932. #include<stdlib.h>
  1933. #include<string>
  1934. int productPrimeDigits(int);
  1935. int main(){
  1936. int digit=0,product=0;
  1937. scanf("%d",&digit);
  1938. product=productPrimeDigits(digit);
  1939. if(product==-1)
  1940. printf("Invalid input");
  1941. else
  1942. printf("%d",product);
  1943. getchar();
  1944. getchar();
  1945. return 0;
  1946. }
  1947. int productPrimeDigits(int number){
  1948. int prod=1,rem=0,i,count=0,flag=0;
  1949. if(number<0 || number>32767)
  1950. prod = -1;
  1951. else
  1952. {
  1953. while(number!=0){
  1954. rem=number%10;
  1955. count=0;
  1956. for(i=1;i<=rem;i++){
  1957. if(rem%i==0)
  1958. count++;
  1959. }
  1960. if(count==2){
  1961. flag=1;
  1962. prod = prod*rem;
  1963. }
  1964. number=number/10;
  1965. }
  1966. if(flag==0)
  1967. prod = 0;
  1968. }
  1969. return prod;
  1970. }
  1971.  
  1972. 55.dailyAllowance
  1973. Read the question carefully and follow the input and output format.
  1974.  
  1975. A Sales person daily allowances calculated as follows .
  1976. Item Money (rupees)
  1977. Shirt 15
  1978. Saree 10
  1979. other items 5
  1980.  
  1981. Given an input array in which the first index represents no.of shirts sold, second index represents the no of sarees sold and the third index represents the other items sold for a particular day, Calculate the total allowances.
  1982.  
  1983. Inlcude a function named dailyAllowance(int items[], int size) that returns an integer, which is the total allowances.
  1984.  
  1985. Business Rules:
  1986. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program
  1987. 2) Print "Invalid item count" when there is any negative numbers available in the input array and terminate the program
  1988. 3) Print "Array size greater than 3" when size of the array is greater than 3 and terminate the program.
  1989.  
  1990. Input and Output Format :
  1991. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of the total allowance.
  1992.  
  1993. Sample Input 1:
  1994. 3
  1995. 10
  1996. 5
  1997. 10
  1998. Sample Output 1:
  1999. 250
  2000.  
  2001. Sample Input 2:
  2002. 4
  2003.  
  2004. Sample Output 2:
  2005. Array size greater than 3
  2006. #include<stdio.h>
  2007. #include<stdlib.h>
  2008.  
  2009. int dailyAllowance(int items[], int size);
  2010. int main(){
  2011. int n=0,input[20],i,allowance=0;
  2012. scanf("%d",&n);
  2013. if(n<0){
  2014. printf("Invalid array size");
  2015. getchar();
  2016. getchar();
  2017. exit(0);
  2018. }
  2019. if(n>3){
  2020. printf("Array size greater than 3");
  2021. getchar();
  2022. getchar();
  2023. exit(0);
  2024. }
  2025. for(i=0;i<n;i++){
  2026. scanf("%d",&input[i]);
  2027. if(input[i]<0){
  2028. printf("Invalid item count");
  2029. getchar();
  2030. getchar();
  2031. exit(0);
  2032. }
  2033. }
  2034.  
  2035.  
  2036.  
  2037. allowance = dailyAllowance(input,n);
  2038. printf("%d",allowance);
  2039. getchar();
  2040. getchar();
  2041. return 0;
  2042. }
  2043. int dailyAllowance(int items[], int size){
  2044. int shirt=15,saree=10,other=5,allowance=0;
  2045. allowance = (items[0]*shirt) + (items[1]*saree) + (items[2]*other);
  2046. return allowance;
  2047. }
  2048. 56.generateNumber
  2049.  
  2050.  
  2051. Read the question carefully and follow the input and output format.
  2052.  
  2053. Given an input number keep the prime digits as it is and the remaining digit in given input number should be replaced with next number(add +1 to the digit).
  2054.  
  2055. Print "Number too small" if the number is less than 0
  2056. Print "Number too large" if the number is greater than 32767
  2057. note : If any digit in the given input is 9 replace with 0. Consider 1 is not a prime number.
  2058.  
  2059. Include a function generateNumber(int number) that returns the generated number
  2060.  
  2061. Input and Output Format :
  2062. Input is a single integer.
  2063. Output is the generated number
  2064.  
  2065. Sample Input 1:
  2066. 6234
  2067.  
  2068. Sample Output 1:
  2069. 7235
  2070.  
  2071. Sample Input 2:
  2072. 32768
  2073.  
  2074. Sample Output 2:
  2075. Number too large
  2076. #include<stdio.h>
  2077. #include<stdlib.h>
  2078.  
  2079. int generateNumber(int number);
  2080. int main(){
  2081. int num=0,res=0;
  2082. scanf("%d",&num);
  2083. if(num<0)
  2084. printf("number too small");
  2085. else if(num>32767)
  2086. printf("number too large");
  2087. else
  2088. {
  2089. res = generateNumber(num);
  2090. printf("%d",res);
  2091. }
  2092. getchar();
  2093. getchar();
  2094. return 0;
  2095. }
  2096. int generateNumber(int number){
  2097. int rem=0,res=0,i=1;
  2098. while(number!=0){
  2099. rem=number%10;
  2100. if(rem==2 || rem==3 || rem==5 || rem==7){
  2101. res=res+(rem*i);
  2102. i=i*10;
  2103. }
  2104. else if(rem==9){
  2105. res=res+0;
  2106. i=i*10;
  2107. }
  2108. else{
  2109. res=res+((rem+1)*i);
  2110. i=i*10;
  2111. }
  2112. number = number/10;
  2113. }
  2114. return res;
  2115. }
  2116. 57.sortCommonElements
  2117.  
  2118. Read the question carefully and follow the input and output format.
  2119.  
  2120. Find out the common elements in the given input arrays and sort the common elements in ascending order.
  2121.  
  2122. Input and Output Format :
  2123. First line corresponds to n, the size of the array. The next n lines correspond to elements in the first array. The next n lines correspond to the elements in the second array. Output corresponds to the common elements sorted in ascending order.
  2124.  
  2125. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program
  2126. 2) Print "Invalid input" when there is any negative number available in the input array and terminate the program
  2127.  
  2128. Include a function named sortCommonElements(int set1[],int set2[],int size) whose return type is void.
  2129. The output array is stored in a global variable named common.
  2130.  
  2131. Sample Input 1:
  2132. 5
  2133. 1
  2134. 3
  2135. 2
  2136. 5
  2137. 7
  2138. 4
  2139. 5
  2140. 6
  2141. 7
  2142. 2
  2143.  
  2144. Sample Output 1:
  2145. 2
  2146. 5
  2147. 7
  2148.  
  2149. Sample Input 2:
  2150. 5
  2151. 5
  2152. 8
  2153. -9
  2154.  
  2155. Sample Output 2:
  2156. Invalid input
  2157.  
  2158. Sample Input 3:
  2159. -4
  2160.  
  2161. Sample Output 3:
  2162. Invalid array size
  2163. #include<stdio.h>
  2164. #include<stdlib.h>
  2165. int common[20];
  2166. void sortCommonElements(int set1[],int set2[],int size);
  2167. int main(){
  2168. int size=0,input1[20],input2[20],i=0;
  2169. scanf("%d",&size);
  2170. if(size<0){
  2171. printf("Invalid Input");
  2172. getchar();
  2173. getchar();
  2174. exit(0);
  2175. }
  2176. for(i=0;i<size;i++){
  2177. scanf("%d",&input1[i]);
  2178. if(input1[i]<0){
  2179. printf("Invalid Input");
  2180. getchar();
  2181. getchar();
  2182. exit(0);
  2183. }
  2184. }
  2185. for(i=0;i<size;i++){
  2186. scanf("%d",&input2[i]);
  2187. if(input2[i]<0){
  2188. printf("Invalid Input");
  2189. getchar();
  2190. getchar();
  2191. exit(0);
  2192. }
  2193. }
  2194. sortCommonElements(input1,input2,size);
  2195. return 0;
  2196. }
  2197. void sortCommonElements(int set1[],int set2[],int size){
  2198. int i=0,j=0,k=0,temp=0;
  2199. for(i=0;i<size;i++){
  2200. for(j=0;j<size;j++){
  2201. if(set1[i]==set2[j]){
  2202. common[k]=set1[i];
  2203. k++;
  2204. }
  2205. }
  2206. }
  2207. /* Sorting elements */
  2208. for(i=0;i<k;i++){
  2209. for(j=i+1;j<k;j++){
  2210. if(common[i]>common[j]){
  2211. temp = common[i];
  2212. common[i] = common[j];
  2213. common[j] = temp;
  2214. }
  2215. }
  2216. }
  2217. for(i=0;i<k;i++)
  2218. printf("%d\n",common[i]);
  2219. getchar();
  2220. getchar();
  2221. }
  2222. 58.findEmployeeID
  2223. Read the question carefully and follow the input and output format.
  2224.  
  2225. In a given input array, elements are given in this Format PPPII, where PPP represents the Project Code and II represents employee id . Find out the Employee Ids who are working in the given project code.
  2226.  
  2227. Input and Output Format :
  2228. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. The next line corresponds to the project code. Output consists of the employee id's.
  2229.  
  2230. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program
  2231. 2) Print "Invalid employee id" when there is any negative numbers available in the input array and terminate the program
  2232. 3) Print "Invalid project code" when branch code is negative number and terminate the program
  2233.  
  2234. Include a function named findEmployeeID(int size,int employee_ids[],int project_code). Its return type is void.
  2235. The output array is stored in a global variable named working_employee.
  2236.  
  2237. Sample Input 1:
  2238. 5
  2239. 12345
  2240. 12334
  2241. 23457
  2242. 23478
  2243. 12546
  2244. 123
  2245. Sample Output 1:
  2246. 45
  2247. 34
  2248.  
  2249. Sample Input 2:
  2250. 5
  2251. 12345
  2252. 12334
  2253. 23457
  2254. -23478
  2255. Sample Output 2:
  2256. Invalid employee id
  2257. #include<stdio.h>
  2258. #include<stdlib.h>
  2259. int working_employee[10];
  2260. void findEmployeeID(int size,int employee_ids[],int project_code);
  2261. int main(){
  2262. int n=0,input[30],i,pcode=0;
  2263. scanf("%d",&n);
  2264. if(n<0){
  2265. printf("Invalid array size");
  2266. getchar();
  2267. getchar();
  2268. exit(0);
  2269. }
  2270. for(i=0;i<n;i++){
  2271. scanf("%d",&input[i]);
  2272. if(input[i]<0){
  2273. printf("Invalid employee id");
  2274. getchar();
  2275. getchar();
  2276. exit(0);
  2277. }
  2278.  
  2279. }
  2280. scanf("%d",&pcode);
  2281. if(pcode<0){
  2282. printf("Invalid project code");
  2283. getchar();
  2284. getchar();
  2285. exit(0);
  2286. }
  2287. findEmployeeID(n,input,pcode);
  2288.  
  2289. return 0;
  2290. }
  2291. void findEmployeeID(int size,int employee_ids[],int project_code){
  2292. int count=0,i,rem,temp=0,k=1,pcode=0,x=1,num=0,var=1;
  2293. for(i=0;i<size;i++){
  2294. temp=employee_ids[i];
  2295. pcode=temp/100;
  2296.  
  2297. if(pcode==project_code){
  2298. working_employee[count]=employee_ids[i]%100;
  2299. count++;
  2300. }
  2301. }
  2302. for(i=0;i<count;i++)
  2303. printf("%d\n",working_employee[i]);
  2304. getchar();
  2305. getchar();
  2306. }
  2307. 59.Array Addition in Reverse
  2308.  
  2309. In an export company, the clothes are stored in boxes and are shipped in three different ships. Each box has a number on it. The boxes are stored in ships in specific pattern as below:
  2310. 1. First box number in Ship1 + Last box number in Ship2 = first box number in Ship3.
  2311. 2. Second box number in Ship1 + Second Last box number in Ship2 = Second box number in ship3.
  2312. Similarly all the boxes are numbered in ship3. Assuming the count of boxes in each ship is equal, find the box numbers in ship3.
  2313.  
  2314. Include a function named arrayAddition that accepts 3 arguments and its return type is void. The first argument is the input array 1, the second argument is the input array 2 and the third argument is an int that corresponds to the size of the array. The output is stored in an array variable named output1.
  2315.  
  2316. If the size of the array (the number of boxes) is negative or if any element in any of the array is negative , print “Invalid Input” and terminate the program.
  2317.  
  2318. Input and Output Format:
  2319. Input consists of utmost 2n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the first array(i.e box numbers in ship 1). The last 'n' integers correspond to the elements in the second array (i.e box numbers in ship 2). If any of the inputs are invalid, then terminate the program.
  2320.  
  2321. Output consists of n integers that correspond to the box numbers in ship 3.
  2322.  
  2323. Assume that the maximum size of the array is 20.
  2324.  
  2325. Sample Input 1 :
  2326. 5
  2327. 23
  2328. 2
  2329. 5
  2330. 32
  2331. 76
  2332. 2
  2333. 9
  2334. 21
  2335. 42
  2336. 4
  2337.  
  2338. Sample Output 1 :
  2339. 27
  2340. 44
  2341. 26
  2342. 41
  2343. 78
  2344.  
  2345. Sample Input 2:
  2346. -5
  2347.  
  2348. Sample Output 2:
  2349. Invalid Input
  2350.  
  2351. Sample Input 3:
  2352. 5
  2353. 23
  2354. 2
  2355. -5
  2356.  
  2357. Sample Output 3:
  2358. Invalid Input
  2359.  
  2360. #include<stdio.h>
  2361. #include<stdlib.h>
  2362. int output1[20];
  2363. void arrayAddition(int[],int[],int);
  2364. int main(){
  2365. int size=0,input1[20],input2[20],i=0;
  2366. scanf("%d",&size);
  2367. if(size<0){
  2368. printf("Invalid Input");
  2369. getchar();
  2370. getchar();
  2371. exit(0);
  2372. }
  2373. for(i=0;i<size;i++){
  2374. scanf("%d",&input1[i]);
  2375. if(input1[i]<0){
  2376. printf("Invalid Input");
  2377. getchar();
  2378. getchar();
  2379. exit(0);
  2380. }
  2381. }
  2382. for(i=0;i<size;i++){
  2383. scanf("%d",&input2[i]);
  2384. if(input2[i]<0){
  2385. printf("Invalid Input");
  2386. getchar();
  2387. getchar();
  2388. exit(0);
  2389. }
  2390. }
  2391. arrayAddition(input1,input2,size);
  2392.  
  2393. return 0;
  2394. }
  2395. void arrayAddition(int ar1[],int ar2[],int size){
  2396. int i=0,j=0,k=0;
  2397. for(i=0,j=size-1;i<size&&j>=0;i++,j--){
  2398. output1[i] = ar1[i]+ar2[j];
  2399. printf("%d\n",output1[i]);
  2400. }
  2401. getchar();
  2402. getchar();
  2403. }
  2404. 60.adjecentDifference
  2405. Read the question carefully and follow the input and output format.
  2406.  
  2407. Given an input Integer array, find the difference in the adjacent elements and print the largest difference
  2408.  
  2409. Input and Output Format :
  2410. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of largest adjacent difference.
  2411.  
  2412. Print "Invalid array size" when size of the array is a negative number and terminate the program
  2413. Print "Invalid input" when there is any negative number available in the input array and terminate the program.
  2414.  
  2415. Include a function named adjecentDifference(int numbers[], int size) whose return type is an integer
  2416.  
  2417. Sample Input 1:
  2418. 7
  2419. 2
  2420. 4
  2421. 5
  2422. 1
  2423. 9
  2424. 3
  2425. 8
  2426. Sample Output 1:
  2427. 8
  2428.  
  2429. Hint: The AdjecentElement Diff are :2,1,4,8,6,5 and Maximum diff is 8 which is obtained by 2-4 =2, 4-5=1,5- 1 =4, 1-9=8,9-3=6,3-8 =5
  2430.  
  2431. Sample Input 2:
  2432. 5
  2433. 1
  2434. 7
  2435. 3
  2436. -8
  2437. Sample Output 2:
  2438. Invalid input
  2439. #include<stdio.h>
  2440. #include<stdlib.h>
  2441. int output1[20];
  2442. int adjecentDifference(int numbers[], int size);
  2443. int main(){
  2444. int size=0,input1[20],i=0,diff=0;
  2445. scanf("%d",&size);
  2446. if(size<0){
  2447. printf("Invalid array size");
  2448. getchar();
  2449. getchar();
  2450. exit(0);
  2451. }
  2452. for(i=0;i<size;i++){
  2453. scanf("%d",&input1[i]);
  2454. if(input1[i]<0){
  2455. printf("Invalid Input");
  2456. getchar();
  2457. getchar();
  2458. exit(0);
  2459. }
  2460. }
  2461. diff = adjecentDifference(input1,size);
  2462. printf("%d",diff);
  2463. getchar();
  2464. getchar();
  2465. return 0;
  2466. }
  2467. int adjecentDifference(int numbers[], int size){
  2468. int i=0,j=0,max=0,diff=0;
  2469. for(i=0;i<size-1;i++){
  2470. if(numbers[i]>numbers[i+1])
  2471. diff=numbers[i]-numbers[i+1];
  2472. else
  2473. diff=numbers[i+1]-numbers[i];
  2474. if(diff>max)
  2475. max=diff;
  2476. }
  2477. return max;
  2478. }
  2479. 61.Duplicate Elements
  2480.  
  2481. Tim is working as a data entry staff in a college. His manager wants him to delete the duplicate student id from the entry. Help Tim in writing a program to delete the duplicate elements.
  2482.  
  2483. Include a function named eliminateDuplicate that accepts 2 arguments and its return type is void. The first argument is the input array and the second argument is an int that corresponds to the size of the array. The output array is stored in a global variable named output1 and the number of elements in the output array is stored in the global variable named output 2.
  2484.  
  2485. If the size of the array is negative or if any element in the array is negative, print “Invalid Input” and terminate the program.
  2486.  
  2487. Input and Output Format:
  2488. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  2489. Output consists of an integer array.
  2490. Refer sample output for formatting specifications.
  2491.  
  2492. Assume that the maximum number of elements in the array is 20.
  2493.  
  2494. Sample Input 1:
  2495. 8
  2496. 1
  2497. 6
  2498. 3
  2499. 5
  2500. 6
  2501. 8
  2502. 5
  2503. 9
  2504.  
  2505. Sample Output 1:
  2506. 1
  2507. 6
  2508. 3
  2509. 5
  2510. 8
  2511. 9
  2512.  
  2513.  
  2514. Sample Input 2:
  2515. -5
  2516.  
  2517. Sample Output 2:
  2518. Invalid Input
  2519.  
  2520. Sample Input 3:
  2521. 5
  2522. 23
  2523. 2
  2524. -200
  2525.  
  2526. Sample Output 3:
  2527. Invalid Input
  2528.  
  2529.  
  2530. #include<stdio.h>
  2531. #include<stdlib.h>
  2532. void eliminateDuplicate(int[],int);
  2533. int main(){
  2534. int n=0,input[20]={0},i;
  2535. scanf("%d",&n);
  2536. if(n<0){
  2537. printf("Invalid input");
  2538. getchar();
  2539. getchar();
  2540. exit(0);
  2541. }
  2542. for(i=0;i<n;i++){
  2543. scanf("%d",&input[i]);
  2544. if(input[i]<0){
  2545. printf("Invalid input");
  2546. getchar();
  2547. getchar();
  2548. exit(0);
  2549. }
  2550. }
  2551.  
  2552. eliminateDuplicate(input,n);
  2553.  
  2554.  
  2555. return 0;
  2556. }
  2557. void eliminateDuplicate(int in[],int size){
  2558. int i,j,k=0;
  2559. for(i=0;i<size;i++){
  2560. for(j=i+1;j<size;){
  2561. if(in[i]==in[j]){
  2562. for(k=j;k<size;k++)
  2563. in[k]=in[k+1];
  2564. size--;
  2565. }
  2566. else
  2567. j++;
  2568. }
  2569. }
  2570. for(i=0;i<size;i++)
  2571. printf("%d\n",in[i]);
  2572. getchar();
  2573. getchar();
  2574. }
  2575.  
  2576. 62.Second Smallest
  2577.  
  2578. Write a program to find the second smallest of all divisors of the given number.
  2579.  
  2580. For example, the divisors of 21 are 1,3,7 and 21. The second smallest divisor is 3.
  2581.  
  2582. Include a function named secondSmallest that accepts an integer argument and returns an integer. The function returns the second smallest divisor or returns -1 if it is a negative number or if it is greater than 32767.
  2583.  
  2584. If the function returns -1, print Invalid Input.
  2585.  
  2586. Input and Output Format:
  2587. Input consists of a single integer.
  2588. Output consists of a single integer.
  2589. Refer sample output for formatting specifications.
  2590.  
  2591.  
  2592. Sample Input 1:
  2593. 21
  2594.  
  2595. Sample Output 1:
  2596. 3
  2597.  
  2598. Sample Input 2:
  2599. -241
  2600.  
  2601. Sample Output 2:
  2602. Invalid Input
  2603.  
  2604. Sample Input 3:
  2605. 50000
  2606.  
  2607. Sample Output 3:
  2608. Invalid Input
  2609.  
  2610.  
  2611. #include<stdio.h>
  2612. #include<stdlib.h>
  2613. int secondSmallest(int);
  2614. int main(){
  2615. int number=0,result;
  2616. scanf("%d",&number);
  2617. result = secondSmallest(number);
  2618. if(result!=-1)
  2619. printf("%d",result);
  2620. else
  2621. printf("Invalid input");
  2622. getchar();
  2623. getchar();
  2624. return 0;
  2625. }
  2626.  
  2627. int secondSmallest(int n){
  2628. int i;
  2629. for(i=2;i<=n;i++){
  2630. if(n%i==0){
  2631. break;
  2632. }
  2633. }
  2634. return i;
  2635. }
  2636. 63.secondMaxMinDiff
  2637. Read the question carefully and follow the input and output format.
  2638.  
  2639. Given an input array, find the difference b/w second largest and second smallest element in the array.
  2640.  
  2641. Hint : There is no repetition of element in the array.
  2642.  
  2643. Input and Output Format:
  2644.  
  2645. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of an integer, which is the difference b/w second largest and second smallest..
  2646.  
  2647. 1) Print Invalid array size when size of the array is negative and terminate the program.
  2648. 2) Print Invalid input when there is any negative numbers available in the input array and terminate the program.
  2649.  
  2650. Include a function named secondMaxMinDiff(int[] array, int n) whose return type is an integer, which is the difference b/w second largest and second smallest.
  2651.  
  2652. Sample Input 1:
  2653. 5
  2654. 1
  2655. 2
  2656. 3
  2657. 4
  2658. 5
  2659.  
  2660. Sample Output 1:
  2661. 2
  2662.  
  2663. Sample Input 2:
  2664. 4
  2665. -3
  2666.  
  2667. Sample Output 2:
  2668. Invalid input
  2669. #include<stdio.h>
  2670. #include<stdlib.h>
  2671. int secondMaxMinDiff(int[], int n);
  2672. int main(){
  2673. int size=0,input1[20],i=0,diff=0;
  2674. scanf("%d",&size);
  2675. if(size<0){
  2676. printf("Invalid array size");
  2677. getchar();
  2678. getchar();
  2679. exit(0);
  2680. }
  2681. for(i=0;i<size;i++){
  2682. scanf("%d",&input1[i]);
  2683. if(input1[i]<0){
  2684. printf("Invalid Input");
  2685. getchar();
  2686. getchar();
  2687. exit(0);
  2688. }
  2689. }
  2690. diff = secondMaxMinDiff(input1,size);
  2691. printf("%d",diff);
  2692. getchar();
  2693. getchar();
  2694. return 0;
  2695. }
  2696. int secondMaxMinDiff(int array[], int n){
  2697. int i=0,j=0,diff=0,temp=0;
  2698. for(i=0;i<n;i++){
  2699. for(j=i+1;j<n;j++){
  2700. if(array[i]<array[j]){
  2701. temp = array[i];
  2702. array[i]=array[j];
  2703. array[j]=temp;
  2704. }
  2705. }
  2706. }
  2707. diff=array[1]-array[n-2];
  2708. return diff;
  2709. }
  2710. 64.newNumber
  2711. Read the question carefully and follow the input and output format.
  2712.  
  2713. Write a program to find the difference between consecutive digits in the given input integer and display it.
  2714.  
  2715. Input and Output Format:
  2716. Input consists of an integer and output the difference between the consecutive digits.
  2717.  
  2718. Print "Number too small" if the number is less than 0
  2719. Print "Number too large" if the number is greater than 32767
  2720.  
  2721. Include a function named newNumber(int number) that returns a integer
  2722.  
  2723. Sample Input 1:
  2724. 1325
  2725. Sample Output 1:
  2726. 213
  2727.  
  2728. Sample Input 2:
  2729. -13
  2730. Sample Output 2:
  2731. Number too small
  2732.  
  2733. #include<stdio.h>
  2734. #include<stdlib.h>
  2735. int newNumber(int number);
  2736. int main(){
  2737. int num=0,new_num=0;
  2738. scanf("%d",&num);
  2739. if(num>32767)
  2740. printf("Number too large");
  2741. else if(num<0)
  2742. printf("Number too small");
  2743. else{
  2744. new_num=newNumber(num);
  2745. printf("%d",new_num);
  2746. }
  2747. getchar();
  2748. getchar();
  2749. return 0;
  2750. }
  2751. int newNumber(int number){
  2752. int rem,i=1,rem1=0,diff=0,digit=0;
  2753. while(number>10){
  2754. rem=number%10;
  2755. number=number/10;
  2756. rem1=number%10;
  2757. if(rem>rem1)
  2758. diff=rem-rem1;
  2759. else
  2760. diff=rem1-rem;
  2761. digit=digit+(diff*i);
  2762. i=i*10;
  2763. }
  2764. return digit;
  2765. }
  2766.  
  2767.  
  2768. 65.Digit Counting
  2769.  
  2770. In a game show everybody got one coupon with some code. They need to count the digits in the code and send SMS to the given number.
  2771.  
  2772. Write a program to find the number of digits in the given number.
  2773.  
  2774. Include a function named countDigits that accepts an integer argument and returns an integer that corresponds to the number of digits. If the input is a negative number, the function returns -1.
  2775.  
  2776. If the function returns -1, print Invalid Input.
  2777.  
  2778. Input and Output Format:
  2779. Input consists of a single integer.
  2780. Output consists of an integer that corresponds to the number of digits in the input.
  2781.  
  2782.  
  2783. Sample Input 1:
  2784. 250
  2785.  
  2786. Sample Output 1:
  2787. 3
  2788.  
  2789. Sample Input 2:
  2790. -2345
  2791.  
  2792. Sample Output 2:
  2793. Invalid Input
  2794.  
  2795.  
  2796. #include<stdio.h>
  2797. #include<stdlib.h>
  2798. int countDigits(int number);
  2799. int main(){
  2800. int num=0,digits=0;
  2801. scanf("%d",&num);
  2802. digits = countDigits(num);
  2803. if(digits==-1)
  2804. printf("invalid input");
  2805. else
  2806. printf("%d",digits);
  2807. getchar();
  2808. getchar();
  2809. return 0;
  2810. }
  2811. int countDigits(int number){
  2812. int rem,count=0;
  2813. if(number<0)
  2814. count=-1;
  2815. else
  2816. {
  2817. while(number!=0){
  2818. count++;
  2819. number=number/10;
  2820. }
  2821. }
  2822. return count;
  2823. }
  2824.  
  2825. 66.maxScoreCount
  2826.  
  2827. Read the question carefully and follow the input and output format.
  2828.  
  2829. Student1 and Student2 are of same class and have recieved their scores for different subjects. Given each subject scores of the Student1 & Student2, Find out in how many subjects student1 has scored more marks than student2.
  2830.  
  2831. Input and Output Format :
  2832. First line of input corresponds to the n, the number of subjects. The next n lines correspond to the scores of Student 1 and the next n lines correspond to the scores of student 2. Output is the number of subjects student1 scored more marks than student2.
  2833.  
  2834. Print "Invalid size" when size of the array is a negative number and terminate the program
  2835. Print "Invalid score" when there is any negative score and terminate the program
  2836.  
  2837. Include a function named maxScoreCount(int size,int student1[],int student2[]) that returns an integer, the number of subjects student1 scored more marks than student2
  2838.  
  2839. Sample Input 1:
  2840. 7
  2841. 45
  2842. 23
  2843. 67
  2844. 34
  2845. 88
  2846. 13
  2847. 67
  2848. 33
  2849. 56
  2850. 89
  2851. 44
  2852. 67
  2853. 89
  2854. 55
  2855.  
  2856. Sample Output 1:
  2857. 3
  2858.  
  2859. Sample Input 2:
  2860. -3
  2861. Sample Output 2:
  2862. Invalid size
  2863.  
  2864. Sample Input 3:
  2865. 2
  2866. 30
  2867. -60
  2868. Sample Output 3:
  2869. Invalid score
  2870. #include<stdio.h>
  2871. #include<stdlib.h>
  2872. int maxScoreCount(int size,int student1[],int student2[]);
  2873. int main(){
  2874. int size=0,input1[20],input2[20],i=0,count=0;
  2875. scanf("%d",&size);
  2876. if(size<0){
  2877. printf("Invalid array size");
  2878. getchar();
  2879. getchar();
  2880. exit(0);
  2881. }
  2882. for(i=0;i<size;i++){
  2883. scanf("%d",&input1[i]);
  2884. if(input1[i]<0){
  2885. printf("Invalid Input");
  2886. getchar();
  2887. getchar();
  2888. exit(0);
  2889. }
  2890. }
  2891. for(i=0;i<size;i++){
  2892. scanf("%d",&input2[i]);
  2893. if(input2[i]<0){
  2894. printf("Invalid Input");
  2895. getchar();
  2896. getchar();
  2897. exit(0);
  2898. }
  2899. }
  2900. count = maxScoreCount(size,input1,input2);
  2901. printf("%d",count);
  2902. getchar();
  2903. getchar();
  2904. return 0;
  2905. }
  2906. int maxScoreCount(int size,int student1[],int student2[]){
  2907. int i=0,count=0;
  2908. for(i=0;i<size;i++){
  2909. if(student1[i]>student2[i])
  2910. count++;
  2911. }
  2912. return count;
  2913. }
  2914. 67.nextPrime
  2915. Read the question carefully and follow the input and output format.
  2916.  
  2917. Write a program to find out the Next Prime to the given number.
  2918.  
  2919. Hint: number is always less than 100.
  2920.  
  2921. Input and Output Format :
  2922.  
  2923. First line of input consists of n, the number. Output is a single integer that displays the next prime.
  2924.  
  2925. Print "Number too large" when the given input number is greater than 32767 .
  2926. Print "Number too small" when given input is a negative number.
  2927.  
  2928. Include a function named nextPrime(int num) whose return type is an integer, the next prime.
  2929.  
  2930. Sample Input 1:
  2931. 9
  2932.  
  2933. Sample Output 1:
  2934. 11
  2935.  
  2936. Sample Input 2:
  2937. 98987
  2938.  
  2939. Sample Output 2:
  2940. Number too large
  2941.  
  2942. #include<stdio.h>
  2943. #include<stdlib.h>
  2944. int nextPrime(int num);
  2945. int main(){
  2946. int number=0,result;
  2947. scanf("%d",&number);
  2948. if(number<0)
  2949. printf("number too small");
  2950. else if(number>32767)
  2951. printf("number too large");
  2952. else{
  2953. result = nextPrime(number);
  2954. printf("%d",result);
  2955. }
  2956. getchar();
  2957. getchar();
  2958. return 0;
  2959. }
  2960.  
  2961. int nextPrime(int num){
  2962. int next=0,i,m,c=0;
  2963. for(i=num+1;i<100;i++){
  2964. c=0;
  2965. for(m=1;m<=i;m++){
  2966. if(i%m==0)
  2967. c++;
  2968. }
  2969. if(c==2)
  2970. next=i;
  2971. if(next!=0)
  2972. break;
  2973. }
  2974. return next;
  2975. }
  2976. 68.Array Average
  2977.  
  2978. Write a program to find the average of the array.
  2979.  
  2980. Include a function named avgArray that accepts 2 arguments and returns a float. The first argument is the input array and the second argument is an int that corresponds to the size of the array. The function returns a float that corresponds to the average of the array.
  2981.  
  2982. If the size of the array is negative or if any element in the array is negative , print “Invalid Input” and terminate the program.
  2983.  
  2984. Input and Output Format:
  2985. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  2986. Output consists of a floating point number that corresponds to the average. It is displayed correct to 2 decimal places.
  2987. Assume that the maximum size of the array is 20.
  2988.  
  2989. Sample Input 1:
  2990. 7
  2991. 1
  2992. 9
  2993. 8
  2994. 4
  2995. 6
  2996. 4
  2997. 5
  2998.  
  2999. Sample Output 1:
  3000. 5.29
  3001.  
  3002. Sample Input 2:
  3003. -5
  3004.  
  3005. Sample Output 2:
  3006. Invalid Input
  3007.  
  3008. Sample Input 3:
  3009. 5
  3010. 23
  3011. 2
  3012. -5
  3013.  
  3014. Sample Output 3:
  3015. Invalid Input
  3016.  
  3017. #include<stdio.h>
  3018. #include<stdlib.h>
  3019. float avgArray(int numbers[], int size);
  3020. int main(){
  3021. int size=0,input1[20],i=0;
  3022. float avg=0.0f;
  3023. scanf("%d",&size);
  3024. if(size<0){
  3025. printf("Invalid input");
  3026. getchar();
  3027. getchar();
  3028. exit(0);
  3029. }
  3030. for(i=0;i<size;i++){
  3031. scanf("%d",&input1[i]);
  3032. if(input1[i]<0){
  3033. printf("Invalid Input");
  3034. getchar();
  3035. getchar();
  3036. exit(0);
  3037. }
  3038. }
  3039. avg = avgArray(input1,size);
  3040. printf("%.2f",avg);
  3041. getchar();
  3042. getchar();
  3043. return 0;
  3044. }
  3045. float avgArray(int numbers[], int size){
  3046. int i=0,j=0,max=0,sum=0;
  3047. float avg=0.0f;
  3048. for(i=0;i<size;i++){
  3049. sum=sum+numbers[i];
  3050. }
  3051. avg=(float)sum/size;
  3052. return avg;
  3053. }
  3054. 69.Strong Number
  3055.  
  3056. Write a program to find whether the given input number is a Strong Number
  3057.  
  3058. Strong Number : (In a number sum of Factorial of individual digits equals to the same number).
  3059.  
  3060. Include a function named checkStrong that accepts an integer and returns an integer. The function returns
  3061. 1. 1 if the input is a Strong Number
  3062. 2. 0 if the input is not a Strong Number
  3063. 3. -1 if the input is a negative number
  3064.  
  3065. Print Invalid Input if the function returns -1.
  3066.  
  3067. Input and Output Format:
  3068. Input consists of a single integer.
  3069. Refer sample output for formatting specifications.
  3070.  
  3071.  
  3072. Sample Input 1:
  3073. 145
  3074.  
  3075. Sample Output 1:
  3076. yes
  3077.  
  3078. Sample Input 2:
  3079. 141
  3080.  
  3081. Sample Output 2:
  3082. no
  3083.  
  3084. Sample Input 3:
  3085. -2345
  3086.  
  3087. Sample Output 3:
  3088. Invalid Input
  3089.  
  3090. /*
  3091. num1=num;
  3092. while(num){
  3093. i=1,f=1;
  3094. r=num%10;
  3095.  
  3096. while(i<=r){
  3097. f=f*i;
  3098. i++;
  3099. }
  3100. sum=sum+f;
  3101. num=num/10;
  3102.  
  3103. }
  3104. if(sum==num1)
  3105. printf("%d is a strong number",num1);
  3106. else
  3107. printf("%d is not a strong number",num1);
  3108.  
  3109. */
  3110.  
  3111. #include<stdio.h>
  3112. #include<stdlib.h>
  3113. int checkStrong(int);
  3114. int main(){
  3115. int number=0,result;
  3116. scanf("%d",&number);
  3117. result = checkStrong(number);
  3118. if(result==1)
  3119. printf("yes");
  3120. else if(result==0)
  3121. printf("no");
  3122. else
  3123. printf("Invalid input");
  3124. getchar();
  3125. getchar();
  3126. return 0;
  3127. }
  3128.  
  3129. int checkStrong(int num){
  3130. int res=0,f=0,r=0,num1=0,i,sum=0;
  3131. if(num<0)
  3132. res=-1;
  3133. else{
  3134. num1=num;
  3135. while(num){
  3136. i=1,f=1;
  3137. r=num%10;
  3138. while(i<=r){
  3139. f=f*i;
  3140. i++;
  3141. }
  3142. sum=sum+f;
  3143. num=num/10;
  3144. }
  3145. if(sum==num1)
  3146. res=1;
  3147. else
  3148. res=0;
  3149. }
  3150. return res;
  3151. }
  3152. 70.Sum of Even Digits
  3153.  
  3154. In the computer science department, HOD wants to divide students into two groups based on their roll numbers. He decided to find the sum of the even digits in the roll number of each student and decided to split them into 2 groups based on this. Write a program to find the sum of the even digits in a number.
  3155.  
  3156. Include a function named addEvenDigits to find the sum of even digits in a number. This function accepts an integer argument and returns an integer. The function returns -1 if the roll number is less than zero or if the roll number is greater than 32767. Refer function specifications given at the end of the problem for further details.
  3157.  
  3158. If the roll number is less than 0 or if it exceeds 32767, print “Invalid Input”.
  3159.  
  3160. Input and Output Format:
  3161. The input consists of an integer that corresponds to the roll number.
  3162. The output consists of an integer that corresponds to the sum of the even digits in the roll number.
  3163.  
  3164. Sample Input 1:
  3165. 3487
  3166.  
  3167. Sample Ouput 1:
  3168. 12
  3169.  
  3170. Sample Input 2:
  3171. -8
  3172.  
  3173. Sample Output 2:
  3174. Invalid Input
  3175.  
  3176. #include<stdio.h>
  3177. #include<stdlib.h>
  3178. int addEvenDigits(int);
  3179. int main(){
  3180. int number,result=0;
  3181. scanf("%d",&number);
  3182. result = addEvenDigits(number);
  3183. if(result==-1)
  3184. printf("Invalid input");
  3185. else
  3186. printf("%d",result);
  3187. getchar();
  3188. getchar();
  3189. return 0;
  3190. }
  3191.  
  3192. int addEvenDigits(int n){
  3193. int res=0,i,rem=0;
  3194. if(n<0 || n>32767)
  3195. res = -1;
  3196. else{
  3197. while(n!=0){
  3198. rem=n%10;
  3199. if(rem%2==0)
  3200. res=res+rem;
  3201. n=n/10;
  3202. }
  3203. }
  3204. return res;
  3205. }
  3206. 61.Duplicate Elements
  3207.  
  3208. Tim is working as a data entry staff in a college. His manager wants him to delete the duplicate student id from the entry. Help Tim in writing a program to delete the duplicate elements.
  3209.  
  3210. Include a function named eliminateDuplicate that accepts 2 arguments and its return type is void. The first argument is the input array and the second argument is an int that corresponds to the size of the array. The output array is stored in a global variable named output1 and the number of elements in the output array is stored in the global variable named output 2.
  3211.  
  3212. If the size of the array is negative or if any element in the array is negative, print “Invalid Input” and terminate the program.
  3213.  
  3214. Input and Output Format:
  3215. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  3216. Output consists of an integer array.
  3217. Refer sample output for formatting specifications.
  3218.  
  3219. Assume that the maximum number of elements in the array is 20.
  3220.  
  3221. Sample Input 1:
  3222. 8
  3223. 1
  3224. 6
  3225. 3
  3226. 5
  3227. 6
  3228. 8
  3229. 5
  3230. 9
  3231.  
  3232. Sample Output 1:
  3233. 1
  3234. 6
  3235. 3
  3236. 5
  3237. 8
  3238. 9
  3239.  
  3240.  
  3241. Sample Input 2:
  3242. -5
  3243.  
  3244. Sample Output 2:
  3245. Invalid Input
  3246.  
  3247. Sample Input 3:
  3248. 5
  3249. 23
  3250. 2
  3251. -200
  3252.  
  3253. Sample Output 3:
  3254. Invalid Input
  3255.  
  3256.  
  3257. #include<stdio.h>
  3258. #include<stdlib.h>
  3259. void eliminateDuplicate(int[],int);
  3260. int main(){
  3261. int n=0,input[20]={0},i;
  3262. scanf("%d",&n);
  3263. if(n<0){
  3264. printf("Invalid input");
  3265. getchar();
  3266. getchar();
  3267. exit(0);
  3268. }
  3269. for(i=0;i<n;i++){
  3270. scanf("%d",&input[i]);
  3271. if(input[i]<0){
  3272. printf("Invalid input");
  3273. getchar();
  3274. getchar();
  3275. exit(0);
  3276. }
  3277. }
  3278.  
  3279. eliminateDuplicate(input,n);
  3280.  
  3281.  
  3282. return 0;
  3283. }
  3284. void eliminateDuplicate(int in[],int size){
  3285. int i,j,k=0;
  3286. for(i=0;i<size;i++){
  3287. for(j=i+1;j<size;){
  3288. if(in[i]==in[j]){
  3289. for(k=j;k<size;k++)
  3290. in[k]=in[k+1];
  3291. size--;
  3292. }
  3293. else
  3294. j++;
  3295. }
  3296. }
  3297. for(i=0;i<size;i++)
  3298. printf("%d\n",in[i]);
  3299. getchar();
  3300. getchar();
  3301. }
  3302.  
  3303. 62.Second Smallest
  3304.  
  3305. Write a program to find the second smallest of all divisors of the given number.
  3306.  
  3307. For example, the divisors of 21 are 1,3,7 and 21. The second smallest divisor is 3.
  3308.  
  3309. Include a function named secondSmallest that accepts an integer argument and returns an integer. The function returns the second smallest divisor or returns -1 if it is a negative number or if it is greater than 32767.
  3310.  
  3311. If the function returns -1, print Invalid Input.
  3312.  
  3313. Input and Output Format:
  3314. Input consists of a single integer.
  3315. Output consists of a single integer.
  3316. Refer sample output for formatting specifications.
  3317.  
  3318.  
  3319. Sample Input 1:
  3320. 21
  3321.  
  3322. Sample Output 1:
  3323. 3
  3324.  
  3325. Sample Input 2:
  3326. -241
  3327.  
  3328. Sample Output 2:
  3329. Invalid Input
  3330.  
  3331. Sample Input 3:
  3332. 50000
  3333.  
  3334. Sample Output 3:
  3335. Invalid Input
  3336.  
  3337.  
  3338. #include<stdio.h>
  3339. #include<stdlib.h>
  3340. int secondSmallest(int);
  3341. int main(){
  3342. int number=0,result;
  3343. scanf("%d",&number);
  3344. result = secondSmallest(number);
  3345. if(result!=-1)
  3346. printf("%d",result);
  3347. else
  3348. printf("Invalid input");
  3349. getchar();
  3350. getchar();
  3351. return 0;
  3352. }
  3353.  
  3354. int secondSmallest(int n){
  3355. int i;
  3356. for(i=2;i<=n;i++){
  3357. if(n%i==0){
  3358. break;
  3359. }
  3360. }
  3361. return i;
  3362. }
  3363. 63.secondMaxMinDiff
  3364. Read the question carefully and follow the input and output format.
  3365.  
  3366. Given an input array, find the difference b/w second largest and second smallest element in the array.
  3367.  
  3368. Hint : There is no repetition of element in the array.
  3369.  
  3370. Input and Output Format:
  3371.  
  3372. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of an integer, which is the difference b/w second largest and second smallest..
  3373.  
  3374. 1) Print Invalid array size when size of the array is negative and terminate the program.
  3375. 2) Print Invalid input when there is any negative numbers available in the input array and terminate the program.
  3376.  
  3377. Include a function named secondMaxMinDiff(int[] array, int n) whose return type is an integer, which is the difference b/w second largest and second smallest.
  3378.  
  3379. Sample Input 1:
  3380. 5
  3381. 1
  3382. 2
  3383. 3
  3384. 4
  3385. 5
  3386.  
  3387. Sample Output 1:
  3388. 2
  3389.  
  3390. Sample Input 2:
  3391. 4
  3392. -3
  3393.  
  3394. Sample Output 2:
  3395. Invalid input
  3396. #include<stdio.h>
  3397. #include<stdlib.h>
  3398. int secondMaxMinDiff(int[], int n);
  3399. int main(){
  3400. int size=0,input1[20],i=0,diff=0;
  3401. scanf("%d",&size);
  3402. if(size<0){
  3403. printf("Invalid array size");
  3404. getchar();
  3405. getchar();
  3406. exit(0);
  3407. }
  3408. for(i=0;i<size;i++){
  3409. scanf("%d",&input1[i]);
  3410. if(input1[i]<0){
  3411. printf("Invalid Input");
  3412. getchar();
  3413. getchar();
  3414. exit(0);
  3415. }
  3416. }
  3417. diff = secondMaxMinDiff(input1,size);
  3418. printf("%d",diff);
  3419. getchar();
  3420. getchar();
  3421. return 0;
  3422. }
  3423. int secondMaxMinDiff(int array[], int n){
  3424. int i=0,j=0,diff=0,temp=0;
  3425. for(i=0;i<n;i++){
  3426. for(j=i+1;j<n;j++){
  3427. if(array[i]<array[j]){
  3428. temp = array[i];
  3429. array[i]=array[j];
  3430. array[j]=temp;
  3431. }
  3432. }
  3433. }
  3434. diff=array[1]-array[n-2];
  3435. return diff;
  3436. }
  3437. 64.newNumber
  3438. Read the question carefully and follow the input and output format.
  3439.  
  3440. Write a program to find the difference between consecutive digits in the given input integer and display it.
  3441.  
  3442. Input and Output Format:
  3443. Input consists of an integer and output the difference between the consecutive digits.
  3444.  
  3445. Print "Number too small" if the number is less than 0
  3446. Print "Number too large" if the number is greater than 32767
  3447.  
  3448. Include a function named newNumber(int number) that returns a integer
  3449.  
  3450. Sample Input 1:
  3451. 1325
  3452. Sample Output 1:
  3453. 213
  3454.  
  3455. Sample Input 2:
  3456. -13
  3457. Sample Output 2:
  3458. Number too small
  3459.  
  3460. #include<stdio.h>
  3461. #include<stdlib.h>
  3462. int newNumber(int number);
  3463. int main(){
  3464. int num=0,new_num=0;
  3465. scanf("%d",&num);
  3466. if(num>32767)
  3467. printf("Number too large");
  3468. else if(num<0)
  3469. printf("Number too small");
  3470. else{
  3471. new_num=newNumber(num);
  3472. printf("%d",new_num);
  3473. }
  3474. getchar();
  3475. getchar();
  3476. return 0;
  3477. }
  3478. int newNumber(int number){
  3479. int rem,i=1,rem1=0,diff=0,digit=0;
  3480. while(number>10){
  3481. rem=number%10;
  3482. number=number/10;
  3483. rem1=number%10;
  3484. if(rem>rem1)
  3485. diff=rem-rem1;
  3486. else
  3487. diff=rem1-rem;
  3488. digit=digit+(diff*i);
  3489. i=i*10;
  3490. }
  3491. return digit;
  3492. }
  3493.  
  3494.  
  3495. 65.Digit Counting
  3496.  
  3497. In a game show everybody got one coupon with some code. They need to count the digits in the code and send SMS to the given number.
  3498.  
  3499. Write a program to find the number of digits in the given number.
  3500.  
  3501. Include a function named countDigits that accepts an integer argument and returns an integer that corresponds to the number of digits. If the input is a negative number, the function returns -1.
  3502.  
  3503. If the function returns -1, print Invalid Input.
  3504.  
  3505. Input and Output Format:
  3506. Input consists of a single integer.
  3507. Output consists of an integer that corresponds to the number of digits in the input.
  3508.  
  3509.  
  3510. Sample Input 1:
  3511. 250
  3512.  
  3513. Sample Output 1:
  3514. 3
  3515.  
  3516. Sample Input 2:
  3517. -2345
  3518.  
  3519. Sample Output 2:
  3520. Invalid Input
  3521.  
  3522.  
  3523. #include<stdio.h>
  3524. #include<stdlib.h>
  3525. int countDigits(int number);
  3526. int main(){
  3527. int num=0,digits=0;
  3528. scanf("%d",&num);
  3529. digits = countDigits(num);
  3530. if(digits==-1)
  3531. printf("invalid input");
  3532. else
  3533. printf("%d",digits);
  3534. getchar();
  3535. getchar();
  3536. return 0;
  3537. }
  3538. int countDigits(int number){
  3539. int rem,count=0;
  3540. if(number<0)
  3541. count=-1;
  3542. else
  3543. {
  3544. while(number!=0){
  3545. count++;
  3546. number=number/10;
  3547. }
  3548. }
  3549. return count;
  3550. }
  3551.  
  3552. 66.maxScoreCount
  3553.  
  3554. Read the question carefully and follow the input and output format.
  3555.  
  3556. Student1 and Student2 are of same class and have recieved their scores for different subjects. Given each subject scores of the Student1 & Student2, Find out in how many subjects student1 has scored more marks than student2.
  3557.  
  3558. Input and Output Format :
  3559. First line of input corresponds to the n, the number of subjects. The next n lines correspond to the scores of Student 1 and the next n lines correspond to the scores of student 2. Output is the number of subjects student1 scored more marks than student2.
  3560.  
  3561. Print "Invalid size" when size of the array is a negative number and terminate the program
  3562. Print "Invalid score" when there is any negative score and terminate the program
  3563.  
  3564. Include a function named maxScoreCount(int size,int student1[],int student2[]) that returns an integer, the number of subjects student1 scored more marks than student2
  3565.  
  3566. Sample Input 1:
  3567. 7
  3568. 45
  3569. 23
  3570. 67
  3571. 34
  3572. 88
  3573. 13
  3574. 67
  3575. 33
  3576. 56
  3577. 89
  3578. 44
  3579. 67
  3580. 89
  3581. 55
  3582.  
  3583. Sample Output 1:
  3584. 3
  3585.  
  3586. Sample Input 2:
  3587. -3
  3588. Sample Output 2:
  3589. Invalid size
  3590.  
  3591. Sample Input 3:
  3592. 2
  3593. 30
  3594. -60
  3595. Sample Output 3:
  3596. Invalid score
  3597. #include<stdio.h>
  3598. #include<stdlib.h>
  3599. int maxScoreCount(int size,int student1[],int student2[]);
  3600. int main(){
  3601. int size=0,input1[20],input2[20],i=0,count=0;
  3602. scanf("%d",&size);
  3603. if(size<0){
  3604. printf("Invalid array size");
  3605. getchar();
  3606. getchar();
  3607. exit(0);
  3608. }
  3609. for(i=0;i<size;i++){
  3610. scanf("%d",&input1[i]);
  3611. if(input1[i]<0){
  3612. printf("Invalid Input");
  3613. getchar();
  3614. getchar();
  3615. exit(0);
  3616. }
  3617. }
  3618. for(i=0;i<size;i++){
  3619. scanf("%d",&input2[i]);
  3620. if(input2[i]<0){
  3621. printf("Invalid Input");
  3622. getchar();
  3623. getchar();
  3624. exit(0);
  3625. }
  3626. }
  3627. count = maxScoreCount(size,input1,input2);
  3628. printf("%d",count);
  3629. getchar();
  3630. getchar();
  3631. return 0;
  3632. }
  3633. int maxScoreCount(int size,int student1[],int student2[]){
  3634. int i=0,count=0;
  3635. for(i=0;i<size;i++){
  3636. if(student1[i]>student2[i])
  3637. count++;
  3638. }
  3639. return count;
  3640. }
  3641. 67.nextPrime
  3642. Read the question carefully and follow the input and output format.
  3643.  
  3644. Write a program to find out the Next Prime to the given number.
  3645.  
  3646. Hint: number is always less than 100.
  3647.  
  3648. Input and Output Format :
  3649.  
  3650. First line of input consists of n, the number. Output is a single integer that displays the next prime.
  3651.  
  3652. Print "Number too large" when the given input number is greater than 32767 .
  3653. Print "Number too small" when given input is a negative number.
  3654.  
  3655. Include a function named nextPrime(int num) whose return type is an integer, the next prime.
  3656.  
  3657. Sample Input 1:
  3658. 9
  3659.  
  3660. Sample Output 1:
  3661. 11
  3662.  
  3663. Sample Input 2:
  3664. 98987
  3665.  
  3666. Sample Output 2:
  3667. Number too large
  3668.  
  3669. #include<stdio.h>
  3670. #include<stdlib.h>
  3671. int nextPrime(int num);
  3672. int main(){
  3673. int number=0,result;
  3674. scanf("%d",&number);
  3675. if(number<0)
  3676. printf("number too small");
  3677. else if(number>32767)
  3678. printf("number too large");
  3679. else{
  3680. result = nextPrime(number);
  3681. printf("%d",result);
  3682. }
  3683. getchar();
  3684. getchar();
  3685. return 0;
  3686. }
  3687.  
  3688. int nextPrime(int num){
  3689. int next=0,i,m,c=0;
  3690. for(i=num+1;i<100;i++){
  3691. c=0;
  3692. for(m=1;m<=i;m++){
  3693. if(i%m==0)
  3694. c++;
  3695. }
  3696. if(c==2)
  3697. next=i;
  3698. if(next!=0)
  3699. break;
  3700. }
  3701. return next;
  3702. }
  3703. 68.Array Average
  3704.  
  3705. Write a program to find the average of the array.
  3706.  
  3707. Include a function named avgArray that accepts 2 arguments and returns a float. The first argument is the input array and the second argument is an int that corresponds to the size of the array. The function returns a float that corresponds to the average of the array.
  3708.  
  3709. If the size of the array is negative or if any element in the array is negative , print “Invalid Input” and terminate the program.
  3710.  
  3711. Input and Output Format:
  3712. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  3713. Output consists of a floating point number that corresponds to the average. It is displayed correct to 2 decimal places.
  3714. Assume that the maximum size of the array is 20.
  3715.  
  3716. Sample Input 1:
  3717. 7
  3718. 1
  3719. 9
  3720. 8
  3721. 4
  3722. 6
  3723. 4
  3724. 5
  3725.  
  3726. Sample Output 1:
  3727. 5.29
  3728.  
  3729. Sample Input 2:
  3730. -5
  3731.  
  3732. Sample Output 2:
  3733. Invalid Input
  3734.  
  3735. Sample Input 3:
  3736. 5
  3737. 23
  3738. 2
  3739. -5
  3740.  
  3741. Sample Output 3:
  3742. Invalid Input
  3743.  
  3744. #include<stdio.h>
  3745. #include<stdlib.h>
  3746. float avgArray(int numbers[], int size);
  3747. int main(){
  3748. int size=0,input1[20],i=0;
  3749. float avg=0.0f;
  3750. scanf("%d",&size);
  3751. if(size<0){
  3752. printf("Invalid input");
  3753. getchar();
  3754. getchar();
  3755. exit(0);
  3756. }
  3757. for(i=0;i<size;i++){
  3758. scanf("%d",&input1[i]);
  3759. if(input1[i]<0){
  3760. printf("Invalid Input");
  3761. getchar();
  3762. getchar();
  3763. exit(0);
  3764. }
  3765. }
  3766. avg = avgArray(input1,size);
  3767. printf("%.2f",avg);
  3768. getchar();
  3769. getchar();
  3770. return 0;
  3771. }
  3772. float avgArray(int numbers[], int size){
  3773. int i=0,j=0,max=0,sum=0;
  3774. float avg=0.0f;
  3775. for(i=0;i<size;i++){
  3776. sum=sum+numbers[i];
  3777. }
  3778. avg=(float)sum/size;
  3779. return avg;
  3780. }
  3781. 69.Strong Number
  3782.  
  3783. Write a program to find whether the given input number is a Strong Number
  3784.  
  3785. Strong Number : (In a number sum of Factorial of individual digits equals to the same number).
  3786.  
  3787. Include a function named checkStrong that accepts an integer and returns an integer. The function returns
  3788. 1. 1 if the input is a Strong Number
  3789. 2. 0 if the input is not a Strong Number
  3790. 3. -1 if the input is a negative number
  3791.  
  3792. Print Invalid Input if the function returns -1.
  3793.  
  3794. Input and Output Format:
  3795. Input consists of a single integer.
  3796. Refer sample output for formatting specifications.
  3797.  
  3798.  
  3799. Sample Input 1:
  3800. 145
  3801.  
  3802. Sample Output 1:
  3803. yes
  3804.  
  3805. Sample Input 2:
  3806. 141
  3807.  
  3808. Sample Output 2:
  3809. no
  3810.  
  3811. Sample Input 3:
  3812. -2345
  3813.  
  3814. Sample Output 3:
  3815. Invalid Input
  3816.  
  3817. /*
  3818. num1=num;
  3819. while(num){
  3820. i=1,f=1;
  3821. r=num%10;
  3822.  
  3823. while(i<=r){
  3824. f=f*i;
  3825. i++;
  3826. }
  3827. sum=sum+f;
  3828. num=num/10;
  3829.  
  3830. }
  3831. if(sum==num1)
  3832. printf("%d is a strong number",num1);
  3833. else
  3834. printf("%d is not a strong number",num1);
  3835.  
  3836. */
  3837.  
  3838. #include<stdio.h>
  3839. #include<stdlib.h>
  3840. int checkStrong(int);
  3841. int main(){
  3842. int number=0,result;
  3843. scanf("%d",&number);
  3844. result = checkStrong(number);
  3845. if(result==1)
  3846. printf("yes");
  3847. else if(result==0)
  3848. printf("no");
  3849. else
  3850. printf("Invalid input");
  3851. getchar();
  3852. getchar();
  3853. return 0;
  3854. }
  3855.  
  3856. int checkStrong(int num){
  3857. int res=0,f=0,r=0,num1=0,i,sum=0;
  3858. if(num<0)
  3859. res=-1;
  3860. else{
  3861. num1=num;
  3862. while(num){
  3863. i=1,f=1;
  3864. r=num%10;
  3865. while(i<=r){
  3866. f=f*i;
  3867. i++;
  3868. }
  3869. sum=sum+f;
  3870. num=num/10;
  3871. }
  3872. if(sum==num1)
  3873. res=1;
  3874. else
  3875. res=0;
  3876. }
  3877. return res;
  3878. }
  3879. 70.Sum of Even Digits
  3880.  
  3881. In the computer science department, HOD wants to divide students into two groups based on their roll numbers. He decided to find the sum of the even digits in the roll number of each student and decided to split them into 2 groups based on this. Write a program to find the sum of the even digits in a number.
  3882.  
  3883. Include a function named addEvenDigits to find the sum of even digits in a number. This function accepts an integer argument and returns an integer. The function returns -1 if the roll number is less than zero or if the roll number is greater than 32767. Refer function specifications given at the end of the problem for further details.
  3884.  
  3885. If the roll number is less than 0 or if it exceeds 32767, print “Invalid Input”.
  3886.  
  3887. Input and Output Format:
  3888. The input consists of an integer that corresponds to the roll number.
  3889. The output consists of an integer that corresponds to the sum of the even digits in the roll number.
  3890.  
  3891. Sample Input 1:
  3892. 3487
  3893.  
  3894. Sample Ouput 1:
  3895. 12
  3896.  
  3897. Sample Input 2:
  3898. -8
  3899.  
  3900. Sample Output 2:
  3901. Invalid Input
  3902.  
  3903. #include<stdio.h>
  3904. #include<stdlib.h>
  3905. int addEvenDigits(int);
  3906. int main(){
  3907. int number,result=0;
  3908. scanf("%d",&number);
  3909. result = addEvenDigits(number);
  3910. if(result==-1)
  3911. printf("Invalid input");
  3912. else
  3913. printf("%d",result);
  3914. getchar();
  3915. getchar();
  3916. return 0;
  3917. }
  3918.  
  3919. int addEvenDigits(int n){
  3920. int res=0,i,rem=0;
  3921. if(n<0 || n>32767)
  3922. res = -1;
  3923. else{
  3924. while(n!=0){
  3925. rem=n%10;
  3926. if(rem%2==0)
  3927. res=res+rem;
  3928. n=n/10;
  3929. }
  3930. }
  3931. return res;
  3932. }
  3933. 71.commonElementsSum
  3934. Read the question carefully and follow the input and output format.
  3935.  
  3936. Given 2 integer arrays , write a program to find the sum of common elements in both the arrays.
  3937.  
  3938. If there are no common elements print 0.
  3939.  
  3940. Input and Output Format :
  3941. First line of input consists of n, the number of elements. Next n lines correspond to the first array elements and the next n lines correspond to the second array elements. Output consist of an integer, which is the sum
  3942.  
  3943. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program.
  3944. 2) Print "Invalid input" when there is any negative numbers available in the input array and terminate the program.
  3945.  
  3946. Include a function named commonElementsSum(int elements1[],int elements2[],int size) whose return type is an integer, the sum.
  3947.  
  3948. Sample Input 1:
  3949. 4
  3950. 1
  3951. 2
  3952. 3
  3953. 4
  3954. 2
  3955. 3
  3956. 6
  3957. 7
  3958.  
  3959. Sample Output 1:
  3960. 5
  3961.  
  3962. Sample Input 2:
  3963. 3
  3964. 8
  3965. 6
  3966. -7
  3967.  
  3968. Sample Output 2:
  3969. Invalid input
  3970.  
  3971.  
  3972. #include<stdio.h>
  3973. #include<stdlib.h>
  3974. int common[20];
  3975. int commonElementsSum(int elements1[],int elements2[],int size);
  3976. int main(){
  3977. int size=0,input1[20],input2[20],i=0,sum=0;
  3978. scanf("%d",&size);
  3979. if(size<0){
  3980. printf("Invalid array size");
  3981. getchar();
  3982. getchar();
  3983. exit(0);
  3984. }
  3985. for(i=0;i<size;i++){
  3986. scanf("%d",&input1[i]);
  3987. if(input1[i]<0){
  3988. printf("Invalid Input");
  3989. getchar();
  3990. getchar();
  3991. exit(0);
  3992. }
  3993. }
  3994. for(i=0;i<size;i++){
  3995. scanf("%d",&input2[i]);
  3996. if(input2[i]<0){
  3997. printf("Invalid Input");
  3998. getchar();
  3999. getchar();
  4000. exit(0);
  4001. }
  4002. }
  4003. sum=commonElementsSum(input1,input2,size);
  4004. printf("%d",sum);
  4005. getchar();
  4006. getchar();
  4007. return 0;
  4008. }
  4009. int commonElementsSum(int elements1[],int elements2[],int size){
  4010. int i=0,j=0,k=0,temp=0,sum=0;
  4011. for(i=0;i<size;i++){
  4012. for(j=0;j<size;j++){
  4013. if(elements1[i]==elements2[j]){
  4014. common[k]=elements1[i];
  4015. k++;
  4016. }
  4017. }
  4018. }
  4019. for(i=0;i<k;i++)
  4020. sum=sum+common[i];
  4021. return sum;
  4022.  
  4023. }
  4024. 72.Palindromic Number
  4025.  
  4026. Write a program to find whether the given input number is a palindrome.
  4027.  
  4028. Include a function named checkPalindrome that accepts an integer and returns an integer. The function returns
  4029. 1. 1 if the input is a palindrome
  4030. 2. 0 if the input is not a palindrome
  4031. 3. -1 if the input is a negative number
  4032.  
  4033. Print Invalid Input if the function returns -1.
  4034.  
  4035. Input and Output Format:
  4036. Input consists of a single integer.
  4037. Refer sample output for formatting specifications.
  4038.  
  4039.  
  4040. Sample Input 1:
  4041. 2002
  4042.  
  4043. Sample Output 1:
  4044. yes
  4045.  
  4046. Sample Input 2:
  4047. 167
  4048.  
  4049. Sample Output 2:
  4050. no
  4051.  
  4052. Sample Input 3:
  4053. -2345
  4054.  
  4055. Sample Output 3:
  4056. Invalid Input
  4057.  
  4058.  
  4059. #include<stdio.h>
  4060. #include<stdlib.h>
  4061. int checkPalindrome (int);
  4062. int main(){
  4063. int number=0,result;
  4064. scanf("%d",&number);
  4065. result = checkPalindrome (number);
  4066. if(result==1)
  4067. printf("yes");
  4068. else if(result==0)
  4069. printf("no");
  4070. else
  4071. printf("Invalid input");
  4072. getchar();
  4073. getchar();
  4074. return 0;
  4075. }
  4076.  
  4077. int checkPalindrome (int n){
  4078. int res=0,temp=0,rem=0,sum=0,reverse=0;
  4079. if(n<0)
  4080. res=-1;
  4081. else{
  4082. temp=n;
  4083. while(temp!=0){
  4084. rem=temp%10;
  4085. reverse=reverse*10+rem;
  4086. temp/=10;
  4087. }
  4088. if(reverse==n)
  4089. res=1;
  4090. else
  4091. res=0;
  4092. }
  4093. return res;
  4094. }
  4095. 73.sumEvenIndex
  4096. Read the question carefully and follow the input and output format.
  4097.  
  4098. Write a program to find the sum of the indexes (positions) of even numbers in the Array. Consider 0 index as 1 and 1 index is 2 and so on……
  4099. Note : Assume Array Index Starts From 1
  4100.  
  4101. Input and Output Format :
  4102. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of an integer, which is the sum.
  4103.  
  4104. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program.
  4105. 2) Print "Invalid input" when there is any negative number available in the input array and terminate the program.
  4106.  
  4107. Include a function named sumEvenIndex(int numbers[], int size) whose return type is an integer, which is the sum..
  4108. Sample Input 1:
  4109. 7
  4110. 4
  4111. 2
  4112. 7
  4113. 9
  4114. 1
  4115. 10
  4116. 13
  4117.  
  4118. Sample Output 1:
  4119. 9
  4120.  
  4121. Sample Input 2:
  4122. -13
  4123.  
  4124. Sample Output 2:
  4125. Invalid array size
  4126. #include<stdio.h>
  4127. #include<stdlib.h>
  4128. int sumEvenIndex(int numbers[], int size);
  4129. int main(){
  4130. int n=0,sum=0,input[30],i,flag=0;
  4131. scanf("%d",&n);
  4132. if(n<0){
  4133. printf("Invalid array size");
  4134. getchar();
  4135. getchar();
  4136. exit(0);
  4137. }
  4138. for(i=1;i<=n;i++){
  4139. scanf("%d",&input[i]);
  4140. if(input[i]<0){
  4141. printf("Invalid Input");
  4142. getchar();
  4143. getchar();
  4144. exit(0);
  4145. }
  4146. }
  4147. sum = sumEvenIndex(input,n);
  4148. printf("%d",sum);
  4149. getchar();
  4150. getchar();
  4151. return 0;
  4152. }
  4153. int sumEvenIndex(int numbers[], int size){
  4154. int i=0,sum=0;
  4155. for(i=1;i<=size;i++){
  4156. if(numbers[i]%2==0)
  4157. sum=sum+i;
  4158. }
  4159. return sum;
  4160. }
  4161. 74.sumEvenOddProduct
  4162. Read the question carefully and follow the input and output format.
  4163.  
  4164. Write a program to find the sum of product of even digits and product of odd digits in a given number.
  4165.  
  4166. If number contains only even numbers or odd numbers take the other numbers product as 1.
  4167.  
  4168. Input and Output Format :
  4169. Input consists of a single integer. Output consist of the sum of even digit product and odd digit product.
  4170.  
  4171. Print "Number too large" when the given input number is greater than 32767
  4172. Print "Number too small" when the given input number is a negative number.
  4173.  
  4174. Include a function named sumEvenOddProduct(int number) whose return type is integer, the sum
  4175.  
  4176. Sample Input 1:
  4177. 4564
  4178. Sample Output 1:
  4179. 101
  4180.  
  4181. {Hint : (4*6*4) + (5) = 96 +5 = 101}
  4182. Sample Input 2:
  4183. 1357
  4184. Sample Output 2:
  4185. 106
  4186.  
  4187.  
  4188. Sample Input 3:
  4189. 981357
  4190. Sample Output 3:
  4191. Number too large
  4192.  
  4193. #include<stdio.h>
  4194. #include<stdlib.h>
  4195. int sumEvenOddProduct(int number);
  4196. int main(){
  4197. int number,result=0;
  4198. scanf("%d",&number);
  4199. if(number>32767)
  4200. printf("number too large");
  4201. else if(number<0)
  4202. printf("number too small");
  4203. else
  4204. {
  4205. result = sumEvenOddProduct(number);
  4206. printf("%d",result);
  4207. }
  4208. getchar();
  4209. getchar();
  4210. return 0;
  4211. }
  4212.  
  4213. int sumEvenOddProduct(int number){
  4214. int res=0,i,rem=0,evenprod=1,oddprod=1;
  4215. while(number!=0){
  4216. rem=number%10;
  4217. if(rem%2==0)
  4218. evenprod=evenprod*rem;
  4219. else
  4220. oddprod=oddprod*rem;
  4221. number=number/10;
  4222. }
  4223. res = evenprod + oddprod;
  4224. return res;
  4225. }
  4226.  
  4227. 75.Sum of the Digits
  4228.  
  4229. In a lucky draw everybody got one coupon with some code. They need to sum the digits in the code and send SMS to the given number. Write a program to find the sum of digits in a number.
  4230.  
  4231. Include a function named sumDigits that accepts an integer argument and returns an integer that corresponds to the sum of the digits. The function returns -1 if the input is less than zero or if the roll number is greater than 32767.
  4232.  
  4233. If the function returns -1, print “Invalid Input”.
  4234.  
  4235. Input and Output Format:
  4236.  
  4237. The input consists of an integer.
  4238. The output consists of an integer that corresponds to the sum of the digits in the number.
  4239.  
  4240. Sample Input 1:
  4241. 3487
  4242.  
  4243. Sample Ouput 1:
  4244. 22
  4245.  
  4246. Sample Input 2:
  4247. -8
  4248.  
  4249. Sample Output 2:
  4250. Invalid Input
  4251.  
  4252.  
  4253.  
  4254. #include<stdio.h>
  4255. #include<stdlib.h>
  4256. int sumDigits(int);
  4257. int main(){
  4258. int number,result=0;
  4259. scanf("%d",&number);
  4260. result = sumDigits(number);
  4261. if(result==-1)
  4262. printf("Invalid input");
  4263. else
  4264. printf("%d",result);
  4265. getchar();
  4266. getchar();
  4267. return 0;
  4268. }
  4269.  
  4270. int sumDigits(int n){
  4271. int res=0,i,rem=0;
  4272. if(n<0 || n>32767)
  4273. res = -1;
  4274. else{
  4275. while(n!=0){
  4276. rem=n%10;
  4277. res=res+rem;
  4278. n=n/10;
  4279. }
  4280. }
  4281. return res;
  4282. }
  4283. 76.Sum of squares of prime numbers
  4284.  
  4285. Given an integer n, write a program to find the sum of squares of prime numbers upto and including n.
  4286.  
  4287. Include a function named sumSquarePrime that accepts an integer argument and returns an integer that corresponds to result. The function returns -1 if the input is less than zero or if the number is greater than 32767.
  4288.  
  4289. If the function returns -1, print “Invalid Input”.
  4290.  
  4291. Please note that 1 is neither prime nor composite.
  4292.  
  4293. Input and Output Format:
  4294.  
  4295. The input consists of an integer.
  4296. The output consists of an integer that corresponds to the sum of the squares of prime numbers.
  4297.  
  4298. Sample Input 1:
  4299. 10
  4300.  
  4301. Sample Ouput 1:
  4302. 87
  4303.  
  4304. Sample Input 2:
  4305. -8
  4306.  
  4307. Sample Output 2:
  4308. Invalid Input
  4309.  
  4310. #include<stdio.h>
  4311. #include<stdlib.h>
  4312. int sumSquarePrime(int);
  4313. int main(){
  4314. int number,result=0;
  4315. scanf("%d",&number);
  4316. result = sumSquarePrime(number);
  4317. if(result==-1)
  4318. printf("Invalid input");
  4319. else
  4320. printf("%d",result);
  4321. getchar();
  4322. getchar();
  4323. return 0;
  4324. }
  4325.  
  4326. int sumSquarePrime(int n){
  4327. int i,count=0,num,sum=0;
  4328. for(num = 1;num<=n;num++){
  4329. count=0;
  4330. for(i=1;i<=num;i++){
  4331. if(num%i==0)
  4332. count++;
  4333. }
  4334. if(count==2)
  4335. sum=sum+(num*num);
  4336.  
  4337. }
  4338. return sum;
  4339. }
  4340. 77.3/5 Number
  4341.  
  4342. Write a program to find whether the given number is a 3/5 Number.
  4343.  
  4344. A number is a 3/5 Number if the product of the digits in the number is divisible by 3 or 5.
  4345.  
  4346. Include a function named divisibleByThreeFive that accepts an integer argument and returns an integer. The function returns
  4347. 1. 1 if it is a 3/5 Number
  4348. 2. 0 if it is not a 3/5 Number
  4349. 3. -1 if it is a negative number
  4350.  
  4351. Input and Output Format:
  4352. Input consists of a single integer.
  4353. Output consists of a string.
  4354. Refer sample output for formatting specifications.
  4355.  
  4356.  
  4357. Sample Input 1:
  4358. 251
  4359.  
  4360. Sample Output 1:
  4361. yes
  4362.  
  4363. Sample Input 2:
  4364. 241
  4365.  
  4366. Sample Output 2:
  4367. no
  4368.  
  4369. Sample Input 3:
  4370. -9
  4371.  
  4372. Sample Output 3:
  4373. Invalid Input
  4374.  
  4375. #include<stdio.h>
  4376. #include<stdlib.h>
  4377. int divisibleByThreeFive(int);
  4378. int main(){
  4379. int number=0,result;
  4380. scanf("%d",&number);
  4381. result = divisibleByThreeFive(number);
  4382. if(result==1)
  4383. printf("yes");
  4384. else if(result==0)
  4385. printf("no");
  4386. else
  4387. printf("Invalid input");
  4388. getchar();
  4389. getchar();
  4390. return 0;
  4391. }
  4392.  
  4393. int divisibleByThreeFive(int n){
  4394. int res=1,i,rem=0,prod=1;
  4395. if(n<0)
  4396. res = -1;
  4397. else{
  4398. while(n!=0){
  4399. rem=n%10;
  4400. prod=prod*rem;
  4401. n=n/10;
  4402. }
  4403. if(prod%3==0 || prod%5==0)
  4404. res=1;
  4405. else
  4406. res=0;
  4407. }
  4408. return res;
  4409. }
  4410.  
  4411.  
  4412.  
  4413. 78.aboveAverageMarks
  4414. Read the question carefully and follow the input and output format.
  4415.  
  4416. Given an input array that represents the marks of students, find out the marks which are greater than or equal to average mark of all students.
  4417.  
  4418. Input and Output Format:
  4419. First line of input consists of n, the number of elements in the input array.
  4420. Next n lines correspond to the array elements. Output consist of an integer array.
  4421.  
  4422. 1) Print "Invalid array size" when size of the array is negative and terminate the program.
  4423. 2) Print "Invalid input" when there is any negative numbers available in the input array and terminate the program.
  4424.  
  4425. Include a function named aboveAverageMarks(int array[], int size) whose return type is void.
  4426. The output array is stored in a global variable named above_average.
  4427.  
  4428. Sample Input 1:
  4429. 5
  4430. 10
  4431. 20
  4432. 30
  4433. 40
  4434. 50
  4435. Sample Output 1:
  4436. 30
  4437. 40
  4438. 50
  4439.  
  4440. Sample Input 2:
  4441. 4
  4442. -3
  4443. Sample Output 2:
  4444. Invalid Input
  4445. #include<stdio.h>
  4446. #include<stdlib.h>
  4447. void aboveAverageMarks(int array[], int size);
  4448. int main(){
  4449. int size=0,input1[20],i=0;
  4450. scanf("%d",&size);
  4451. if(size<0){
  4452. printf("Invalid input");
  4453. getchar();
  4454. getchar();
  4455. exit(0);
  4456. }
  4457. for(i=0;i<size;i++){
  4458. scanf("%d",&input1[i]);
  4459. if(input1[i]<0){
  4460. printf("Invalid Input");
  4461. getchar();
  4462. getchar();
  4463. exit(0);
  4464. }
  4465. }
  4466. aboveAverageMarks(input1,size);
  4467. return 0;
  4468. }
  4469. void aboveAverageMarks(int array[], int size){
  4470. int i=0,j=0,avg=0,sum=0;
  4471. for(i=0;i<size;i++)
  4472. sum=sum+array[i];
  4473. avg=sum/size;
  4474. for(i=0;i<size;i++){
  4475. if(array[i]>=avg)
  4476. printf("%d\n",array[i]);
  4477. }
  4478. getchar();
  4479. getchar();
  4480. }
  4481. 79.changeNumber
  4482. Read the question carefully and follow the input and output format.
  4483.  
  4484. Tom needs to generate a new number from the given input with the following conditions.Consider Input is always a 3 digit number.
  4485.  
  4486. conditions:
  4487. (i) Middle digit comes first.
  4488. (ii) Last digit should come in middle
  4489. (iii) First digit should come as a last digit
  4490.  
  4491.  
  4492. Business rule:
  4493. 1. Print "Invalid input" if input is negative number.
  4494. 2. Print "Not a 3 digit number" if the given number is not a 3 digit number.
  4495. 158
  4496. 581
  4497. Include a function named changeNumber(int number) that returns an integer.
  4498.  
  4499. Input and Output Format:
  4500. Input consists of an integer.
  4501. Refer business rules and sample output for output format.
  4502.  
  4503. Sample Input 1:
  4504. 123
  4505. Sample Output 1:
  4506. 231
  4507.  
  4508.  
  4509. Sample Input 2:
  4510. 1234
  4511. Sample Output 2:
  4512. Not a 3 digit number
  4513. #include<stdio.h>
  4514. #include<stdlib.h>
  4515. int changeNumber(int n);
  4516. int main(){
  4517. int number=0,result;
  4518. scanf("%d",&number);
  4519. if(number<0)
  4520. printf("invalid input");
  4521. else if(number<100 || number>999)
  4522. printf("Not a three digit number");
  4523. else{
  4524. result = changeNumber(number);
  4525. printf("%d",result);
  4526. }
  4527. getchar();
  4528. getchar();
  4529. return 0;
  4530. }
  4531.  
  4532. int changeNumber(int n){
  4533. int rem=0,d1,d2,d3,i=1,temp=1,res=0;
  4534. do{
  4535. rem=n%10;
  4536. d3=rem;
  4537. n=n/10;
  4538. rem=n%10;
  4539. d2=rem;
  4540. n=n/10;
  4541. rem=n%10;
  4542. d1=rem;
  4543. }while(0);
  4544. do{
  4545. res=res+(d1*i);
  4546. i=i*10;
  4547. res=res+(d3*i);
  4548. i=i*10;
  4549. res=res+(d2*i);
  4550. }while(0);
  4551. return res;
  4552. }
  4553. 80.differentElements
  4554. Read the question carefully and follow the input and output format.
  4555.  
  4556. Given two input arrays find out the elements which are not common.
  4557.  
  4558. Input and Output Format:
  4559.  
  4560. First line of input consists of n, the number of elements. Next n lines correspond to the first array elements and the next n lines correspond to the second array elements. Output consist of an integer array, which contains the elements that are not common between the first and second array.
  4561.  
  4562. 1) Print Invalid array size when size of the array is a negative number and terminate the program.
  4563. 2) Print Invalid input when there is any negative numbers available in the input array and terminate the program.
  4564.  
  4565. Include a function named differentElements(int set1[], int set2[], int size) whose return type is void.
  4566. The output array is stored in a global variable named not_common.
  4567.  
  4568. Sample Input 1:
  4569. 5
  4570. 1 2 3 4 5
  4571. 5 6 4 8 7
  4572.  
  4573. Sample Output 1:
  4574. 1
  4575. 2
  4576. 3
  4577. 6
  4578. 8
  4579. 7
  4580.  
  4581. Sample Input 2:
  4582. 5
  4583. 1 4 8 9 4
  4584. -8
  4585. Sample Output 2:
  4586. Invalid input
  4587.  
  4588. #include<stdio.h>
  4589. #include<stdlib.h>
  4590. int not_common[20];
  4591. void differentElements(int set1[], int set2[], int size);
  4592. int main(){
  4593. int size=0,input1[20],input2[20],i=0;
  4594. scanf("%d",&size);
  4595. if(size<0){
  4596. printf("Invalid Array size");
  4597. getchar();
  4598. getchar();
  4599. exit(0);
  4600. }
  4601. for(i=0;i<size;i++){
  4602. scanf("%d",&input1[i]);
  4603. if(input1[i]<0){
  4604. printf("Invalid Input");
  4605. getchar();
  4606. getchar();
  4607. exit(0);
  4608. }
  4609. }
  4610. for(i=0;i<size;i++){
  4611. scanf("%d",&input2[i]);
  4612. if(input2[i]<0){
  4613. printf("Invalid Input");
  4614. getchar();
  4615. getchar();
  4616. exit(0);
  4617. }
  4618. }
  4619. differentElements(input1,input2,size);
  4620.  
  4621. return 0;
  4622. }
  4623. void differentElements(int set1[], int set2[], int size){
  4624. int i=0,j=0,k=0,flag=0,flag1=0;
  4625. for(i=0;i<size;i++){
  4626. flag=0;
  4627. for(j=0;j<size;j++){
  4628. if(set1[i]==set2[j])
  4629. flag=1;
  4630. }
  4631. if(flag==0){
  4632. not_common[k]=set1[i];
  4633. k++;
  4634. }
  4635. }
  4636. for(i=0;i<size;i++){
  4637. flag1=0;
  4638. for(j=0;j<size;j++){
  4639. if(set2[i]==set1[j])
  4640. flag1=1;
  4641. }
  4642. if(flag1==0){
  4643. not_common[k]=set2[i];
  4644. k++;
  4645. }
  4646. }
  4647. for(i=0;i<k;i++)
  4648. printf("%d\n",not_common[i]);
  4649. getchar();
  4650. getchar();
  4651. }
  4652.  
  4653. 81.registerAccountNumbers
  4654.  
  4655. Read the question carefully and follow the input and output format.
  4656.  
  4657. Given an array in which the elements are in xxxyy format, where first xxx digits represent the Branch code and the yy represents the account
  4658. id. Find out the No of accounts in the given branch code
  4659.  
  4660. Input and Output Format :
  4661. The first input n corresponds to the size of the array, the next n lines correspond to the elements of the array and the last line of the input corresponds to the branch code.
  4662. Output corresponds to the number of accounts in the given branch code
  4663. If the given branch code is not available, print 0.
  4664.  
  4665. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program
  4666. 2) Print "Invalid account Number" when there is any negative number available in the input array and terminate the program
  4667. 3) Print "Invalid branch code" when branch code is negative number and terminate the program
  4668.  
  4669. Include a function named registerAccountNumbers (int size, int account_numbers[], int branch_code) that returns the no of accounts
  4670.  
  4671. Sample Input 1 :
  4672. 6
  4673. 12345
  4674. 12370
  4675. 12324
  4676. 13355
  4677. 13333
  4678. 14575
  4679. 123
  4680.  
  4681. Sample Output 1 :
  4682. 3
  4683.  
  4684. Sample Input 2 :
  4685. -6
  4686.  
  4687. Sample Output 2:
  4688. Invalid array size
  4689.  
  4690. #include<stdio.h>
  4691. #include<stdlib.h>
  4692. int registerAccountNumbers (int size, int account_numbers[], int branch_code);
  4693. int main(){
  4694. int n=0,no_of_acc=0,input[30],i,flag=0,bcode=0;
  4695. scanf("%d",&n);
  4696. if(n<0){
  4697. printf("Invalid array size");
  4698. getchar();
  4699. getchar();
  4700. exit(0);
  4701. }
  4702. for(i=0;i<n;i++){
  4703. scanf("%d",&input[i]);
  4704. if(input[i]<0)
  4705. flag=1;
  4706. }
  4707. if(flag==1){
  4708. printf("Invalid account number");
  4709. getchar();
  4710. getchar();
  4711. exit(0);
  4712. }
  4713. scanf("%d",&bcode);
  4714. if(bcode<0){
  4715. printf("Invalid branch code");
  4716. getchar();
  4717. getchar();
  4718. exit(0);
  4719. }
  4720. no_of_acc=registerAccountNumbers(n,input,bcode);
  4721. printf("%d",no_of_acc);
  4722. getchar();
  4723. getchar();
  4724. return 0;
  4725. }
  4726. int registerAccountNumbers(int size, int account_numbers[], int branch_code){
  4727. int count=0,i,rem,temp=0,k=1,bcode=0,x=1;
  4728. for(i=0;i<size;i++){
  4729. temp=account_numbers[i];
  4730. bcode=temp/100;
  4731. if(bcode==branch_code)
  4732. count++;
  4733. }
  4734. return count;
  4735. }
  4736. 82.clearedStage1
  4737. Read the question carefully and follow the input and output format.
  4738.  
  4739. Given an integer array. The first index represents the Student id, Second index represents C-programming marks and the third index Represents SQL marks. Write a program to find the Ids of students who have cleared both C-programming and SQL.
  4740.  
  4741. Note :(1) The Pass Marks is >=70
  4742.  
  4743. Input and Output Format :
  4744.  
  4745. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of an integer array.
  4746.  
  4747. 1) Print "Invalid array size" when size of the array is negative and terminate the program.
  4748. 2) Print "Invalid input" when there is any negative number available in the input array and terminate the program.
  4749.  
  4750. Include a function named clearedStage1(int array[], int size) whose return type is void.
  4751. The output array is stored in a global variable named cleared.
  4752.  
  4753. Sample Input 1:
  4754. 9
  4755. 1
  4756. 25
  4757. 75
  4758. 3
  4759. 75
  4760. 80
  4761. 2
  4762. 75
  4763. 75
  4764.  
  4765. Sample Output 1:
  4766. 3
  4767. 2
  4768.  
  4769. Sample Input 2:
  4770. 6
  4771. 4
  4772. 25
  4773. -78
  4774.  
  4775. Sample Output 2:
  4776. Invalid input
  4777.  
  4778. #include<stdio.h>
  4779. #include<stdlib.h>
  4780. int registerAccountNumbers (int size, int account_numbers[], int branch_code);
  4781. int main(){
  4782. int n=0,no_of_acc=0,input[30],i,flag=0,bcode=0;
  4783. scanf("%d",&n);
  4784. if(n<0){
  4785. printf("Invalid array size");
  4786. getchar();
  4787. getchar();
  4788. exit(0);
  4789. }
  4790. for(i=0;i<n;i++){
  4791. scanf("%d",&input[i]);
  4792. if(input[i]<0)
  4793. flag=1;
  4794. }
  4795. if(flag==1){
  4796. printf("Invalid account number");
  4797. getchar();
  4798. getchar();
  4799. exit(0);
  4800. }
  4801. scanf("%d",&bcode);
  4802. if(bcode<0){
  4803. printf("Invalid branch code");
  4804. getchar();
  4805. getchar();
  4806. exit(0);
  4807. }
  4808. no_of_acc=registerAccountNumbers(n,input,bcode);
  4809. printf("%d",no_of_acc);
  4810. getchar();
  4811. getchar();
  4812. return 0;
  4813. }
  4814. int registerAccountNumbers(int size, int account_numbers[], int branch_code){
  4815. int count=0,i,rem,temp=0,k=1,bcode=0,x=1;
  4816. for(i=0;i<size;i++){
  4817. temp=account_numbers[i];
  4818. bcode=temp/100;
  4819. if(bcode==branch_code)
  4820. count++;
  4821. }
  4822. return count;
  4823. }
  4824. 83.findLargest
  4825. Read the question carefully and follow the input and output format.
  4826.  
  4827. Write a program to find the largest of the 3 given numbers.
  4828.  
  4829. Input and Output Format :
  4830. Input consists of 3 integers. Output consist of an integer that is the maximum.
  4831.  
  4832. Print "Number too large" when any of given input numbers is greater than 32767 .
  4833. Print "Number too small" when given input is a negative number.
  4834.  
  4835. Include a function named findLargest(int num1, int num2, int num3) whose return type is an integer, which is the largest.
  4836.  
  4837. Sample Input 1:
  4838. 2
  4839. 3
  4840. 4
  4841.  
  4842. Sample Output 1:
  4843. 4
  4844.  
  4845. Sample Input 2:
  4846. 98974
  4847.  
  4848. Sample Output 2:
  4849. Number too large
  4850.  
  4851. Sample Input 3:
  4852. -32767
  4853.  
  4854. Sample Output 3:
  4855. Number too small
  4856. 84.sumThreeLargest
  4857. Read the question carefully and follow the input and output format.
  4858.  
  4859. Write a program to find the sum of first ,second and third largest element in the given array.
  4860.  
  4861. Input and Output Format:
  4862. First line of input consists of n, the number of elements. Next n lines correspond to the array elements . Output consists of an Integer, the sum.
  4863.  
  4864. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program.
  4865. 2) Print "Invalid input" when there is any negative numbers available in the input array and terminate the program.
  4866.  
  4867. Include a function named sumThreeLargest(int array[], int n) whose return type is integer
  4868.  
  4869. Sample Input 1:
  4870. 8
  4871. 1
  4872. 2
  4873. 2
  4874. 3
  4875. 4
  4876. 5
  4877. 5
  4878. 4
  4879.  
  4880. Sample Output 1:
  4881. 12
  4882.  
  4883. Sample Input 2:
  4884. 4
  4885. 1
  4886. 2
  4887. -3
  4888. Sample Output 2:
  4889. Invalid input
  4890. #include<stdio.h>
  4891. #include<stdlib.h>
  4892. int sumThreeLargest(int array[], int n);
  4893. int main(){
  4894. int n=0,input[20]={0},i,largest;
  4895. scanf("%d",&n);
  4896. if(n<0){
  4897. printf("Invalid array size");
  4898. getchar();
  4899. getchar();
  4900. exit(0);
  4901. }
  4902. for(i=0;i<n;i++){
  4903. scanf("%d",&input[i]);
  4904. if(input[i]<0){
  4905. printf("Invalid input");
  4906. getchar();
  4907. getchar();
  4908. exit(0);
  4909. }
  4910. }
  4911.  
  4912. largest = sumThreeLargest(input,n);
  4913. printf("%d",largest);
  4914. getchar();
  4915. getchar();
  4916. return 0;
  4917. }
  4918. int sumThreeLargest(int array[], int n){
  4919. int i,j,k=0,temp=0;
  4920. for(i=0;i<n;i++){
  4921. for(j=i+1;j<n;){
  4922. if(array[i]==array[j]){
  4923. for(k=j;k<n;k++)
  4924. array[k]=array[k+1];
  4925. n--;
  4926. }
  4927. else
  4928. j++;
  4929. }
  4930. }
  4931. for(i=0;i<n;i++){
  4932. for(j=i+1;j<n;j++){
  4933. temp = array[i];
  4934. array[i] = array[j];
  4935. array[j] = temp;
  4936. }
  4937. }
  4938. return array[0]+array[1]+array[2];
  4939. }
  4940. 85.highestProfitYear
  4941. Read the question carefully and follow the input and output format.
  4942.  
  4943. An array holds information of a company profit margin and year. Find out the year in which highest revenue was earned. Assume the first index of array indicates year and the next index indicates the amount of money earned by the company and so on.
  4944.  
  4945. Input and Output Format :
  4946. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of an integer, which is the sum
  4947.  
  4948. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program.
  4949. 2) Print "Invalid input" when there is any negative number available in the input array and terminate the program.
  4950.  
  4951. Include a function named highestProfitYear(int revenue[],int size) whose return type is an integer, which is the year.
  4952.  
  4953. Sample Input 1:
  4954. 6
  4955. 2012
  4956. 10000
  4957. 2011
  4958. 5000
  4959. 2009
  4960. 4000
  4961.  
  4962. Sample Output 1:
  4963. 2012
  4964.  
  4965. Sample Input 2:
  4966. 8
  4967. 2015
  4968. 89745
  4969. -2015
  4970.  
  4971. Sample Output 2:
  4972. Invalid input
  4973. #include<stdio.h>
  4974. #include<stdlib.h>
  4975. int highestProfitYear(int revenue[],int size);
  4976. int main(){
  4977. int n=0,input[20]={0},i,highest;
  4978. scanf("%d",&n);
  4979. if(n<0){
  4980. printf("Invalid array size");
  4981. getchar();
  4982. getchar();
  4983. exit(0);
  4984. }
  4985. for(i=0;i<n;i++){
  4986. scanf("%d",&input[i]);
  4987. if(input[i]<0){
  4988. printf("Invalid input");
  4989. getchar();
  4990. getchar();
  4991. exit(0);
  4992. }
  4993. }
  4994.  
  4995. highest = highestProfitYear(input,n);
  4996. printf("%d",highest);
  4997. getchar();
  4998. getchar();
  4999. return 0;
  5000. }
  5001. int highestProfitYear(int revenue[],int size){
  5002. int i,j,k=0,highest=0,max=0;
  5003. for(i=1;i<size;i=i+2){
  5004. if(revenue[i]>max){
  5005. max=revenue[i];
  5006. highest=revenue[i-1];
  5007. }
  5008. }
  5009.  
  5010. return highest;
  5011. }
  5012.  
  5013. 86.countNoOfConnections
  5014. Read the question carefully and follow the input and output format.
  5015.  
  5016. Given an input array, the elements are of format XYYY . where X represents the connection type. YYY represents the connection id.
  5017.  
  5018. If X is 2 -> means 2G connection
  5019. If X is 3 -> means 3G connection
  5020. If X is 4 -> means 4G connection
  5021. You need to find the number of type of connections.
  5022.  
  5023. Note:
  5024. If a particular connection type (starting with 2 or 3 or 4) is not available represent with zero in the corresponding position.
  5025.  
  5026. Include a function named countNoOfConnections(int connection_list[],int no) that returns the number of types of connections
  5027.  
  5028. Business Rules :
  5029. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program.
  5030. 2) Print "Invalid connection" when there is any negative number available in the input array and terminate the program
  5031.  
  5032. Input and Output Format :
  5033. First line of input corresponds to n, next n lines corresponds to the elements of the array
  5034. Output consists of the the number of type of connections. [1st line of the output corresponds to the number of 2G connections, 2nd line corresponds to the number of 3G connections and 3rd line corresponds to the number of 4G connections]
  5035.  
  5036. Sample Input 1 :
  5037. 5
  5038. 2333
  5039. 3101
  5040. 2102
  5041. 4567
  5042. 3123
  5043.  
  5044. Sample Output 1:
  5045. 2
  5046. 2
  5047. 1
  5048.  
  5049. Sample Input 2 :
  5050. 2
  5051. -2234
  5052.  
  5053.  
  5054. Sample Output 2:
  5055. Invalid connection
  5056.  
  5057. #include<stdio.h>
  5058. #include<stdlib.h>
  5059. void countNoOfConnections(int connection_list[],int no);
  5060. int main(){
  5061. int n=0,input[20]={0},i;
  5062. scanf("%d",&n);
  5063. if(n<0){
  5064. printf("Invalid array size");
  5065. getchar();
  5066. getchar();
  5067. exit(0);
  5068. }
  5069. for(i=0;i<n;i++){
  5070. scanf("%d",&input[i]);
  5071. if(input[i]<0){
  5072. printf("Invalid Connection");
  5073. getchar();
  5074. getchar();
  5075. exit(0);
  5076. }
  5077. }
  5078.  
  5079. countNoOfConnections(input,n);
  5080.  
  5081. getchar();
  5082. getchar();
  5083. return 0;
  5084. }
  5085. void countNoOfConnections(int connection_list[],int no){
  5086. int i,j,k=0,temp=0,x=0,two=0,three=0,four=0,other=1,out[10]={0};
  5087. for(i=0;i<no;i++){
  5088. temp=connection_list[i];
  5089. x=temp/1000;
  5090.  
  5091. if(x==2)
  5092. two++;
  5093. else if(x==3)
  5094. three++;
  5095. else if(x==4)
  5096. four++;
  5097. else
  5098. other=0;
  5099. }
  5100. out[0]=two;
  5101. out[1]=three;
  5102. out[2]=four;
  5103.  
  5104. for(i=0;i<3;i++)
  5105. printf("%d\n",out[i]);
  5106. }
  5107. 87.Sum of positive numbers in Array
  5108.  
  5109. Write a program to find the sum of positive numbers in an array.
  5110.  
  5111. Include a function named addPositives that accepts 2 arguments and returns an int. The first argument is the input array and the second argument is an int that corresponds to the size of the array. The function returns the sum of the positive numbers in the array.
  5112.  
  5113. If the size of the array is negative, print “Invalid Input” and terminate the program..
  5114.  
  5115. Input and Output Format:
  5116. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  5117. Assume that the maximum size of the array is 20.
  5118.  
  5119. Sample Input 1:
  5120. 5
  5121. 3
  5122. 5
  5123. -2
  5124. 6
  5125. -6
  5126.  
  5127.  
  5128. Sample Output 1:
  5129. 14
  5130.  
  5131. Sample Input 2:
  5132. -5
  5133.  
  5134. Sample Output 2:
  5135. Invalid Input
  5136. #include<stdio.h>
  5137. #include<stdlib.h>
  5138. int addPositives(int array[],int n);
  5139. int main(){
  5140. int n=0,input[20]={0},i,sum;
  5141. scanf("%d",&n);
  5142. if(n<0){
  5143. printf("Invalid input");
  5144. getchar();
  5145. getchar();
  5146. exit(0);
  5147. }
  5148. for(i=0;i<n;i++)
  5149. scanf("%d",&input[i]);
  5150.  
  5151.  
  5152.  
  5153. sum=addPositives(input,n);
  5154. printf("%d",sum);
  5155. getchar();
  5156. getchar();
  5157. return 0;
  5158. }
  5159. int addPositives(int array[],int n){
  5160. int i,j,sum=0;
  5161. for(i=0;i<n;i++){
  5162. if(array[i]>0)
  5163. sum=sum+array[i];
  5164. }
  5165. return sum;
  5166.  
  5167. }
  5168. 88.Find Index
  5169.  
  5170. Write a program to find the index of a particular number in a given input array.
  5171.  
  5172. Include a function named findIndex that accepts 3 arguments and returns an int. The first argument is the input array, the second argument is an int that corresponds to the size of the array and the third argument is the element to be searched for. The function returns the corresponding index if the search element is present in the array and returns -1 if the search element is not present in the array.
  5173.  
  5174. If the size of the array is negative or if any element in the array is negative, print “Invalid Input” and terminate the program.
  5175.  
  5176.  
  5177. Input and Output Format:
  5178. Input consists of n+2 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array. The last integer corresponds to the element whose count needs to be found.
  5179. Output consists of an integer that corresponds to the index of the search element if it is present.
  5180. Else, print 'not found'.
  5181.  
  5182. Refer sample output for formatting specifications.
  5183.  
  5184. Assume that the maximum number of elements in the array is 20 and that all elements in the array are unique.
  5185.  
  5186. Sample Input 1:
  5187. 8
  5188. 2
  5189. 1
  5190. 3
  5191. 8
  5192. 6
  5193. 12
  5194. 10
  5195. 19
  5196. 8
  5197.  
  5198. Sample Output 1:
  5199. 3
  5200.  
  5201. Sample Input 2:
  5202. 8
  5203. 2
  5204. 1
  5205. 3
  5206. 8
  5207. 6
  5208. 12
  5209. 10
  5210. 19
  5211. 80
  5212.  
  5213. Sample Output 2:
  5214. not found
  5215.  
  5216. Sample Input 3:
  5217. -5
  5218.  
  5219. Sample Output 3:
  5220. Invalid Input
  5221.  
  5222. Sample Input 4:
  5223. 5
  5224. 23
  5225. 2
  5226. -200
  5227.  
  5228. Sample Output 4:
  5229. Invalid Input
  5230.  
  5231. #include<stdio.h>
  5232. #include<stdlib.h>
  5233. int cricketer[20];
  5234. int findIndex(int,int[],int);
  5235. int main(){
  5236. int n=0,index=0,input[30],i,search_element=0;
  5237. scanf("%d",&n);
  5238. if(n<0){
  5239. printf("Invalid Input");
  5240. getchar();
  5241. getchar();
  5242. exit(0);
  5243. }
  5244. for(i=0;i<n;i++){
  5245. scanf("%d",&input[i]);
  5246. if(input[i]<0){
  5247. printf("Invalid Input");
  5248. getchar();
  5249. getchar();
  5250. exit(0);
  5251. }
  5252. }
  5253. scanf("%d",&search_element);
  5254. index = findIndex(n,input,search_element);
  5255. if(index==-1)
  5256. printf("not found");
  5257. else
  5258. printf("%d",index);
  5259. getchar();
  5260. getchar();
  5261. return 0;
  5262. }
  5263. int findIndex( int size,int array[], int search){
  5264. int index,i,f=0;
  5265. for(i=1 ; i<size ; i=i+2)
  5266. {
  5267. if(array[i]==search){
  5268. f=1;
  5269. index = array[i-1];
  5270. break;
  5271. }
  5272. }
  5273. if(f==1)
  5274. return index;
  5275. else
  5276. return -1;
  5277. }
  5278. 89.Store Consequtives
  5279.  
  5280. Write a program to obtain a new array that contains the consequtive values of the given input array. The output array is named as output1.
  5281.  
  5282. Include a function named storeConsequtives that accepts 2 arguments and its return type is void. The first argument is the input array and the second argument is an int that corresponds to the size of the array . The output array is stored in a global variable named output1.
  5283.  
  5284. If the size of the array is negative or if any of the elements in the array are negative , print “Invalid Input” and terminate the program.
  5285.  
  5286. Input and Output Format:
  5287. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  5288. Output consists of an integer array.
  5289. Refer sample output for formatting specifications.
  5290.  
  5291. Assume that the maximum number of elements in the array is 20.
  5292.  
  5293. Sample Input 1:
  5294. 4
  5295. 2
  5296. 5
  5297. 1
  5298. 4
  5299.  
  5300. Sample Output 1:
  5301. 3
  5302. 6
  5303. 2
  5304. 5
  5305.  
  5306. Sample Input 2:
  5307. -5
  5308.  
  5309. Sample Output 2:
  5310. Invalid Input
  5311.  
  5312.  
  5313. #include<stdio.h>
  5314. #include<stdlib.h>
  5315. int output1[20];
  5316. void storeConsequtives(int numbers[], int size);
  5317. int main(){
  5318. int size=0,input1[20],i=0;
  5319. scanf("%d",&size);
  5320. if(size<0){
  5321. printf("Invalid input");
  5322. getchar();
  5323. getchar();
  5324. exit(0);
  5325. }
  5326. for(i=0;i<size;i++){
  5327. scanf("%d",&input1[i]);
  5328. if(input1[i]<0){
  5329. printf("Invalid Input");
  5330. getchar();
  5331. getchar();
  5332. exit(0);
  5333. }
  5334. }
  5335. storeConsequtives(input1,size);
  5336. return 0;
  5337. }
  5338. void storeConsequtives(int numbers[], int size){
  5339. int i=0,j=0;
  5340. for(i=0;i<size;i++){
  5341. output1[i]=numbers[i]+1;
  5342. printf("%d\n",output1[i]);
  5343. }
  5344. getchar();
  5345. getchar();
  5346. }
  5347. 90.findGrade
  5348. Read the question carefully and follow the input and output format.
  5349.  
  5350. In a school examination the result of students are published in the form of an array where first index is the student id and the second index is the total marks in mathematics third index is student id and fourth index is total marks in mathematics and so on... Write a method that assigns the student id as the key and the grade in mathematics as the value to the output array based on the following conditions:
  5351.  
  5352. If(Marks >=90 ) : 1
  5353. If(Marks >=80 and <90 ) : 2
  5354. If(Marks >=70 and <80) : 3
  5355. If(Marks <70 ) : 0
  5356.  
  5357. Hint: Array size is always is even.
  5358.  
  5359. Input and Output Format :
  5360.  
  5361. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of an integer array.
  5362. 1) Print "Invalid array size" when size of the array is negative and terminate the program.
  5363. 2) Print "Invalid input" when there is any negative numbers available in the input array and terminate the program.
  5364.  
  5365. Include a function named findGrade(int array[], int size) whose return type is void.
  5366. The output array is stored in a global variable named grade.
  5367.  
  5368. Sample Input 1:
  5369. 10
  5370. 1
  5371. 65
  5372. 2
  5373. 74
  5374. 3
  5375. 86
  5376. 4
  5377. 95
  5378. 6
  5379. 69
  5380. Sample Output 1:
  5381. 1
  5382. 0
  5383. 2
  5384. 3
  5385. 3
  5386. 2
  5387. 4
  5388. 1
  5389. 6
  5390. 0
  5391.  
  5392. Sample Input 2:
  5393. 4
  5394. -3
  5395. Sample Output 2:
  5396. Invalid input
  5397. #include<stdio.h>
  5398. #include<stdlib.h>
  5399. int grade[20];
  5400. void findGrade(int array[], int size);
  5401. int main(){
  5402. int size=0,input1[20],i=0;
  5403. scanf("%d",&size);
  5404. if(size<0){
  5405. printf("Invalid array size");
  5406. getchar();
  5407. getchar();
  5408. exit(0);
  5409. }
  5410. for(i=0;i<size;i++){
  5411. scanf("%d",&input1[i]);
  5412. if(input1[i]<0){
  5413. printf("Invalid Input");
  5414. getchar();
  5415. getchar();
  5416. exit(0);
  5417. }
  5418. }
  5419. findGrade(input1,size);
  5420. return 0;
  5421. }
  5422. void findGrade(int array[], int size){
  5423. int i=0,j=0;
  5424. for(i=1;i<size;i=i+2){
  5425. if(array[i]>=90){
  5426. grade[i-1]=array[i-1];
  5427. grade[i]=1;
  5428. }
  5429. else if(array[i]>=80 && array[i]<90){
  5430. grade[i-1]=array[i-1];
  5431. grade[i]=2;
  5432. }
  5433. else if(array[i]>=70 && array[i]<80){
  5434. grade[i-1]=array[i-1];
  5435. grade[i]=3;
  5436. }
  5437. else{
  5438. grade[i-1]=array[i-1];
  5439. grade[i]=0;
  5440. }
  5441. }
  5442. for(i=0;i<size;i++)
  5443. printf("%d\n",grade[i]);
  5444. getchar();
  5445. getchar();
  5446. }
  5447. 91.Odd Even Average
  5448.  
  5449. The Owner of a block visited the Layout and found that he has some plot numbers of his own and some are odd numbers and some are even numbers. He is maintaining the details in a file in the system. For the password protection our owner has followed one formula. He calculated the sum of his even numbers plot and sum of odd numbers plot and found the average of those two and he used that average as his password for the details file. Find the password that our owner has arrived.
  5450.  
  5451. Include a function named avgOddEvenSum that accepts 2 arguments and returns a float. The first argument is the input array and the second argument is an int that corresponds to the size of the array. The function returns a float that corresponds to the average of the array.
  5452.  
  5453. If the size of the array is negative or if any element in the array is negative , print “Invalid Input” and terminate the program.
  5454.  
  5455. Input and Output Format:
  5456. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  5457. Output consists of a floating point number that corresponds to the average. It is displayed correct to 2 decimal places.
  5458. Assume that the maximum size of the array is 20.
  5459.  
  5460. Sample Input 1:
  5461. 5
  5462. 1
  5463. 2
  5464. 3
  5465. 4
  5466. 5
  5467.  
  5468. Sample Output 1:
  5469. 7.50
  5470.  
  5471. Sample Input 2:
  5472. -5
  5473.  
  5474. Sample Output 2:
  5475. Invalid Input
  5476.  
  5477. Sample Input 3:
  5478. 5
  5479. 23
  5480. 2
  5481. -5
  5482.  
  5483. Sample Output 3:
  5484. Invalid Input
  5485.  
  5486. #include<stdio.h>
  5487. #include<stdlib.h>
  5488. float avgOddEvenSum(int[],int);
  5489. int main(){
  5490. int n=0,i,flag=0,input[20];
  5491. float avg=0.0f;
  5492. scanf("%d",&n);
  5493. if(n<0){
  5494. printf("Invalid input");
  5495. getchar();
  5496. getchar();
  5497. exit(0);
  5498. }
  5499. for(i=0;i<n;i++){
  5500. scanf("%d",&input[i]);
  5501. if(input[i]<0)
  5502. flag=1;
  5503. }
  5504. if(flag==1){
  5505. printf("Invalid input");
  5506. getchar();
  5507. getchar();
  5508. exit(0);
  5509. }
  5510. avg = avgOddEvenSum(input,n);
  5511. printf("%0.2f",avg);
  5512. getchar();
  5513. getchar();
  5514. return 0;
  5515. }
  5516. float avgOddEvenSum(int array[],int size){
  5517. float avg;
  5518. int i,sumodd=0,sumeven=0;
  5519. for(i=0;i<size;i++){
  5520. if(array[i]%2==0)
  5521. sumeven=sumeven+array[i];
  5522. else
  5523. sumodd=sumodd+array[i];
  5524. }
  5525. avg = float(sumeven+sumodd)/2.0f;
  5526. return avg;
  5527. }
  5528. 92.convertToBinary
  5529. Read the question carefully and follow the input and output format.
  5530.  
  5531. Kate is a military officer. He needs to send top-secret code to the other soldiers in a different place. He need to encrypt it. We need to write a function to convert the given decimal number to the corresponding binary number.
  5532.  
  5533. Input consist of single integer. Output consists of binary number.
  5534.  
  5535. 1) Print "Number too small" when input is negative.
  5536. 2) Print "Number too large" when input value is greater than 100.
  5537.  
  5538. Include a function named convertToBinary(int num) whose return type is void.
  5539.  
  5540. Sample Input 1:
  5541. 12
  5542.  
  5543. Sample Output 1:
  5544. 1100
  5545.  
  5546. Sample Input 2:
  5547. 101
  5548.  
  5549. Sample Output 2:
  5550. Number too large
  5551.  
  5552.  
  5553. #include<stdio.h>
  5554. #include<stdlib.h>
  5555. void convertToBinary(int num);
  5556. int main(){
  5557. int number=0;
  5558. scanf("%d",&number);
  5559. if(number<0)
  5560. printf("Number too small");
  5561. else if(number>100)
  5562. printf("Number too large");
  5563. else
  5564. convertToBinary(number);
  5565. return 0;
  5566. }
  5567. void convertToBinary(int num){
  5568. int a[20],i=0;
  5569. while(num>0)
  5570. {
  5571. a[i]=num%2;
  5572. i++;
  5573. num=num/2;
  5574. }
  5575. for(int j=i-1;j>=0;j--)
  5576. printf("%d",a[j]);
  5577. getchar();
  5578. getchar();
  5579. }
  5580.  
  5581. 93.reverseNumber
  5582. Read the question carefully and follow the input and output format.
  5583.  
  5584. Write a program to find the reverse of a given input integer
  5585.  
  5586. Input and Output Format :
  5587. Input consists of an integer, n. Output consist of the reverse of the number n.
  5588.  
  5589. Print "Number too large" when the given input number is greater than 32767
  5590. Print "Number too small" when the given input numbers is a negative number.
  5591.  
  5592. Include a function named reverseNumber(int num) whose return type is integer, the reverse of n.
  5593.  
  5594. Sample Input 1:
  5595. 1234
  5596.  
  5597. Sample Output 1:
  5598. 4321
  5599.  
  5600. Sample Input 2:
  5601. 326357
  5602.  
  5603. Sample Output 2:
  5604. Number too large
  5605. #include<stdio.h>
  5606. #include<stdlib.h>
  5607. int reverseNumber(int num);
  5608. int main(){
  5609. int number=0,revnumber=0;
  5610. scanf("%d",&number);
  5611. if(number<0)
  5612. printf("Number too small");
  5613. else if(number>32767)
  5614. printf("Number too large");
  5615. else{
  5616. revnumber = reverseNumber(number);
  5617. printf("%d",revnumber);
  5618. }
  5619. getchar();
  5620. getchar();
  5621. return 0;
  5622. }
  5623. int reverseNumber(int num){
  5624. int reverse=0;
  5625. while (num != 0)
  5626. {
  5627. reverse = reverse * 10;
  5628. reverse = reverse + num%10;
  5629. num=num/10;
  5630. }
  5631. return reverse;
  5632. }
  5633. 94.Sum of Prime Cubes
  5634.  
  5635. Given an input integer n, write a program to find the sum of the cubes of the prime numbers upto n. (including n)
  5636.  
  5637. Please note that 1 is neither prime nor composite.
  5638.  
  5639. Include a function named sumCubeOfPrime that accepts an integer argument and returns an integer. The function returns -1 if the input is a negative number or if it is greater than 3000.
  5640.  
  5641. If the function returns -1, print Invalid Input.
  5642.  
  5643. Input and Output Format:
  5644. Input consists of a single integer.
  5645. Output consists of a single integer.
  5646. Refer sample output for formatting specifications.
  5647.  
  5648.  
  5649. Sample Input 1:
  5650. 5
  5651.  
  5652. Sample Output 1:
  5653. 160
  5654.  
  5655. Sample Input 2:
  5656. -241
  5657.  
  5658. Sample Output 2:
  5659. Invalid Input
  5660.  
  5661. Sample Input 3:
  5662. 50000
  5663.  
  5664. Sample Output 3:
  5665. Invalid Input
  5666.  
  5667. #include<stdio.h>
  5668. #include<stdlib.h>
  5669. int sumCubeOfPrime(int);
  5670. int main(){
  5671. int number,result=0;
  5672. scanf("%d",&number);
  5673. result = sumCubeOfPrime(number);
  5674. if(result==-1)
  5675. printf("Invalid input");
  5676. else
  5677. printf("%d",result);
  5678. getchar();
  5679. getchar();
  5680. return 0;
  5681. }
  5682.  
  5683. int sumCubeOfPrime(int n){
  5684. int i,count=0,num,sum=0;
  5685. if(n<0 || n>3000)
  5686. sum=-1;
  5687. else{
  5688.  
  5689. for(num = 1;num<=n;num++){
  5690. count=0;
  5691. for(i=1;i<=num;i++){
  5692. if(num%i==0)
  5693. count++;
  5694. }
  5695. if(count==2)
  5696. sum=sum+(num*num*num);
  5697.  
  5698. }
  5699. }
  5700. return sum;
  5701. }
  5702. 95.Negative Elements
  5703.  
  5704. Write a program to remove all the negative elements of the input array , sort the positive elements and stores them in an output array .
  5705.  
  5706. Include a function named eliminateNegatives that accepts 2 arguments and its return type is void. The first argument is the input array and the second argument is an int that corresponds to the size of the array. The output array is stored in a global variable named output1 and the size of the output array is stored in a global variable named output2.
  5707.  
  5708. If the size of the array is negative , print “Invalid Input” and terminate the program.
  5709.  
  5710. Input and Output Format:
  5711. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  5712. Output consists of an integer array.
  5713. Refer sample output for formatting specifications.
  5714.  
  5715. Assume that the maximum number of elements in the array is 20.
  5716.  
  5717. Sample Input 1:
  5718. 8
  5719. 1
  5720. 6
  5721. 3
  5722. 5
  5723. -6
  5724. 8
  5725. -15
  5726. 9
  5727.  
  5728. Sample Output 1:
  5729. 1
  5730. 3
  5731. 5
  5732.  
  5733. 6
  5734. 8
  5735. 9
  5736.  
  5737.  
  5738. Sample Input 2:
  5739. -5
  5740.  
  5741. Sample Output 2:
  5742. Invalid Input
  5743. #include<stdio.h>
  5744. #include<stdlib.h>
  5745. int output1[20];
  5746. void eliminateNegatives(int[],int);
  5747. int main(){
  5748. int size=0,input1[20],i=0;
  5749. scanf("%d",&size);
  5750. if(size<0){
  5751. printf("Invalid input");
  5752. getchar();
  5753. getchar();
  5754. exit(0);
  5755. }
  5756. for(i=0;i<size;i++)
  5757. scanf("%d",&input1[i]);
  5758.  
  5759. eliminateNegatives(input1,size);
  5760.  
  5761. return 0;
  5762. }
  5763. void eliminateNegatives(int array[],int size){
  5764. int i=0,k=0,j=0,temp=0;
  5765. for(i=0;i<size;i++){
  5766. if(array[i]>0){
  5767. output1[k]=array[i];
  5768. k++;
  5769. }
  5770. }
  5771. for(i=0;i<k;i++){
  5772. for(j=i+1;j<k;j++){
  5773. if(output1[i]>output1[j]){
  5774. temp = output1[i];
  5775. output1[i]=output1[j];
  5776. output1[j]=temp;
  5777. }
  5778. }
  5779. }
  5780. for(i=0;i<k;i++)
  5781. printf("%d\n",output1[i]);
  5782. getchar();
  5783. getchar();
  5784. }
  5785.  
  5786.  
  5787. 96.Savings Calculation
  5788. Jim got salary for this month and he spends 50% of his salary for food and 20% of his salary for travel. If the number of days he worked is 31 he gets a bonus of Rs.500. Write a program to find how much he can save in his pocket after spending all these?
  5789.  
  5790. Include a function named calculateSavings that accepts 2 integer arguments and returns a float. The first integer corresponds to Jim's basic salary and the second integer corresponds to the number of days Jim has worked. The function returns a float that corresponds to the amount that Jim could save.
  5791.  
  5792. Print Invalid Input and terminate the program in the following cases:
  5793. 1. Basic salary is greater than 9000
  5794. 2. Number of working days is greater than 31
  5795. 3. Basic salary is negative
  5796. 4. Number of working days is negative
  5797.  
  5798. Input and Output Format:
  5799. Input consists of 2 integers. The first integer corresponds to Jim's basic salary and the second integer corresponds to the number of days he has worked.
  5800. Output consists of a single float that corresponds to Jim's savings. Jim's savings is displayed correct to 2 decimal places.
  5801.  
  5802. Sample Input 1:
  5803. 7000
  5804. 30
  5805.  
  5806. Sample Output 1:
  5807. 2100 .00
  5808.  
  5809.  
  5810. Sample Input 2:
  5811. 50000
  5812.  
  5813.  
  5814. Sample Output 2:
  5815. Invalid Input
  5816.  
  5817. #include<stdio.h>
  5818. #include<stdlib.h>
  5819. float calculateSavings(int,int);
  5820. int main(){
  5821. int basic=0,days=0;
  5822. float save=0.0f;
  5823. scanf("%d%d",&basic,&days);
  5824. if(basic>9000 || days>31 || basic<0 || days<0){
  5825. printf("Invalid input");
  5826. getchar();
  5827. getchar();
  5828. exit(0);
  5829. }
  5830. save = calculateSavings(basic,days);
  5831. printf("%0.2f",save);
  5832. getchar();
  5833. getchar();
  5834. return 0;
  5835. }
  5836.  
  5837. float calculateSavings(int basic,int days){
  5838. float spent=0.0f,savings=0.0f;
  5839. spent=(float)(basic*70)/100;
  5840. if(days==31)
  5841. savings = basic+500-spent;
  5842. else
  5843. savings = basic-spent;
  5844. return savings;
  5845. }
  5846.  
  5847. 97.studentMarks
  5848. Read the question carefully and follow the input and output format.
  5849.  
  5850. The Given input is of the format XXXYY , where XXX is Id , YY is marks. Write a code to display the id and marks separately as given in the output formats. [Refer sample input and output]
  5851.  
  5852. Input and Output Format :
  5853. Input consists of a number. Refer sample output for output format.
  5854.  
  5855. Print "Number too large" when any of given input numbers is greater than 32767 .
  5856. Print "Number too small" when given input is a negative number.
  5857.  
  5858. Include a function named studentMarks(int number) whose return type is void.
  5859.  
  5860. Sample Input 1:
  5861. 12345
  5862.  
  5863. Sample Output 1:
  5864. 123
  5865. 45
  5866.  
  5867. Sample Input 2:
  5868. -13
  5869.  
  5870. Sample Output 2:
  5871. Invalid input
  5872.  
  5873. #include<stdio.h>
  5874. #include<stdlib.h>
  5875. void studentMarks(int number);
  5876. int main(){
  5877. int number=0,result;
  5878. scanf("%d",&number);
  5879. if(number<0)
  5880. printf("number too small");
  5881. else if(number>32767)
  5882. printf("number too large");
  5883. else
  5884. studentMarks(number);
  5885. getchar();
  5886. getchar();
  5887. return 0;
  5888. }
  5889.  
  5890. void studentMarks(int number){
  5891. int id=0,mark=0,rem=0,i=1,flag=1,j=1;
  5892. while(number!=0){
  5893. if(flag<=2){
  5894. rem=number%10;
  5895. mark=mark+(rem*i);
  5896. i=i*10;
  5897. number=number/10;
  5898. flag++;
  5899. }
  5900. else{
  5901. rem=number%10;
  5902. id=id+(rem*j);
  5903. j=j*10;
  5904. number=number/10;
  5905. flag++;
  5906. }
  5907. }
  5908. printf("%d\n%d",id,mark);
  5909. getchar();
  5910. getchar();
  5911. }
  5912. 98.maximumSum
  5913. Read the question carefully and follow the input and output format.
  5914.  
  5915. Given an Integer array, find out sum of Even and odd Numbers individually and find the maximum.
  5916.  
  5917. Input and Output Format :
  5918. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of maximum of odd and even sum.
  5919.  
  5920. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program.
  5921. 2) Print "Invalid input" when there is any negative numbers available in the input array and terminate the program.
  5922.  
  5923.  
  5924. Include a function named maximumSum(int numbers[], int size) whose return type is an integer,.
  5925.  
  5926. Sample Input 1:
  5927. 5
  5928. 12
  5929. 13
  5930. 14
  5931. 15
  5932. 16
  5933.  
  5934. Sample Output 1:
  5935. 42
  5936.  
  5937. Sample Input 2:
  5938. -13
  5939.  
  5940. Sample Output 2:
  5941. Invalid array size
  5942.  
  5943. #include<stdio.h>
  5944. #include<stdlib.h>
  5945. int maximumSum(int[],int);
  5946. int main(){
  5947. int n=0,i,flag=0,input[20],max=0;
  5948. scanf("%d",&n);
  5949. if(n<0){
  5950. printf("Invalid array size");
  5951. getchar();
  5952. getchar();
  5953. exit(0);
  5954. }
  5955. for(i=0;i<n;i++){
  5956. scanf("%d",&input[i]);
  5957. if(input[i]<0)
  5958. flag=1;
  5959. }
  5960. if(flag==1){
  5961. printf("Invalid input");
  5962. getchar();
  5963. getchar();
  5964. exit(0);
  5965. }
  5966. max = maximumSum(input,n);
  5967. printf("%d",max);
  5968. getchar();
  5969. getchar();
  5970. return 0;
  5971. }
  5972. int maximumSum(int numbers[], int size){
  5973. int i=0,max=0,evensum=0,oddsum=0;
  5974. for(i=0;i<size;i++){
  5975. if(numbers[i]%2==0)
  5976. evensum = evensum + numbers[i];
  5977. else
  5978. oddsum = oddsum + numbers[i];
  5979. if(evensum>oddsum)
  5980. max = evensum;
  5981. else
  5982. max=oddsum;
  5983. }
  5984. return max;
  5985. }
  5986.  
  5987. 99.newNumber
  5988. Read the question carefully and follow the input and output format.
  5989.  
  5990. Write a program to find the difference between consecutive digits in the given input integer and display it.
  5991.  
  5992. Input and Output Format:
  5993. Input consists of an integer and output the difference between the consecutive digits.
  5994.  
  5995. Print "Number too small" if the number is less than 0
  5996. Print "Number too large" if the number is greater than 32767
  5997.  
  5998. Include a function named newNumber(int number) that returns a integer
  5999.  
  6000. Sample Input 1:
  6001. 1325
  6002. Sample Output 1:
  6003. 213
  6004.  
  6005. Sample Input 2:
  6006. -13
  6007. Sample Output 2:
  6008. Number too small
  6009.  
  6010. #include<stdio.h>
  6011. #include<stdlib.h>
  6012. int newNumber(int number);
  6013. int main(){
  6014. int num=0,new_num=0;
  6015. scanf("%d",&num);
  6016. if(num>32767)
  6017. printf("Number too large");
  6018. else if(num<0)
  6019. printf("Number too small");
  6020. else{
  6021. new_num=newNumber(num);
  6022. printf("%d",new_num);
  6023. }
  6024. getchar();
  6025. getchar();
  6026. return 0;
  6027. }
  6028. int newNumber(int number){
  6029. int rem,i=1,rem1=0,diff=0,digit=0;
  6030. while(number>10){
  6031. rem=number%10;
  6032. number=number/10;
  6033. rem1=number%10;
  6034. if(rem>rem1)
  6035. diff=rem-rem1;
  6036. else
  6037. diff=rem1-rem;
  6038. digit=digit+(diff*i);
  6039. i=i*10;
  6040. }
  6041. return digit;
  6042. }
  6043.  
  6044. 100.nonWorkingDoctors
  6045. Read the question carefully and follow the input and output format.
  6046.  
  6047. A doctor survey results information is stored in 2 arrays. First array represents all doctors ids (working and non -working both). Second array represents only working doctor's id . Please find the doctor ids who are not working .
  6048.  
  6049. Input and Output Format :
  6050. First line of input corresponds to n1, the size of first array and next n1 lines correspond to the elements of the first array. The next line corresponds to n2, the size of second array and next n2 lines correspond to the elements of the second array
  6051. Output is the id's of doctor who are not working
  6052.  
  6053. Print "Invalid array size" when size of the array is a negative number and terminate the program
  6054. Print "Invalid id" when there is any negative numbers available in the input array and terminate the program.
  6055.  
  6056. Include a function named nonWorkingDoctors(int total[],int working[],int n,int m) whose return type is void.
  6057.  
  6058. Sample Input 1:
  6059. 7
  6060. 7
  6061. 2
  6062. 3
  6063. 4
  6064. 5
  6065. 6
  6066. 1
  6067. 3
  6068. 3
  6069. 4
  6070. 5
  6071. Sample Output 1:
  6072. 7
  6073. 2
  6074. 6
  6075. 1
  6076.  
  6077.  
  6078. Sample Input 2:
  6079. 7
  6080. 7
  6081. 2
  6082. 3
  6083. 4
  6084. 5
  6085. 6
  6086. -1
  6087. Sample Output 2:
  6088. Invalid id
  6089. #include<stdio.h>
  6090. #include<stdlib.h>
  6091. int output1[20];
  6092. void nonWorkingDoctors(int total[],int working[],int n,int m);
  6093. int main(){
  6094. int size1=0,size2=0,input1[20],input2[20],i=0;
  6095. scanf("%d",&size1);
  6096. if(size1<0){
  6097. printf("Invalid array size");
  6098. getchar();
  6099. getchar();
  6100. exit(0);
  6101. }
  6102. for(i=0;i<size1;i++){
  6103. scanf("%d",&input1[i]);
  6104. if(input1[i]<0){
  6105. printf("Invalid id");
  6106. getchar();
  6107. getchar();
  6108. exit(0);
  6109. }
  6110. }
  6111. scanf("%d",&size2);
  6112. if(size2<0){
  6113. printf("Invalid array size");
  6114. getchar();
  6115. getchar();
  6116. exit(0);
  6117. }
  6118. for(i=0;i<size2;i++){
  6119. scanf("%d",&input2[i]);
  6120. if(input2[i]<0){
  6121. printf("Invalid id");
  6122. getchar();
  6123. getchar();
  6124. exit(0);
  6125. }
  6126. }
  6127. nonWorkingDoctors(input1,input2,size1,size2);
  6128.  
  6129. return 0;
  6130. }
  6131. void nonWorkingDoctors(int total[],int working[],int n,int m){
  6132. int i=0,j=0,k=0,flag=0;
  6133. for(i=0;i<n;i++){
  6134. flag=0;
  6135. for(j=0;j<m;j++){
  6136. if(total[i]==working[j])
  6137. flag=1;
  6138. }
  6139. if(flag==0)
  6140. printf("%d\n",total[i]);
  6141. }
  6142. getchar();
  6143. getchar();
  6144. }
  6145. 101.firstMiddleSame
  6146. Read the question carefully and follow the input and output format.
  6147.  
  6148. Write a program to check if the first and middle element in an array is the same, if so display “100” in output or else display the first element of the array.
  6149.  
  6150. Note: Array size is always odd.
  6151.  
  6152. Input and Output Format :
  6153. The first line of the input consists of an integer, n that corresponds to the number of elements in the array.
  6154. The next 'n' lines correspond to the elements in the array.
  6155.  
  6156. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program.
  6157. 2) Print "Invalid input" when there is any negative numbers available in the input array and terminate the program.
  6158. 3) Print "Size must be odd" when the size of the array is even.
  6159.  
  6160. Include a function named firstMiddleSame(int array[], int size) whose return type is an integer..
  6161.  
  6162. Sample Input 1:
  6163. 7
  6164. 8
  6165. 4
  6166. 5
  6167. 8
  6168. 3
  6169. 2
  6170. 1
  6171.  
  6172. Sample Output 1:
  6173. 100
  6174.  
  6175. Sample Input 2:
  6176. 10
  6177. 4
  6178. 5
  6179. 6
  6180. -8
  6181.  
  6182. Sample Output 2:
  6183. Invalid input
  6184.  
  6185. Sample Input 3:
  6186. 3
  6187. 4
  6188. 8
  6189. 6
  6190.  
  6191. Sample Output 3:
  6192. 4
  6193.  
  6194. #include<stdio.h>
  6195. #include<stdlib.h>
  6196. int firstMiddleSame(int array[], int size);
  6197. int main(){
  6198. int size=0,input1[20],i=0,res=0;
  6199. scanf("%d",&size);
  6200. if(size<0){
  6201. printf("Invalid array size");
  6202. getchar();
  6203. getchar();
  6204. exit(0);
  6205. }
  6206. for(i=0;i<size;i++){
  6207. scanf("%d",&input1[i]);
  6208. if(input1[i]<0){
  6209. printf("Invalid id");
  6210. getchar();
  6211. getchar();
  6212. exit(0);
  6213. }
  6214. }
  6215. if(size%2==0){
  6216. printf("size must be odd");
  6217. getchar();
  6218. getchar();
  6219. exit(0);
  6220. }
  6221.  
  6222. res = firstMiddleSame(input1,size);
  6223. printf("%d",res);
  6224. getchar();
  6225. getchar();
  6226. return 0;
  6227. }
  6228. int firstMiddleSame(int array[], int size){
  6229. int mid=size/2,res=0;
  6230. if(array[0]==array[mid])
  6231. res = 100;
  6232. else
  6233. res = array[0];
  6234. return res;
  6235. }
  6236. 102.countEvenRepeat
  6237. Read the question carefully and follow the input and output format.
  6238.  
  6239. Write a program to count the number of repeated even elements in a given input array.
  6240.  
  6241. Input and Output Format :
  6242. First line of input consists of n, the number of elements. And the remaining n lines is the elements of the array.
  6243. Output is a single integer that displays the count.
  6244.  
  6245. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program .
  6246. 2) Print "Invalid input" when there is any negative numbers available in the input array and terminate the program.
  6247.  
  6248. Include a function named countEvenRepeat(int array[], int size) whose return type is an integer, the count
  6249.  
  6250. Sample Input 1:
  6251. 9
  6252. 8
  6253. 4
  6254. 5
  6255. 8
  6256. 4
  6257. 2
  6258. 1
  6259. 4
  6260. 5
  6261.  
  6262. Sample Output 1:
  6263. 2
  6264.  
  6265. Sample Input 2:
  6266. 10
  6267. 4
  6268. 5
  6269. 6
  6270. -8
  6271.  
  6272. Sample Output 2:
  6273. Invalid input
  6274. #include<stdio.h>
  6275. #include<stdlib.h>
  6276. int countEvenRepeat(int array[], int size);
  6277. int main(){
  6278. int size=0,input1[20],i=0,res=0;
  6279. scanf("%d",&size);
  6280. if(size<0){
  6281. printf("Invalid array size");
  6282. getchar();
  6283. getchar();
  6284. exit(0);
  6285. }
  6286. for(i=0;i<size;i++){
  6287. scanf("%d",&input1[i]);
  6288. if(input1[i]<0){
  6289. printf("Invalid input");
  6290. getchar();
  6291. getchar();
  6292. exit(0);
  6293. }
  6294. }
  6295. res = countEvenRepeat(input1,size);
  6296. printf("%d",res);
  6297. getchar();
  6298. getchar();
  6299. return 0;
  6300. }
  6301. int countEvenRepeat(int array[], int size){
  6302. int i, j, k,count=0,sum=0;
  6303. for(i=0;i<size;i++){
  6304. count=1;
  6305. for(j=i+1;j<size;){
  6306. if(array[i] == array[j]){
  6307. ++count;
  6308. for(k=j;k<size;k++){
  6309. array[k] = array[k+1];
  6310. }
  6311. size--;
  6312. }
  6313. else
  6314. j++;
  6315. }
  6316. if(count!=1 && array[i]%2==0)
  6317. sum=sum+1;
  6318. }
  6319. return sum;
  6320. }
  6321. 103.Array Sorting
  6322.  
  6323. Write a program to sort the first half of the input array elements in ascending order and the second half of the input array elements in descending order.
  6324.  
  6325. Include a function named ascDescArray that accepts 2 arguments and its return type is void. The first argument is the input array and the second argument is an int that corresponds to the size of the array.
  6326.  
  6327. If the size of the array is negative or if any element in the array is negative , print “Invalid Input” and terminate the program.
  6328.  
  6329. Input and Output Format:
  6330. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  6331. Output consists of n integers that correspond to the elements in the sorted array.
  6332. Assume that the maximum size of the array is 20.
  6333.  
  6334. Sample Input 1:
  6335. 7
  6336. 1
  6337. 9
  6338. 8
  6339. 4
  6340. 6
  6341. 4
  6342. 5
  6343.  
  6344. Sample Output 1:
  6345. 1
  6346. 4
  6347. 8
  6348. 9
  6349. 6
  6350. 5
  6351. 4
  6352.  
  6353.  
  6354. Sample Input 2:
  6355. -5
  6356.  
  6357. Sample Output 2:
  6358. Invalid Input
  6359.  
  6360. Sample Input 3:
  6361. 5
  6362. 23
  6363. 2
  6364. -5
  6365.  
  6366. Sample Output 3:
  6367. Invalid Input
  6368.  
  6369. #include<stdio.h>
  6370. #include<stdlib.h>
  6371. void ascDescArray(int array[], int size);
  6372. int main(){
  6373. int size=0,input1[20],i=0;
  6374. scanf("%d",&size);
  6375. if(size<0){
  6376. printf("Invalid input");
  6377. getchar();
  6378. getchar();
  6379. exit(0);
  6380. }
  6381. for(i=0;i<size;i++){
  6382. scanf("%d",&input1[i]);
  6383. if(input1[i]<0){
  6384. printf("Invalid input");
  6385. getchar();
  6386. getchar();
  6387. exit(0);
  6388. }
  6389. }
  6390. ascDescArray(input1,size);
  6391. getchar();
  6392. getchar();
  6393. return 0;
  6394. }
  6395. void ascDescArray(int array[], int size){
  6396. int i, j, k,size1=size/2+1,size2=size-size1;
  6397. int temp=0;
  6398. for(i=0;i<size1;i++){
  6399. for(j=i+1;j<size1;j++){
  6400. if(array[i]>array[j]){
  6401. temp = array[i];
  6402. array[i] = array[j];
  6403. array[j] = temp;
  6404. }
  6405. }
  6406. }
  6407. for(i=size1;i<size;i++){
  6408. for(j=i+1;j<size;j++){
  6409. if(array[i]<array[j]){
  6410. temp = array[i];
  6411. array[i] = array[j];
  6412. array[j] = temp;
  6413. }
  6414. }
  6415. }
  6416. for(i=0;i<size;i++)
  6417. printf("%d\n",array[i]);
  6418.  
  6419. }
  6420. 104.occurenceDigit
  6421.  
  6422. Read the question carefully and follow the input and output format.
  6423.  
  6424. Given a number n, count the occurences of a number,x in n.
  6425.  
  6426. Input and Output Format :
  6427. The first line of the input consists of an integer n, the second line consists of an integer, which is the digit whose occurence is to be calculated. Output is an integer that gives the count.
  6428.  
  6429. Print "Number too small" if any of the 2 input numbers is less than 0 and terminate the program.
  6430. Print "Number too large" if any of the 2 input numbers is greater than 32767 and terminate the program.
  6431.  
  6432. Include a function named occurenceDigit(int number,int digit) that returns an integer, which is the count of the digit.
  6433.  
  6434. Sample Input 1:
  6435. 1122
  6436. 1
  6437. Sample Output 1:
  6438. 2
  6439.  
  6440.  
  6441. Sample Input 2:
  6442. -2134
  6443. Sample Output 2:
  6444. Number too small
  6445. #include<stdio.h>
  6446. #include<stdlib.h>
  6447. int occurenceDigit(int number,int digit);
  6448. int main(){
  6449. int number=0,result,find_digit=0;
  6450. scanf("%d",&number);
  6451. scanf("%d",&find_digit);
  6452. if(number<0 || find_digit<0){
  6453. printf("Number too small");
  6454. getchar();
  6455. getchar();
  6456. exit(0);
  6457. }
  6458. else if(number>32767 || find_digit>32767){
  6459. printf("Number too large");
  6460. getchar();
  6461. getchar();
  6462. exit(0);
  6463. }
  6464. else{
  6465. result = occurenceDigit(number,find_digit);
  6466. printf("%d",result);
  6467. }
  6468. getchar();
  6469. getchar();
  6470. return 0;
  6471. }
  6472.  
  6473. int occurenceDigit(int number,int digit){
  6474. int rem,count=0;
  6475. while(number!=0){
  6476. rem=number%10;
  6477. if(rem==digit)
  6478. count++;
  6479. number=number/10;
  6480. }
  6481. return count;
  6482. }
  6483. 105.consecutiveDifference
  6484. Read the question carefully and follow the input and output format.
  6485.  
  6486. Given input as integer array in which consecutive elements should have a difference of 4 or more than 4.
  6487.  
  6488. If the above condition matches display “1” else “0”
  6489.  
  6490. Input and Output Format :
  6491. First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of an integer, which is the either 1 or 0
  6492.  
  6493. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program.
  6494. 2) Print "Invalid input" when there is any negative numbers available in the input array and terminate the program.
  6495.  
  6496. Include a function named consecutiveDifference(int elements[], int size) whose return type is an integer either 1 or 0.
  6497.  
  6498. Sample Input 1:
  6499. 6
  6500. 1
  6501. 5
  6502. 10
  6503. 6
  6504. 2
  6505. 7
  6506.  
  6507. Sample Output 1:
  6508. 1
  6509.  
  6510. Sample Input 2:
  6511. -8
  6512.  
  6513. Sample Output 2:
  6514. Invalid array size
  6515. #include<stdio.h>
  6516. #include<stdlib.h>
  6517. int consecutiveDifference(int elements[], int size);
  6518. int main(){
  6519. int size=0,input1[20],i=0,res=0;
  6520. scanf("%d",&size);
  6521. if(size<0){
  6522. printf("Invalid array size");
  6523. getchar();
  6524. getchar();
  6525. exit(0);
  6526. }
  6527. for(i=0;i<size;i++){
  6528. scanf("%d",&input1[i]);
  6529. if(input1[i]<0){
  6530. printf("Invalid Input");
  6531. getchar();
  6532. getchar();
  6533. exit(0);
  6534. }
  6535. }
  6536. res = consecutiveDifference(input1,size);
  6537. if(res==1)
  6538. printf("%d",res);
  6539. else
  6540. printf("%d",res);
  6541. getchar();
  6542. getchar();
  6543. return 0;
  6544. }
  6545. int consecutiveDifference(int elements[], int size){
  6546. int i=0,j=0,res=0,diff=0,flag=0;
  6547. for(i=0;i<size;i++){
  6548. flag=0;
  6549. if(elements[i]>elements[i+1])
  6550. diff=elements[i]-elements[i+1];
  6551. else
  6552. diff=elements[i+1]-elements[i];
  6553. if(diff<4){
  6554. flag=1;
  6555. break;
  6556. }
  6557. }
  6558. if(flag==1)
  6559. res=0;
  6560. else
  6561. res=1;
  6562. return res;
  6563. }
  6564. 106.Change using Minimal Coins / Notes
  6565.  
  6566. Ram needs to pay the school fees of his 6 year old kid. As he is busy with his work, he is not finding time to go to the school to make payment. His kid's school doesn't accept online payment. So he decided to send the fee amount through his kid. The available denominations of rupees or coins is 500, 100, 50, 10, 5 and 1. Can you write a program to find the minimal number of coins or notes to be given to his kid?
  6567.  
  6568. Include a function named countRupees that accepts an integer and returns an integer that corresponds to the minimal number of coins/rupee notes. The function returns -1 if the input is negative.
  6569.  
  6570. Input and Output Format:
  6571. Input consists of a single integer that corresponds to the fee amount to be paid.
  6572. Output consists of an integer that corresponds to the minimal number of coins or rupee notes.
  6573.  
  6574. Print Invalid Input if the input value is negative.
  6575.  
  6576.  
  6577. Sample Input 1:
  6578. 682
  6579.  
  6580. Sample Output 1:
  6581. 8
  6582.  
  6583. Sample Input 2:
  6584. -2345
  6585.  
  6586. Sample Output 2:
  6587. Invalid Input
  6588.  
  6589. #include<stdio.h>
  6590. #include<stdlib.h>
  6591. int countRupees(int);
  6592. int main(){
  6593. int fees,count=0;
  6594. scanf("%d",&fees);
  6595. count = countRupees(fees);
  6596. if(count==-1)
  6597. printf("invalid input");
  6598. else
  6599. printf("%d",count);
  6600. getchar();
  6601. getchar();
  6602. return 0;
  6603. }
  6604. int countRupees(int rupees){
  6605. int count=0;
  6606. int c1,c2,c3,c4,c5,c6;
  6607. if(rupees<0)
  6608. count=-1;
  6609. else
  6610. {
  6611. c1=rupees/500;
  6612. rupees=rupees-(500*c1);
  6613. c2=rupees/100;
  6614. rupees=rupees-(100*c2);
  6615. c3=rupees/50;
  6616. rupees=rupees-(50*c3);
  6617. c4=rupees/10;
  6618. rupees=rupees-(10*c4);
  6619. c5=rupees/5;
  6620. rupees=rupees-(5*c5);
  6621. c6=rupees/1;
  6622. rupees=rupees-(1*c6);
  6623. count=c1+c2+c3+c4+c5+c6;
  6624. }
  6625. return count;
  6626. }
  6627. 107.singleDoubleTripCount
  6628. Read the question carefully and follow the input and output format.
  6629.  
  6630. In a given input array find out number of single digits, double digits and triple digits.
  6631.  
  6632. Input and Output Format :
  6633. First line of input consists of an integer, the size of the array. Next line correspond to the elements of the array. Output consist of an integer array.
  6634.  
  6635. 1) Print "Invalid array size" when size of the array is a negative number and terminate the program.
  6636. 2) Print "Invalid input" when there is any negative numbers available in the input array and terminate the program.
  6637.  
  6638. Include a function named singleDoubleTripCount(int elements[], int size) whose return type is void.
  6639. The output array is stored in a global variable named count. The seize of the output array is 6.
  6640. Sample Input 1:
  6641. 5
  6642. 1
  6643. 2
  6644. 23
  6645. 34
  6646. 456
  6647.  
  6648. Sample Output 1:
  6649. 1
  6650. 2
  6651. 2
  6652. 2
  6653. 3
  6654. 1
  6655.  
  6656. Sample Input 2:
  6657. 4
  6658. 1
  6659. 2
  6660. -3
  6661.  
  6662. Sample Output 2:
  6663. Invalid input
  6664. #include<stdio.h>
  6665. #include<stdlib.h>
  6666. int count[6];
  6667. void singleDoubleTripCount(int elements[], int size);
  6668. int main(){
  6669. int size=0,input1[20],i=0;
  6670. scanf("%d",&size);
  6671. if(size<0){
  6672. printf("Invalid array size");
  6673. getchar();
  6674. getchar();
  6675. exit(0);
  6676. }
  6677. for(i=0;i<size;i++){
  6678. scanf("%d",&input1[i]);
  6679. if(input1[i]<0){
  6680. printf("Invalid Input");
  6681. getchar();
  6682. getchar();
  6683. exit(0);
  6684. }
  6685. }
  6686. singleDoubleTripCount(input1,size);
  6687. getchar();
  6688. getchar();
  6689. return 0;
  6690. }
  6691. void singleDoubleTripCount(int elements[], int size){
  6692. int i=0,c1=0,c2=0,c3=0;
  6693. count[0]=1;
  6694. count[2]=2;
  6695. count[4]=3;
  6696. for(i=0;i<size;i++){
  6697. if(elements[i]>=0 && elements[i]<=9)
  6698. count[1]=++c1;
  6699. else if(elements[i]>=10 && elements[i]<=99)
  6700. count[3]=++c2;
  6701. else if(elements[i]>=100 && elements[i]<=999)
  6702. count[5]=++c3;
  6703. else
  6704. ;
  6705. }
  6706. for(i=0;i<6;i++)
  6707. printf("%d\n",count[i]);
  6708. }
  6709.  
  6710. 108.Sum of multiples
  6711.  
  6712. Given 2 integers n and m, write a program to find the sum of all numbers divisible by m upto and including n (i.e from 1 to n).
  6713.  
  6714. Include a function named sumMultiples that accepts 2 integer arguments and returns an integer that corresponds to the sum of the multiples. The first argument corresponds to n and the second argument corresponds to m. The function returns -1 if the any of the two inputs is less than 0.
  6715.  
  6716. If the function returns -1, print “Invalid Input”.
  6717.  
  6718. Input and Output Format:
  6719.  
  6720. The input consists of 2 integers. The 1st integer corresponds to n and the 2nd integer corresponds to m.
  6721. The output consists of an integer that corresponds to the sum of the multiples.
  6722.  
  6723. Sample Input 1:
  6724. 11
  6725. 5
  6726.  
  6727. Sample Ouput 1:
  6728. 15
  6729.  
  6730. Sample Input 2:
  6731. -8
  6732. 2
  6733.  
  6734. Sample Output 2:
  6735. Invalid Input
  6736.  
  6737.  
  6738. #include<stdio.h>
  6739. #include<stdlib.h>
  6740. int sumMultiples(int,int);
  6741. int main(){
  6742. int n=0,m=0,sum=0;
  6743. scanf("%d%d",&n,&m);
  6744. sum = sumMultiples(n,m);
  6745. if(sum == -1)
  6746. printf("Invalid Input");
  6747. else
  6748. printf("%d",sum);
  6749. getchar();
  6750. getchar();
  6751. return 0;
  6752. }
  6753. int sumMultiples(int n,int m){
  6754. int i,sum=0;
  6755. if(n<0 || m<0)
  6756. sum=-1;
  6757. else{
  6758. for(i=m;i<=n;i++){
  6759. if(i%m==0)
  6760. sum = sum + i;
  6761. }
  6762. }
  6763. return sum;
  6764. }
  6765. 109.Search Element
  6766.  
  6767. Write a program to find whether a particular number appears in a given input array.
  6768.  
  6769. Include a function named isElementPresent that accepts 3 arguments and returns an int. The first argument is the input array, the second argument is an int that corresponds to the size of the array and the third argument is the element to be searched for. The function returns 1 if the search element is present in the array and returns 0 if the search element is not present in the array.
  6770.  
  6771. If the size of the array is negative or if any element in the array is negative, print “Invalid Input” and terminate the program.
  6772.  
  6773. Input and Output Format:
  6774. Input consists of n+2 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array. The last integer corresponds to the element whose count needs to be found.
  6775. Output consists of a string that is either 'yes' or 'no'.
  6776.  
  6777. Refer sample output for formatting specifications.
  6778.  
  6779. Assume that the maximum number of elements in the array is 20.
  6780.  
  6781. Sample Input 1:
  6782. 8
  6783. 2
  6784. 1
  6785. 3
  6786. 8
  6787. 6
  6788. 8
  6789. 10
  6790. 8
  6791. 8
  6792.  
  6793. Sample Output 1:
  6794. yes
  6795.  
  6796. Sample Input 2:
  6797. -5
  6798.  
  6799. Sample Output 2:
  6800. Invalid Input
  6801.  
  6802. Sample Input 3:
  6803. 5
  6804. 23
  6805. 2
  6806. -200
  6807.  
  6808. Sample Output 3:
  6809. Invalid Input
  6810.  
  6811.  
  6812. #include<stdio.h>
  6813. #include<stdlib.h>
  6814. int isElementPresent(int[],int,int);
  6815. int main(){
  6816. int size=0,input1[20],i=0,res=0,element=0;
  6817. scanf("%d",&size);
  6818. if(size<0){
  6819. printf("Invalid Input");
  6820. getchar();
  6821. getchar();
  6822. exit(0);
  6823. }
  6824. for(i=0;i<size;i++){
  6825. scanf("%d",&input1[i]);
  6826. if(input1[i]<0){
  6827. printf("Invalid Input");
  6828. getchar();
  6829. getchar();
  6830. exit(0);
  6831. }
  6832. }
  6833. scanf("%d",&element);
  6834. res = isElementPresent(input1,size,element);
  6835. if(res==1)
  6836. printf("yes");
  6837. else
  6838. printf("no");
  6839. getchar();
  6840. getchar();
  6841. return 0;
  6842. }
  6843. int isElementPresent(int numbers[], int size, int element){
  6844. int i=0,res=0;
  6845. for(i=0;i<size;i++){
  6846. if(numbers[i]==element){
  6847. res=1;
  6848. break;
  6849. }
  6850. }
  6851. return res;
  6852. }
  6853. 110.Binary Conversion
  6854. Write a program to convert a given input decimal number to binary.
  6855.  
  6856. Include a function named convertToBinary that accepts an integer argument and its return type is void. Print the binary representation of the number in this function.
  6857.  
  6858. If the input value is negative or greater than 100, print Invalid Input and terminate the program.
  6859.  
  6860. Input and Output Format:
  6861. Input consists of a single integer.
  6862. Output consists of the binary representation of the given integer.
  6863. Refer sample output for formatting specifications.
  6864.  
  6865.  
  6866. Sample Input 1:
  6867. 12
  6868.  
  6869. Sample Output 1:
  6870. 1100
  6871.  
  6872. Sample Input 2:
  6873. 64
  6874.  
  6875. Sample Output 2:
  6876. 1000000
  6877.  
  6878. Sample Input 3:
  6879. -2345
  6880.  
  6881. Sample Output 3:
  6882. Invalid Input
  6883.  
  6884. #include<stdio.h>
  6885. #include<stdlib.h>
  6886. void convertToBinary(int num);
  6887. int main(){
  6888. int number=0;
  6889. scanf("%d",&number);
  6890. if(number<0 || number>100){
  6891. printf("Invalid input");
  6892. getchar();
  6893. getchar();
  6894. exit(0);
  6895. }
  6896. else
  6897. convertToBinary(number);
  6898. return 0;
  6899. }
  6900. void convertToBinary(int num){
  6901. int a[20],i=0;
  6902. while(num>0)
  6903. {
  6904. a[i]=num%2;
  6905. i++;
  6906. num=num/2;
  6907. }
  6908. for(int j=i-1;j>=0;j--)
  6909. printf("%d",a[j]);
  6910. getchar();
  6911. getchar();
  6912. }
  6913.  
  6914. 111.Repeated Element
  6915.  
  6916. Write a program to find the maximum repeated element in a given input array.
  6917.  
  6918. Include a function named maxRepeatedElement that accepts 2 arguments and returns an int. The first argument is the input array and the second argument is an int that corresponds to the size of the array. The function returns an int that corresponds to the maximum repeated element.
  6919.  
  6920. If the size of the array is negative or if any element in the array is negative, print “Invalid Input” and terminate the program.
  6921.  
  6922. Input and Output Format:
  6923. Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next 'n' integers correspond to the elements in the array.
  6924. Output consists of an integer that corresponds to the maximum repeated element.
  6925. Assume that the maximum number of elements in the array is 20 and that there will always be a unique maximum repeated element.
  6926.  
  6927. Sample Input 1:
  6928. 8
  6929. 2
  6930. 1
  6931. 3
  6932. 4
  6933. 6
  6934. 8
  6935. 10
  6936. 8
  6937.  
  6938. Sample Output 1:
  6939. 8
  6940.  
  6941. Sample Input 2:
  6942. -5
  6943.  
  6944. Sample Output 2:
  6945. Invalid Input
  6946.  
  6947. Sample Input 3:
  6948. 5
  6949. 23
  6950. 2
  6951. -200
  6952.  
  6953. Sample Output 3:
  6954. Invalid Input
  6955.  
  6956. #include<stdio.h>
  6957. #include<stdlib.h>
  6958. int maxRepeatedElement(int array[], int size);
  6959. int main(){
  6960. int size=0,input1[20],i=0,res=0;
  6961. scanf("%d",&size);
  6962. if(size<0){
  6963. printf("Invalid Input");
  6964. getchar();
  6965. getchar();
  6966. exit(0);
  6967. }
  6968. for(i=0;i<size;i++){
  6969. scanf("%d",&input1[i]);
  6970. if(input1[i]<0){
  6971. printf("Invalid input");
  6972. getchar();
  6973. getchar();
  6974. exit(0);
  6975. }
  6976. }
  6977. res = maxRepeatedElement(input1,size);
  6978. printf("%d",res);
  6979. getchar();
  6980. getchar();
  6981. return 0;
  6982. }
  6983. int maxRepeatedElement(int array[], int size){
  6984. int i, j, k=0;
  6985. for(i=0;i<size;i++){
  6986. for(j=i+1;j<size;j++){
  6987. if(array[i] == array[j]){
  6988. k=array[i];
  6989. break;
  6990. }
  6991. }
  6992. }
  6993. return k;
  6994. }
  6995.  
  6996. /*
  6997. int maxRepeatedElement(int array[], int size){
  6998. int i, j, k,count=0,sum=0;
  6999. for(i=0;i<size;i++){
  7000. count=1;
  7001. for(j=i+1;j<size;){
  7002. if(array[i] == array[j]){
  7003. ++count;
  7004. for(k=j;k<size;k++){
  7005. array[k] = array[k+1];
  7006. }
  7007. size--;
  7008. }
  7009. else
  7010. j++;
  7011. }
  7012. if(count!=1 && array[i]%2==0)
  7013. sum=sum+1;
  7014. }
  7015. return sum;
  7016. }
  7017. */
  7018. 112.subTwoArrays
  7019. Read the question carefully and follow the input and output format.
  7020.  
  7021. Given two input arrays, write a program to find out numbers which is present in the first array and not in the second array.
  7022.  
  7023. Input and Output Format :
  7024. First line of input consists of n, the number of elements. Next n lines correspond to the first array elements and the next n lines correspond to the second array elements. Output consist of an integer array.
  7025.  
  7026. 1) Print "Invalid array size" when size of the array is a negative number.
  7027. 2) Print "Invalid input" when there is any negative numbers available in the input array.
  7028.  
  7029.  
  7030. Include a function named subTwoArrays(int elements1[], int elements2[], int size) whose return type is void.
  7031. The output array is stored in a global variable named no_common.
  7032.  
  7033. Sample Input 1:
  7034. 5
  7035. 1
  7036. 2
  7037. 3
  7038. 4
  7039. 5
  7040. 3
  7041. 5
  7042. 7
  7043. 9
  7044. 10
  7045.  
  7046. Sample Output 1:
  7047. 1
  7048. 2
  7049. 4
  7050.  
  7051. Sample Input 2:
  7052. 4
  7053. 1
  7054. 2
  7055. -3
  7056.  
  7057. Sample Output 2:
  7058. Invalid input
  7059. #include<stdio.h>
  7060. #include<stdlib.h>
  7061. int no_common[20];
  7062. void subTwoArrays(int elements1[], int elements2[], int size);
  7063. int main(){
  7064. int size=0,input1[20],input2[20],i=0;
  7065. scanf("%d",&size);
  7066. if(size<0){
  7067. printf("Invalid array size");
  7068. getchar();
  7069. getchar();
  7070. exit(0);
  7071. }
  7072. for(i=0;i<size;i++){
  7073. scanf("%d",&input1[i]);
  7074. if(input1[i]<0){
  7075. printf("Invalid input");
  7076. getchar();
  7077. getchar();
  7078. exit(0);
  7079. }
  7080. }
  7081. for(i=0;i<size;i++){
  7082. scanf("%d",&input2[i]);
  7083. if(input2[i]<0){
  7084. printf("Invalid input");
  7085. getchar();
  7086. getchar();
  7087. exit(0);
  7088. }
  7089. }
  7090. subTwoArrays(input1,input2,size);
  7091.  
  7092. return 0;
  7093. }
  7094. void subTwoArrays(int elements1[], int elements2[], int size){
  7095. int i=0,j=0,k=0,flag=0;
  7096. for(i=0;i<size;i++){
  7097. flag=0;
  7098. for(j=0;j<size;j++){
  7099. if(elements1[i]==elements2[j])
  7100. flag=1;
  7101.  
  7102. }
  7103. if(flag==0){
  7104. no_common[k]=elements1[i];
  7105. k++;
  7106. }
  7107. }
  7108. for(i=0;i<k;i++)
  7109. printf("%d\n",no_common[i]);
  7110. getchar();
  7111. getchar();
  7112. }
  7113. 113.primeFactorialSum
  7114. Read the question carefully and follow the input and output format.
  7115.  
  7116. In a given input number , find out the sum of factorial of digits that are prime.
  7117.  
  7118. Input and Output Format :
  7119. Input consists of an integer. Output consists of the factorial sum.
  7120. 1) Print "Number too large" when the given input number is greater than 32767
  7121. 2) Print "Number too small" when the given input number is a negative number.
  7122.  
  7123. Include a function named primeFactorialSum(int number) whose return type is an integer.
  7124.  
  7125. Sample Input 1:
  7126. 123
  7127. Sample Output 1:
  7128. 8
  7129.  
  7130. Hint : 2! + 3! = (8)
  7131.  
  7132. Sample Input 2:
  7133. 32768
  7134. Sample Output 2:
  7135. Number too large
  7136.  
  7137. #include<stdio.h>
  7138. #include<stdlib.h>
  7139. int primeFactorialSum(int number);
  7140. int main(){
  7141. int number,result=0;
  7142. scanf("%d",&number);
  7143. if(number>32767)
  7144. printf("Number too large");
  7145. else if(number<0)
  7146. printf("Number too small");
  7147. else{
  7148. result = primeFactorialSum(number);
  7149. printf("%d",result);
  7150. }
  7151. getchar();
  7152. getchar();
  7153. return 0;
  7154. }
  7155.  
  7156. int primeFactorialSum(int number){
  7157. int i,count=0,num,sum=0,rem=0,flag=0,k,res=1;
  7158. while(number!=0){
  7159. rem=number%10;
  7160. count=0;
  7161. for(i=1;i<=rem;i++){
  7162. if(rem%i==0)
  7163. count++;
  7164. }
  7165. if(count==2){
  7166. res=1;
  7167. for(k=1;k<=rem;k++)
  7168. res = res * k;
  7169. sum = sum + res;
  7170. }
  7171. number=number/10;
  7172. }
  7173. return sum;
  7174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement