0% found this document useful (0 votes)
6 views3 pages

LAB6SNB

C lab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

LAB6SNB

C lab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Problem Solving and Computer

ProgrammingLab 6
NAME: SANJEEV NAIK BANOTHU
ROLL NO: 221220052
1. If a four-digit number is input through the keyboard WAP to find the sum of the
first and last digit of the number and display it.
SOURCE CODE
#include <stdio.h>
int main() {
int a,x,r=0;
printf("ENTER THE NUMBER:");
scanf("%d",&a);
x=a;
r=a%10;
while(a>9){
a=a/10;
}

printf("SUM OF FIRST AND LAST DIGITS IN THE NUMBER %d is


%d",x,r+a);
}

OUTPUT

2. WAP to find GCD and LCM of the two numbers input through the keyboard.
SOURCE CODE
#include<stdio.h>
int main(){
int x,y,lcm,gcd=1;
printf("enter the two numbers");
scanf("%d %d",&x,&y);
for(int i=1;i<=x*y;i++){
if(i%x==0 && i%y==0){
lcm=i;
break;
}
}
printf("least common multiple of %d and %d is %d\n",x,y,lcm);
for(int i=1;(i<=x && i<=y);i++){
if(x%i==0 && y%i==0) gcd=i;
}
printf("greatest common divisor of %d and %d is %d",x,y,gcd);
return 0;
}

OUTPUT

3. Read n integers store them in an array find their sum and average.
SOURCE CODE
#include<stdio.h>
int main(){
int n,sum=0;
printf("ENTER THE NUMBER 'n':");
scanf("%d",&n);
int num[n];
for(int i=0;i<n;i++){
scanf("%d",&num[i]);
sum=sum+num[i];
}
float average = (float)sum/n;
printf("SUM OF %d NUMBERS IS %d\n",n,sum);
printf("AVERAGE OF THE %d NUMBERS IS %0.2f\n",n,average);
return 0;
}

OUTPUT
4. Read n integers store them in array and search for an element in an array using
an algorithm for Searching.
SOURCE CODE
#include<stdio.h>
int main(){
int n,x,k=0;
printf("ENTER THE NUMBER 'n':");
scanf("%d",&n);
int num[n];
for(int i=0;i<n;i++){
scanf("%d",&num[i]);
}
printf("ENTER THE FOR WHICH WE HAVE TO SEARCH:");
scanf("%d",&x);
for(int i=0;i<n;i++){
if(num[i]==x) k=1;
}
k==1?printf("%d IS IN THE ARRAY",x):printf("%d IS NOT IN THE
ARRAY",x);
return 0;
}

OUTPUT

You might also like