Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CAP180
- 01. WAP to find the largest no among 3 nos. Done
- //Write a program to check the largest no. between three no. entered by the user.
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int a,b,c;
- printf("Please enter the first no.: ");
- scanf("%d", &a);
- printf("Please enter the second no.: ");
- scanf("%d", &b);
- printf("Please enter the third no.: ");
- scanf("%d", &c);
- if (a>b && a>c)
- {
- printf("%d is Greater", a);
- }
- else if (b>a && b>c)
- {
- printf("%d is Greater", b);
- }
- else
- {
- printf("%d is Greater", c);
- }
- getch();
- }
- 02. WAP to check for leap years(it should be divisible by 4, 100, 400)
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int year;
- printf("Enter a year \n");
- scanf("%d", &year);
- if (year % 400 == 0)
- printf("%d is a leap year \n", year);
- else if (year % 100 == 0)
- printf("%d is a not leap year \n", year);
- else if (year % 4 == 0)
- printf("%d is a leap year \n", year);
- else
- printf("%d is not a leap year \n", year);
- }
- 03. WAP to check odd or even
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int a;
- printf("Enter an integer number: ");
- scanf("%d", &a);
- if (a%2 == 0)
- printf("The no. %d is an even number.", a);
- else
- printf("The no. %d is a odd number", a);
- getch();
- }
- 04. WAP to add two no. using function.
- #include<stdio.h>
- int addition(int, int);
- main()
- {
- int first, second, sum;
- printf("Enter two no.: \n");
- scanf("%d %d", &first, &second);
- sum = addition(first, second);
- printf("Sum = %d\n", sum);
- return 0;
- }
- int addition(int a, int b)
- {
- int result;
- result = a + b;
- return result;
- }
- 05. WAP to check if the entered alphabet is vawel or consonemt
- 06. WAP to display grades
- 07. WAP to check the no. is positive or negetive.
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int a;
- printf("Enter an Integer no.: ");
- scanf("%d", &a);
- if (a>0)
- {
- printf("The no. is Positive");
- }
- else if (a<0)
- {
- printf("The no. is Negative");
- }
- else
- printf("Invalid Input");
- getch();
- }
- 08. WAP to check if the entered value is digit or alphabet or special charecter.
- 09. WAP to check wheather the no. is divisible by 5 and 7 or not.
- #include <stdio.h>
- int main()
- {
- int num;
- /* Input number from user */
- printf("Enter any number: ");
- scanf("%d", &num);
- /*
- * If num modulo division 5 is 0
- * and num modulo division 7 is 0 then
- * the number is divisible by 5 and 7 both
- */
- if((num % 5 == 0) && (num % 7 == 0))
- {
- printf("Number is divisible by 5 and 7");
- }
- else
- {
- printf("Number is not divisible by 5 and 7");
- }
- return 0;
- }
- 10. WAP to print the table of any no. entered by user.
- #include <stdio.h>
- int main()
- {
- int n, i;
- printf("Enter an integer: ");
- scanf("%d",&n);
- for(i=1; i<=10; ++i)
- {
- printf("%d * %d = %d \n", n, i, n*i);
- }
- return 0;
- }
- 11. WAP to find the factorial
- //Factorial program
- #include <stdio.h>
- int main()
- {
- int c, n, fact = 1;
- printf("Enter a number to calculate its factorial\n");
- scanf("%d", &n);
- for (c = 1; c <= n; c++)
- fact = fact * c;
- printf("Factorial of %d = %d\n", n, fact);
- return 0;
- }
- 12. WAP to find prime no. using for loops
- #include<stdio.h>
- main()
- {
- int n, c = 2;
- printf("Enter a number to check if it is prime\n");
- scanf("%d",&n);
- for ( c=2 ; c<=n-1; c++ )
- {
- if ( n%c == 0 )
- {
- printf("%d isn't prime.\n", n);
- break;
- }
- }
- if ( c == n )
- printf("%d is prime.\n", n);
- return 0;
- }
- 13. WAP to find the sum of odd no. in n given values.
- /* C Program to Print Sum of Odd Numbers from 1 to N */
- #include<stdio.h>
- int main()
- {
- int i, number, Sum = 0;
- printf("Please Enter the Maximum Limit Value : ");
- scanf("%d", &number);
- printf("Odd Numbers between 0 and %d are : ", number);
- for(i = 1; i <= number; i=i+2)
- {
- Sum = Sum + i;
- printf("%d ", i);
- }
- printf("\nThe Sum of Odd Numbers from 1 to %d = %d", number, Sum);
- return 0;
- }
Add Comment
Please, Sign In to add comment