cba_guru

C Programs

Jun 8th, 2018
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.18 KB | None | 0 0
  1. CAP180
  2. 01. WAP to find the largest no among 3 nos.                     Done
  3. //Write a program to check the largest no. between three no. entered by the user.
  4.  
  5. #include<stdio.h>
  6. #include<conio.h>
  7.  
  8. void main()
  9. {
  10.     int a,b,c;
  11.    
  12.     printf("Please enter the first no.: ");
  13.     scanf("%d", &a);
  14.     printf("Please enter the second no.: ");
  15.     scanf("%d", &b);
  16.     printf("Please enter the third no.: ");
  17.     scanf("%d", &c);
  18.    
  19.     if (a>b && a>c)
  20.     {
  21.         printf("%d is Greater", a);
  22.     }
  23.     else if (b>a && b>c)
  24.     {
  25.         printf("%d is Greater", b);
  26.     }
  27.     else
  28.     {
  29.         printf("%d is Greater", c);
  30.     }
  31.    
  32.     getch();
  33. }
  34.  
  35. 02. WAP to check for leap years(it should be divisible by 4, 100, 400)
  36. #include<stdio.h>
  37. #include<conio.h>
  38.  
  39. void main()
  40. {
  41.     int year;
  42.     printf("Enter a year \n");
  43.     scanf("%d", &year);
  44.  
  45.     if (year % 400 == 0)
  46.     printf("%d is a leap year \n", year);
  47.     else if (year % 100 == 0)
  48.     printf("%d is a not leap year \n", year);
  49.     else if (year % 4 == 0)
  50.     printf("%d is a leap year \n", year);
  51.     else
  52.     printf("%d is not a leap year \n", year);
  53. }
  54. 03. WAP to check odd or even
  55. #include<stdio.h>
  56. #include<conio.h>
  57.  
  58. void main()
  59. {
  60.     int a;
  61.     printf("Enter an integer number: ");
  62.     scanf("%d", &a);
  63.    
  64.     if (a%2 == 0)
  65.         printf("The no. %d is an even number.", a);
  66.     else
  67.         printf("The no. %d is a odd number", a);
  68.        
  69.     getch();
  70. }
  71. 04. WAP to add two no. using function.
  72. #include<stdio.h>
  73.  
  74. int addition(int, int);
  75.  
  76. main()
  77. {
  78.    int first, second, sum;
  79.    printf("Enter two no.: \n");
  80.    scanf("%d %d", &first, &second);
  81.    sum = addition(first, second);
  82.    printf("Sum = %d\n", sum);
  83.    return 0;
  84. }
  85.  
  86. int addition(int a, int b)
  87. {
  88.    int result;
  89.    result = a + b;
  90.    return result;
  91. }
  92. 05. WAP to check if the entered alphabet is vawel or consonemt
  93. 06. WAP to display grades
  94. 07. WAP to check the no. is positive or negetive.
  95. #include<stdio.h>
  96. #include<conio.h>
  97.  
  98. void main()
  99. {
  100.     int a;
  101.     printf("Enter an Integer no.: ");
  102.     scanf("%d", &a);
  103.    
  104.     if (a>0)
  105.     {
  106.         printf("The no. is Positive");
  107.     }
  108.     else if (a<0)
  109.     {
  110.         printf("The no. is Negative");
  111.     }
  112.     else
  113.     printf("Invalid Input");
  114.    
  115.     getch();
  116. }
  117. 08. WAP to check if the entered value is digit or alphabet or special charecter.
  118. 09. WAP to check wheather the no. is divisible by 5 and 7 or not.
  119. #include <stdio.h>
  120.  
  121. int main()
  122. {
  123.     int num;
  124.  
  125.     /* Input number from user */
  126.     printf("Enter any number: ");
  127.     scanf("%d", &num);
  128.  
  129.     /*
  130.      * If  num modulo division 5 is 0
  131.      * and num modulo division 7 is 0 then
  132.      * the number is divisible by 5 and 7 both
  133.      */
  134.     if((num % 5 == 0) && (num % 7 == 0))
  135.     {
  136.         printf("Number is divisible by 5 and 7");
  137.     }
  138.     else
  139.     {
  140.         printf("Number is not divisible by 5 and 7");
  141.     }
  142.  
  143.     return 0;
  144. }
  145. 10. WAP to print the table of any no. entered by user.
  146. #include <stdio.h>
  147. int main()
  148. {
  149.     int n, i;
  150.  
  151.     printf("Enter an integer: ");
  152.     scanf("%d",&n);
  153.  
  154.     for(i=1; i<=10; ++i)
  155.     {
  156.         printf("%d * %d = %d \n", n, i, n*i);
  157.     }
  158.    
  159.     return 0;
  160. }
  161. 11. WAP to find the factorial
  162. //Factorial program
  163.  
  164. #include <stdio.h>
  165.  
  166. int main()
  167. {
  168.   int c, n, fact = 1;
  169.  
  170.   printf("Enter a number to calculate its factorial\n");
  171.   scanf("%d", &n);
  172.  
  173.   for (c = 1; c <= n; c++)
  174.     fact = fact * c;
  175.  
  176.   printf("Factorial of %d = %d\n", n, fact);
  177.  
  178.   return 0;
  179. }
  180. 12. WAP to find prime no. using for loops
  181. #include<stdio.h>
  182.  
  183. main()
  184. {
  185.    int n, c = 2;
  186.  
  187.    printf("Enter a number to check if it is prime\n");
  188.    scanf("%d",&n);
  189.  
  190.    for ( c=2 ; c<=n-1; c++ )
  191.    {
  192.     if ( n%c == 0 )
  193.     {
  194.      printf("%d isn't prime.\n", n);
  195.      break;
  196.     }
  197.    }
  198.    if ( c == n )
  199.     printf("%d is prime.\n", n);
  200.  
  201.    return 0;
  202. }
  203. 13. WAP to find the sum of odd no. in n given values.
  204. /* C Program to Print Sum of Odd Numbers from 1 to N */
  205.  
  206. #include<stdio.h>
  207.  
  208. int main()
  209. {
  210.   int i, number, Sum = 0;
  211.  
  212.   printf("Please Enter the Maximum Limit Value : ");
  213.   scanf("%d", &number);
  214.  
  215.   printf("Odd Numbers between 0 and %d are : ", number);
  216.   for(i = 1; i <= number; i=i+2)
  217.   {
  218.     Sum = Sum + i;
  219.     printf("%d  ", i);
  220.   }
  221.   printf("\nThe Sum of Odd Numbers from 1 to %d  = %d", number, Sum);
  222.  
  223.   return 0;
  224. }
Add Comment
Please, Sign In to add comment