FYBSC(CS)_Slip 6

  Q 1) A 

i. Write a ‘C’ program to find maximum of two numbers.

#include <stdio.h>
int main()
{
    int num1, num2, max;

    printf("Enter two numbers: ");
    scanf("%d%d", &num1, &num2);

    /* Compare num1 with num2 */
    if(num1 > num2)
        max = num1;
    else
        max = num2;
    printf("OUTPUT:: %d is maximum.", max);
    return 0;
}

Program Output:

Enter two numbers:
10
12
OUTPUT:: 12 is maximum

ii Write a recursive function in ‘C’ to calculate factorial of a number. Use this function in main.

#include<stdio.h>
int find_factorial(int);
int main()
{
   int num, fact;
   printf("\nEnter any integer number:");
   scanf("%d",&num);
 
   fact =find_factorial(num);
 
   printf("\nfactorial of %d is: %d",num, fact);
   return 0;
}
int find_factorial(int n)
{
   if(n==0)
      return(1);
    return(n*find_factorial(n-1));
}

Program Output:

Enter any integer number:6

factorial of 6 is: 720

OR

Q 1) A Write a ‘C’ program with menu to perform the following operations on a character. 

1.Check uppercase or lowercase

2.Display its ASCII value

3.Display its next and previous character

4.Exit

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
    int ch, var;
    char c;
    printf("\n Enter any character : ");
    scanf("%c",&c);
    while(1)
    {
    printf("\n Menu : \n 1. Check uppercase or lowercase");
    printf("\n 2. Display its ASCII value");
    printf("\n 3. Display its next and previous character\n 4. Exit");
    printf("\n Enter your choice (1-4)\n");
    scanf("%d",&ch);
    switch(ch)
    {
        case 1:
               if(isupper(c))
                printf("%c is Uppercase character",c);
            else if(islower(c))
                printf("%c is Lowercase character",c);
            else
                printf("Neither lowercase nor uppercase");
               break;
        case 2:
              printf("\n ASCII value of characher %c is %d",c,c);
              break;
        case 3:
              printf("\n Previous character of %c is %c",c,c-1);
            printf("\n Next character %c is %c",c,c+1);
              break;
        case 4:
              exit(0);
              break;
        default : printf("\n Invalid input…");
    }
    printf("\nDo You Want To Continue(1/0)\n");
    scanf("%d",&var);
    if(var==0)
        break;
    }
    return 0;
}

Program Output:

Enter any character : R

 Menu :
 1. Check uppercase or lowercase
 2. Display its ASCII value
 3. Display its next and previous character
 4. Exit

 Enter your choice (1-4)
 1
 R is Uppercase character
 Do You Want To Continue(1/0)
 1

 Menu :
 1. Check uppercase or lowercase
 2. Display its ASCII value
 3. Display its next and previous character
 4. Exit

 Enter your choice (1-4)
 2

 ASCII value of character R is82
 Do You Want To Continue(1/0)
 1

 Menu :
 1. Check uppercase or lowercase
 2. Display its ASCII value
 3. Display its next and previous character
 4. Exit

 Enter your choice (1-4)
 3

 Previous character of R is Q
 Next character R is S
 Do You Want To Continue(1/0)
 0

0 Comments:

Post a Comment