0% found this document useful (0 votes)
4 views

Week3-Section-F

The document is a laboratory manual for a Problem Solving with C course, specifically detailing Week 3 exercises. It includes programs for checking if a character is a vowel or consonant, calculating the factorial of a number, and outlines tasks for checking prime numbers and computing GCD and LCM. Each program is accompanied by example code and expected outputs.

Uploaded by

piyushapatel2006
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Week3-Section-F

The document is a laboratory manual for a Problem Solving with C course, specifically detailing Week 3 exercises. It includes programs for checking if a character is a vowel or consonant, calculating the factorial of a number, and outlines tasks for checking prime numbers and computing GCD and LCM. Each program is accompanied by example code and expected outputs.

Uploaded by

piyushapatel2006
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Problem Solving with C

LABORATORY MANUAL
Week 3
1. Write a program that checks whether a given character is a vowel or a consonant using switch-
case..
--------------
CODE:
#include<stdio.h>
int main()
{
char character;
printf("enter a character\n");
scanf("%c/n",&character);
if(character>='A' && character<='Z'||character>='a' && character<='z')
{
printf("it is an alphabet\n");
}
else
{
printf("not an alphabet\n");
return 0;
}
switch(character)
{
case 'A':
printf("vowels");
break;
case 'a':
printf("vowels");
break;
case 'E':
printf("vowels");
break;
case 'e':
printf("vowels");
break;
case 'I':
printf("vowels");
break;
case 'i':
printf("vowels");
break;
case 'O':
printf("vowels");
break;
case 'o':
printf("vowels");
break;
case 'U':
printf("vowels");
break;
case 'u':
printf("vowels");
break;
default:
printf("consonant");
}
return 0;
}

--------------
Output :
enter a character
s
it is an alphabet
consonantnithishy@master-To-be-filled-by-O-E-M:~$ ./a.out
enter a character
1
not an alphabet

--------------

2. Write a program to calculate the factorial of a given number using a loop. Use if to check for
negative input.
--------------
CODE:
#include<stdio.h>
int main()
{
int n,i,fact;
printf("enter a number\n");
scanf("%d",&n);
fact=1;
if (n<0)
{
printf("negative numbers\n");
}
else
{
for(i=1;i<=n;i++)
fact=fact*i;
printf("factorial is %d",fact);
}
return 0;
}

-------------
Output :
enter a number
6
factorial is 720

--------------

3. Write a program to check whether a given number is prime or not using loops and control
structures.
--------------
CODE:

--------------
Output :

--------------

4. Write a program to compute both the GCD and LCM of two numbers. Use the Euclidean algorithm
for GCD and the relation: LCM×GCD=product of the numbers..
--------------
CODE:

--------------
Output :

--------------

You might also like