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

Lab 5 SNB

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

Lab 5 SNB

C lab
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Problem Solving and Computer

ProgrammingLab 5
NAME: SANJEEV NAIK BANOTHU
ROLL NO: 221220052

1.WAP to find whether a character is vowel or consonant using switch


statement

SOURCE CODE
#include <stdio.h>
int main() {
printf("ENTER THE CHARACTER:");
char ch;
scanf("%c",&ch);
if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z')){
switch(ch){
case 'A':printf("VOWEL");
break;
case 'E':printf("VOWEL");
break;
case 'I':printf("VOWEL");
break;
case 'O':printf("VOWEL");
break;
case 'U':printf("VOWEL");
break;
case 'a':printf("VOWEL");
break;
case 'e':printf("VOWEL");
break;
case 'i':printf("VOWEL");
break;
case 'o':printf("VOWEL");
break;
case 'u':printf("VOWEL");
break;
default :printf("CONSONANT");
break;
}
}
else printf("ENTER VALID CHARACTER");
return 0;
}
OUTPUT

2.WAP to print the day using switch statement.

SOURCE CODE
#include <stdio.h>
int main() {
printf("ENTER THE DAY NUMBER OF THE WEEK:");
int day;
scanf("%d",&day);
switch(day){
case 1:printf("MONDAY");
break;
case 2:printf("TUESDAY");
break;
case 3:printf("WEDNESDAY");
break;
case 4:printf("THURSDAY");
break;
case 5:printf("FRIDAY");
break;
case 6:printf("SATURDAY");
break;
case 7:printf("SUNDAY");
break;
default:printf("ENTER VALID NUMBER");
break;

}
return 0;
}
OUTPUT

3.WAP to check whether the entered number is positive


negative or zero using switch statement.

SOURCE CODE
#include <stdio.h>
int main() {
printf("ENTER NUMBER:");
int num;
scanf("%d",&num);
if(num>0) num=1;
if(num<0) num=-1;
if(num==0) num=0;
switch(num){
case 1:printf("POSITIVE");
break;
case -1:printf("NEGATIVE");
break;
case 0:printf("ZERO");
break;
}
return 0;
}

OUTPUT
4.Write a program to
A. Print positive integers from 1 to 10.

SOURCE CODE

#include <stdio.h>
int main() {
for(int i=1;i<=10;i++){
printf("%d ",i);
}
return 0;
}

OUTPUT

B. Count the numbers in a given number.

SOURCE CODE
#include <stdio.h>
int main() {
int a,k=0,x;
printf("ENTER THE NUMBER:");
scanf("%d",&a);
x=a;
while(a!=0){
k++;
a=a/10;
}
printf("TOTAL NO.OF DIGITS IN THE NUMBER %d is %d",x,k);
}

OUTPUT
C. Print the given number in reverse order.

SOURCE CODE
#include<stdio.h>
int main(){
int i,x,n,rem,pal=0;
printf("enter the number:");
scanf("%d",&x);
n=x;
while(x!=0){
rem=x%10;
pal=pal*10+rem;
x=x/10;
}
printf("THE REVERSE OF A NUMBER %d is %d",n,pal);
return 0;
}

OUTPUT

D. Print the sum of digits in a number using for loop.

SOURCE CODE
#include <stdio.h>
int main() {
int a,k=0,x;
printf("ENTER THE NUMBER:");
scanf("%d",&a);
x=a;
for(a;a>0;a/=10){
k+=a%10;
}
printf("SUM OF DIGITS IN THE NUMBER %d is %d",x,k);
}

OUTPUT
E. Check whether a number is palindrome or not.

SOURCE CODE
#include<stdio.h>
int main(){
int i,x,n,rem,pal=0;
printf("enter the number:");
scanf("%d",&x);
n=x;
while(x!=0){
rem=x%10;
pal=pal*10+rem;
x=x/10;
}
if (pal==n)
printf("%d is Palindrome number",n);
else
printf("%d is not a palindrome number",n);

return 0;
}

OUTPUT
F. Generate Fibonacci series.

SOURCE CODE
#include <stdio.h>
#include<math.h>
// fiboncci is series in an=an-2 + an-1
int fib(int n);
int main() {
int n;
printf("ENTER THE NUMBER UPTO WHICH FIBONACCI SERIES SHOULD BE
GENERAED:");
scanf("%d" , &n);
for(int i=0; i<=n ; i++){
printf("%d " , fib(i));
}
return 0;
}
int fib(int n){
if(n==0){
return 0;
}
if(n==1){
return 1;
}
int f1 = fib(n-1);
int f2 = fib(n-2);
int f = f1 + f2;
return f;
}

OUTPUT

You might also like