Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.02 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title> Data set Test </title>
  5. <link rel="stylesheet" type="text/css" href="Style.css" />
  6. <script type="text/javascript" src="javaScript.js" > </script>
  7. </head>
  8.  
  9. <body background="bg.jpg">
  10. <h1> <u> <MARQUEE> WELCOME To Online Test !! </MARQUEE> </u> </h1>
  11. <hr size=10 noshade>
  12. <h2 class="fst" >
  13. Please, Fill up information and answer the questions below.
  14. </h2>
  15. <h5> NAME : <input type="text" id="text1" value="" /> </h5>
  16. <h5> ID_NO: <input type="text" id="text2" value="" /> </h5>
  17. <h3> <u> QUESTIONS: </u> </h3>
  18.  
  19. <ol>
  20. <h1>SET A</h1>
  21. <li> 1 Program to Check Even or Odd </li>
  22. <textarea rows="20" cols="100">
  23. #include <stdio.h>
  24. int main()
  25. {
  26. int number;
  27. printf("Enter an integer: ");
  28. scanf("%d", &number);
  29. // True if the number is perfectly divisible by 2
  30. if(number % 2 == 0)
  31. printf("%d is even.", number);
  32. else
  33. printf("%d is odd.", number);
  34. return 0;
  35. }
  36. </textarea>
  37. <br>
  38. <br>
  39. <li> 2: Program to Swap Numbers Using Temporary Variable ? </li>
  40.  
  41. <textarea rows="20" cols="100">
  42. #include <stdio.h>
  43. int main()
  44. {
  45. int firstNumber, secondNumber, temporaryVariable;
  46.  
  47. printf("Enter first number: ");
  48.  
  49. scanf("%d", &firstNumber);
  50.  
  51. printf("Enter second number: ");
  52.  
  53. scanf("%d",&secondNumber);
  54.  
  55. // Value of firstNumber is assigned to temporaryVariable
  56.  
  57. temporaryVariable = firstNumber;
  58.  
  59. // Value of secondNumber is assigned to firstNumber
  60.  
  61. firstNumber = secondNumber;
  62.  
  63. // Value of temporaryVariable (which contains the initial value of firstNumber) is assigned to secondNumber
  64.  
  65. secondNumber = temporaryVariable;
  66.  
  67. printf("\nAfter swapping, firstNumber = %d\n", firstNumber);
  68.  
  69. printf("After swapping, secondNumber = %d", secondNumber);
  70.  
  71. return 0;
  72. }
  73. </textarea>
  74. <br>
  75. <br>
  76.  
  77. <li> 3:Program to Print ASCII Value? </li>
  78.  
  79. <textarea rows="20" cols="100">
  80. #include <stdio.h>
  81. int main()
  82. {
  83.  
  84. char c;
  85.  
  86. printf("Enter a character: ");
  87.  
  88. // Reads character input from the user
  89.  
  90. scanf("%c", &c);
  91.  
  92.  
  93. // %d displays the integer value of a character
  94.  
  95. // %c displays the actual character
  96.  
  97. printf("ASCII value of %c = %d", c, c);
  98.  
  99. return 0;
  100. }
  101. </textarea>
  102. <br>
  103.  
  104. <li> 4: Reverse an Integer ? </li>
  105.  
  106. <textarea rows="20" cols="100">
  107. #include <stdio.h>
  108. int main()
  109. {
  110.  
  111. int n, reversedNumber = 0, remainder;
  112.  
  113. printf("Enter an integer: ");
  114.  
  115. scanf("%d", &n);
  116.  
  117. while(n != 0)
  118. {
  119.  
  120. remainder = n%10;
  121.  
  122. reversedNumber = reversedNumber*10 + remainder;
  123.  
  124. n /= 10;
  125.  
  126. }
  127.  
  128. printf("Reversed Number = %d", reversedNumber);
  129.  
  130. return 0;
  131. }
  132.  
  133. </textarea>
  134.  
  135. <br><br>
  136.  
  137.  
  138. <li> 5: Program to Count Number of Digits in an Integer </li>
  139. <textarea rows="20" cols="100">
  140. #include <stdio.h>
  141. int main()
  142. {
  143.  
  144. int n;
  145.  
  146. int count = 0;
  147.  
  148. printf("Enter an integer: ");
  149.  
  150. scanf("%d", &n);
  151.  
  152. while(n != 0)
  153.  
  154. {
  155.  
  156. // n = n/10
  157.  
  158. n /= 10;
  159.  
  160. ++count;
  161.  
  162. }
  163.  
  164. printf("Number of digits: %d", count);
  165. }
  166.  
  167. </textarea>
  168.  
  169. <li> 6: Program to Check Palindrome: </li>
  170. <textarea rows="20" cols="100">
  171.  
  172. #include <stdio.h>
  173. int main()
  174. {
  175.  
  176. int n, reversedInteger = 0, remainder, originalInteger;
  177.  
  178. printf("Enter an integer: ");
  179.  
  180. scanf("%d", &n);
  181.  
  182. originalInteger = n;
  183.  
  184. // reversed integer is stored in variable
  185.  
  186. while( n!=0 )
  187.  
  188. {
  189.  
  190. remainder = n%10;
  191.  
  192. reversedInteger = reversedInteger*10 + remainder;
  193.  
  194. n /= 10;
  195. }
  196. // palindrome if orignalInteger and reversedInteger are equal
  197.  
  198. if (originalInteger == reversedInteger)
  199.  
  200. printf("%d is a palindrome.", originalInteger);
  201.  
  202. else
  203.  
  204. printf("%d is not a palindrome.", originalInteger);
  205.  
  206.  
  207. return 0;
  208. }
  209. </textarea>
  210.  
  211. <li> 7: Program to Check Leap Year: </li>
  212. <textarea rows="20" cols="100">
  213. #include <stdio.h>
  214. int main()
  215. {
  216.  
  217. int year;
  218.  
  219. printf("Enter a year: ");
  220.  
  221. scanf("%d",&year);
  222.  
  223. if(year%4 == 0)
  224. {
  225.  
  226. if( year%100 == 0)
  227. {
  228.  
  229. // year is divisible by 400, hence the year is a leap year
  230.  
  231. if ( year%400 == 0)
  232. printf("%d is a leap year.", year);
  233.  
  234. else
  235. printf("%d is not a leap year.", year);
  236. }
  237.  
  238. else
  239.  
  240. printf("%d is a leap year.", year );
  241.  
  242. }
  243. else
  244.  
  245. printf("%d is not a leap year.", year);
  246.  
  247.  
  248. return 0;
  249. }
  250. </textarea>
  251. <li> 8: Check if a Number is Positive or Negative Using if...else
  252. </li>
  253. <textarea rows="20" cols="100">
  254.  
  255.  
  256. #include <stdio.h>
  257.  
  258. int main()
  259. {
  260.  
  261. int number;
  262.  
  263. printf("Enter a number: ");
  264.  
  265. scanf("%d", &number);
  266.  
  267. if (number <= 0)
  268.  
  269. {
  270.  
  271. if (number == 0)
  272.  
  273. printf("You entered 0.");
  274.  
  275. else
  276.  
  277. printf("You entered a negative number.");
  278.  
  279. }
  280.  
  281. else
  282.  
  283. printf("You entered a positive number.");
  284.  
  285. return 0;
  286. }
  287. </textarea>
  288.  
  289.  
  290. <li> 9: Program to Check Prime Number
  291.  
  292. </li>
  293. <textarea rows="20" cols="100">
  294.  
  295. #include <stdio.h>
  296. int main()
  297. {
  298.  
  299. int n, i, flag = 0;
  300. printf("Enter a positive integer: ");
  301.  
  302. scanf("%d",&n);
  303. for(i=2; i<=n/2; ++i)
  304. {
  305.  
  306. // condition for nonprime number
  307.  
  308. if(n%i==0)
  309.  
  310. {
  311.  
  312. flag=1;
  313.  
  314. break;
  315.  
  316. }
  317. }
  318.  
  319. if (flag==0)
  320.  
  321. printf("%d is a prime number.",n);
  322.  
  323. else
  324.  
  325. printf("%d is not a prime number.",n);
  326.  
  327. return 0;
  328. }
  329. </textarea>
  330.  
  331. <li> 10: Program to Check Alphabet: </li>
  332. <textarea rows="20" cols="100">
  333.  
  334. Example 10: Program to Check Alphabet
  335.  
  336. #include <stdio.h>
  337. int main()
  338. {
  339.  
  340. char c;
  341.  
  342. printf("Enter a character: ");
  343.  
  344. scanf("%c",&c);
  345.  
  346. if( (c>='a' && c<='z') || (c>='A' && c<='Z'))
  347.  
  348. printf("%c is an alphabet.",c);
  349.  
  350. else
  351.  
  352. printf("%c is not an alphabet.",c);
  353.  
  354. return 0;
  355. }
  356. </textarea>
  357.  
  358. <h1> SET B </h1>
  359.  
  360.  
  361. <li> 11: Program to print half pyramid using : </li>
  362. <textarea rows="20" cols="100">
  363.  
  364. #include <stdio.h>
  365. int main()
  366. {
  367. int i, j, rows;
  368. printf("Enter number of rows: ");
  369. scanf("%d",&rows);
  370. for(i=1; i<=rows; ++i)
  371. {
  372. for(j=1; j<=i; ++j)
  373. {
  374. printf("* ");
  375. }
  376. printf("\n");
  377. }
  378. return 0;
  379. }
  380. </textarea>
  381. <li> 12: Program to print half pyramid using : </li>
  382. <textarea rows="20" cols="100">
  383.  
  384. #include<stdio.h>
  385. int main() {
  386. int side, area;
  387.  
  388. printf("\nEnter the Length of Side : ");
  389. scanf("%d", &side);
  390.  
  391. area = side * side;
  392. printf("\nArea of Square : %d", area);
  393.  
  394. return (0);
  395. }
  396.  
  397. </textarea>
  398.  
  399. <li> 13: Swich/Case grade
  400. </li>
  401. <textarea rows="20" cols="100">
  402.  
  403.  
  404. #include <stdio.h>
  405. int main () {
  406. /* local variable definition */
  407. char grade = 'B';
  408. switch(grade) {
  409. case 'A' :
  410. printf("Excellent!\n" );
  411. break;
  412. case 'B' :
  413. case 'C' :
  414. printf("Well done\n" );
  415. break;
  416. case 'D' :
  417. printf("You passed\n" );
  418. break;
  419. case 'F' :
  420. printf("Better try again\n" );
  421. break;
  422. default :
  423. printf("Invalid grade\n" );
  424. break;
  425. }
  426.  
  427. printf("Your grade is %c\n", grade );
  428.  
  429. return 0;
  430. }
  431. </textarea>
  432.  
  433. <li> 14:Here is a example to add two integers. To perform this task, a user-defined function addNumbers() is defined.
  434.  
  435. </li>
  436. <textarea rows="20" cols="100">
  437. #include <stdio.h>
  438. int addNumbers(int a, int b); // function prototype
  439. int main()
  440. {
  441. int n1,n2,sum;
  442. printf("Enters two numbers: ");
  443. scanf("%d %d",&n1,&n2);
  444. sum = addNumbers(n1, n2); // function call
  445. printf("sum = %d",sum);
  446. return 0;
  447. }
  448. int addNumbers(int a,int b) // function definition
  449. {
  450. int result;
  451. result = a+b;
  452. return result; // return statement
  453. }
  454.  
  455. </textarea>
  456.  
  457.  
  458. <li> 15: Book id and price with structure
  459. </li>
  460. <textarea rows="20" cols="100">
  461.  
  462. #include <stdio.h>
  463.  
  464. struct Books {
  465.  
  466. int book_id;
  467. int price;
  468. };
  469.  
  470. int main( ) {
  471. struct Books Book1; /* Declare Book1 of type Book */
  472. struct Books Book2; /* Declare Book2 of type Book */
  473.  
  474. /* book 1 specification */
  475.  
  476. Book1.book_id = 6495407;
  477. Book1.price = 250;
  478.  
  479. Book2.book_id = 6495700;
  480. Book2.price = 300;
  481. /* print Book1 info */
  482.  
  483. printf( "Book 1 book_id : %d\n", Book1.book_id);
  484. printf( "Book 1 price : %d\n", Book1.price);
  485. /* print Book2 info */
  486.  
  487. printf( "Book 2 book_id : %d\n", Book2.book_id);
  488. printf( "Book 2 price : %d\n", Book2.price);
  489. return 0;
  490. }
  491. </textarea>
  492.  
  493. <li> 16: Book id and price with structure
  494. </li>
  495. <textarea rows="20" cols="100">
  496. #include <stdio.h>
  497.  
  498. struct Car {
  499.  
  500. int car_id;
  501. int price;
  502. };
  503.  
  504. int main( ) {
  505. struct Car Car1;
  506. struct Car Car2;
  507.  
  508. Car1.car_id = 101;
  509. Car1.price = 1000000;
  510.  
  511. Car2.car_id = 102;
  512. Car2.price = 1500000;
  513.  
  514. printf( "Car 1 car_id : %d\n", Car1.car_id);
  515. printf( "Car 1 price : %d\n", Car1.price);
  516.  
  517. printf( "Car 2 car_id : %d\n", Car2.car_id);
  518. printf( "Car 2 price : %d\n", Car2.price);
  519. return 0;
  520. }
  521. </textarea>
  522.  
  523.  
  524. <li> 17: 17: Accessing array element
  525. </li>
  526. <textarea rows="20" cols="100">
  527.  
  528. #include <stdio.h>
  529.  
  530. int main () {
  531.  
  532. int n[ 10 ]; /* n is an array of 10 integers */
  533. int i,j;
  534.  
  535. /* initialize elements of array n to 0 */
  536. for ( i = 0; i < 10; i++ ) {
  537. n[ i ] = i + 100; /* set element at location i to i + 100 */
  538. }
  539.  
  540. /* output each array element's value */
  541. for (j = 0; j < 10; j++ ) {
  542. printf("Element[%d] = %d\n", j, n[j] );
  543. }
  544.  
  545. return 0;
  546. }
  547. </textarea>
  548.  
  549.  
  550. <li> 18 : Factorial of a Number
  551.  
  552. </li>
  553. <textarea rows="20" cols="100">
  554. #include <stdio.h>
  555. int main()
  556. {
  557. int n, i;
  558. int factorial = 1;
  559. printf("Enter an integer: ");
  560. scanf("%d",&n);
  561. // show error if the user enters a negative integer
  562. if (n < 0)
  563. printf("Error! Factorial of a negative number doesn't exist.");
  564. else
  565. {
  566. for(i=1; i<=n; ++i)
  567. {
  568. factorial *= i; // factorial = factorial*i;
  569. }
  570. printf("Factorial of %d = %llu", n, factorial);
  571. }
  572. return 0;
  573. }
  574. </textarea>
  575.  
  576. <li> 19: Find greater,less,equal
  577. </li>
  578. <textarea rows="20" cols="100">
  579.  
  580. #include<stdio.h>
  581. int main()
  582. {
  583. int x = 10;
  584. int y = 5;
  585.  
  586. if(x == y)
  587. printf("Equal");
  588. else if(x > y)
  589. printf("Greater");
  590. else
  591. printf("Less");
  592.  
  593. }
  594. </textarea>
  595.  
  596. <li> 20: Find armstrong number
  597. </li>
  598. <textarea rows="20" cols="100">
  599.  
  600. #include<stdio.h>
  601.  
  602. int main()
  603. {
  604. int n,r,sum=0,temp;
  605.  
  606. printf("enter the number=");
  607. scanf("%d",&n);
  608. temp=n;
  609. while(n>0)
  610. {
  611. r=n%10;
  612. sum=sum+(r*r*r);
  613. n=n/10;
  614. }
  615. if(temp==sum)
  616. printf("armstrong number ");
  617. else
  618. printf("not armstrong number");
  619.  
  620. }
  621. </textarea>
  622.  
  623. <h1> SET C </h1>
  624.  
  625. <li> 21: Find armstrong number
  626. </li>
  627. <textarea rows="20" cols="100">
  628.  
  629. #include<stdio.h>
  630.  
  631. int main()
  632. {
  633. int a[10],n,i;
  634. printf("Enter the number to convert: ");
  635. scanf("%d",&n);
  636. for(i=0;n>0;i++)
  637. {
  638. a[i]=n%2;
  639. n=n/2;
  640. }
  641. printf("\nBinary of Given Number is=");
  642. for(i=i-1;i>=0;i--)
  643. {
  644. printf("%d",a[i]);
  645. }
  646.  
  647. }
  648. </textarea>
  649.  
  650.  
  651. <li> 22: Array In C programming to find out the average of 4 integers
  652. </li>
  653. <textarea rows="20" cols="100">
  654. #include <stdio.h>
  655. int main()
  656. {
  657. int avg = 0;
  658. int sum =0;
  659. int x=0;
  660. /* Array- declaration – length 4*/
  661. int num[4];
  662. /* We are using a for loop to traverse through the array
  663. * while storing the entered values in the array
  664. */
  665. for (x=0; x<4;x++)
  666. {
  667. printf("Enter number %d \n", (x+1));
  668. scanf("%d", &num[x]);
  669. }
  670. for (x=0; x<4;x++)
  671. {
  672. sum = sum+num[x];
  673. }
  674. avg = sum/4;
  675. printf("Average of entered number is: %d", avg);
  676. return 0;
  677. }
  678. </textarea>
  679.  
  680. <li> 23: while loop
  681. </li>
  682. <textarea rows="20" cols="100">
  683.  
  684. #include <stdio.h>
  685. int main()
  686. {
  687. int count=1;
  688. while (count <= 4)
  689. {
  690. printf("%d ", count);
  691. count++;
  692. }
  693. return 0;
  694. }
  695. </textarea>
  696.  
  697. <li> 24:Do while loop
  698. </li>
  699. <textarea rows="20" cols="100">
  700. #include <stdio.h>
  701. int main()
  702. {
  703. int j=0;
  704. do
  705. {
  706. printf("Value of variable j is: %d\n", j);
  707. j++;
  708. }while (j<=3);
  709. return 0;
  710. }
  711. </textarea>
  712.  
  713. <li>25 :Function subtraction
  714.  
  715. </li>
  716. <textarea rows="20" cols="100">
  717.  
  718. #include <stdio.h>
  719. int subtraction(int a, int b)
  720. {
  721. int c=a-b;
  722. return c;
  723. }
  724.  
  725. int main(
  726. {
  727. int var1 =10;
  728. int var2 = 20;
  729. int var3 = subtraction(var1, var2);
  730. printf("%d", var3);
  731.  
  732. return 0;
  733. }
  734. </textarea>
  735.  
  736. <li>26 :Function multiplication
  737.  
  738. </li>
  739. <textarea rows="20" cols="100">
  740.  
  741. #include <stdio.h>
  742. int multiplication(int a, int b)
  743. {
  744. int c=a-b;
  745. return c;
  746. }
  747.  
  748. int main(
  749. {
  750. int var1 =10;
  751. int var2 = 20;
  752. int var3 = multiplication(var1, var2);
  753. printf("%d", var3);
  754.  
  755. return 0;
  756. }
  757.  
  758. </textarea>
  759. <li>27 :Function Dividation
  760.  
  761. </li>
  762. <textarea rows="20" cols="100">
  763.  
  764. #include <stdio.h>
  765. int dividation(int a, int b)
  766. {
  767. int c=a-b;
  768. return c;
  769. }
  770.  
  771. int main()
  772. {
  773. int var1 =10;
  774. int var2 = 20;
  775. int var3 = dividation(var1, var2);
  776. printf("%d", var3);
  777.  
  778. return 0;
  779. }
  780. </textarea>
  781.  
  782. <li>28 :Switch case check value
  783.  
  784. </li>
  785. <textarea rows="20" cols="100">
  786.  
  787. #include <stdio.h>
  788.  
  789. int main ()
  790. {
  791. int value = 3;
  792. switch(value)
  793. {
  794. case 1:
  795. printf(“Value is 1 \n” );
  796. break;
  797.  
  798. case 2:
  799. printf(“Value is 2 \n” );
  800. break;
  801.  
  802. case 3:
  803. printf(“Value is 3 \n” );
  804. break;
  805.  
  806. case 4:
  807. printf(“Value is 4 \n” );
  808. break;
  809.  
  810. default :
  811. printf(“Value is other than 1,2,3,4 \n” );
  812. }
  813. return 0;
  814. }
  815. </textarea>
  816.  
  817. <li>29 :Switch case check week
  818.  
  819. </li>
  820. <textarea rows="20" cols="100">
  821.  
  822. #include <stdio.h>
  823.  
  824. int main()
  825. {
  826. int week;
  827.  
  828. /* Input week number from user */
  829. printf("Enter week number(1-7): ");
  830. scanf("%d", &week);
  831.  
  832. switch(week)
  833. {
  834. case 1:
  835. printf("Monday");
  836. break;
  837. case 2:
  838. printf("Tuesday");
  839. break;
  840. case 3:
  841. printf("Wednesday");
  842. break;
  843. case 4:
  844. printf("Thursday");
  845. break;
  846. case 5:
  847. printf("Friday");
  848. break;
  849. case 6:
  850. printf("Saturday");
  851. break;
  852. case 7:
  853. printf("Sunday");
  854. break;
  855. default:
  856. printf("Invalid input! Please enter week number between 1-7.");
  857. }
  858.  
  859. return 0;
  860.  
  861. </textarea>
  862.  
  863.  
  864. <li>30 :Switch case check vowel or consonant
  865.  
  866. </li>
  867. <textarea rows="20" cols="100">
  868.  
  869. #include <stdio.h>
  870. int main()
  871. {
  872. char ch;
  873.  
  874. /* Input an alphabet from user */
  875. printf("Enter any alphabet: ");
  876. scanf("%c", &ch);
  877.  
  878. /* Switch value of ch */
  879. switch(ch)
  880. {
  881. case 'a':
  882. printf("Vowel");
  883. break;
  884. case 'e':
  885. printf("Vowel");
  886. break;
  887. case 'i':
  888. printf("Vowel");
  889. break;
  890. case 'o':
  891. printf("Vowel");
  892. break;
  893. case 'u':
  894. printf("Vowel");
  895. break;
  896. case 'A':
  897. printf("Vowel");
  898. break;
  899. case 'E':
  900. printf("Vowel");
  901. break;
  902. case 'I':
  903. printf("Vowel");
  904. break;
  905. case 'O':
  906. printf("Vowel");
  907. break;
  908. case 'U':
  909. printf("Vowel");
  910. break;
  911. default:
  912. printf("Consonant");
  913. }
  914.  
  915. return 0;
  916. }
  917. </textarea>
  918.  
  919.  
  920. <br><br>
  921. </ol>
  922. <button type="submit" onClick="check()" value="SUBMIT"> <a href="sub2.html" target="_blank"> <h2>SUBMIT</h2> </a> </button>
  923. <hr size=9 noshade>
  924. <p class="last" align="right" size="125%" > <a href="developer.html" > ABOUT PAGE DEVELOPERS NAZMUL SARKER </a> </p>
  925. </body>
  926. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement