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

Lab Assignment 6

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)
19 views

Lab Assignment 6

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/ 7

Name - Tanmay Shrivastava

Course-BTech(CSE)
Roll No.-24155589

Day 8(Lab Assignments)


Question1)Print Armstrong numbers from 100 to 999.
#include <stdio.h>
int main()
{
int i,a,s,r=0,sum;
for(i=100;i<=999;i++)
{
a=i;
r=0;
while(a>0) OUTPUT:
{ 153 370 371 403
s=a%10;
sum=s*s*s;
r=r+sum;
a=a/10;
}
if(r==i)
printf("%d\t",i);
}
return 0;
}
Question2)Find the sum of digits of a number until the sum is reduced to 1 digit..
#include <stdio.h>
int main()
{ INPUT:
int a,i,s;
i=0; Enter the number=81
printf("Enter the number:");
scanf("%d",&a);
printf("%d->",a);
while(a/10>=10)
{ OUTPUT:
while(a>0) 81->9->End
{
s=a%10;
i=i+s;
a=a/10;
}
printf("%d->",i);
a=i;
}
printf("End");
return 0;
}
Question3)Check whether a number is prime or not.
#include <stdio.h>
#include <math.h>
int main()
{
int a,i,b; INPUT:
b=0; Enter the number=7
printf("Enter the number=");
scanf("%d",&a);
for(i=2;i<=sqrt(a);i++)
{
if(a%i==0)
{ OUTPUT:
printf("%d is not a prime number",a);
b++; 7 is a prime number
break;
}
}
if(b==0)
{
printf("%d is a prime number",a);
}
return 0;
}
Question4)Input a number and a digit and find whether the digit is present in the number or not, if
present then count the number of times it occurs in the number.
#include <stdio.h>
INPUT:
int main() Enter the number=232
{ Enter the digit=2
int a,b,i,s;
i=0;
printf("Enter the number=");
scanf("%d",&a);
printf("Enter the digit=");
scanf("%d",&b);
while(a>0)
{
s=a%10; OUTPUT:
if(s==b) 2 appears 2 times
{
i=i+1;
}
a=a/10;
}
printf("%d appears %d times",b,i);
return 0;
}
Question5)Enter a six digit number and print the sum of all even digits of that number and
multiplication of all odd digits.
#include <stdio.h>
int main()
{
int a,b,s,m; INPUT:
s=0;
m=1; Enter a six digit number=123456
printf("Enter a six digit number=");
scanf("%d",&a);
while(a>0)
{
b=a%10;
if(b%2==0)
{
s=s+b; OUTPUT:
} Sum=12,Multiplication=18
else
{
m=m*b;
}
a=a/10;
}
printf("Sum=%d,Multiplication=%d",s,m);
return 0;
}
Question 6)An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a
program to display each digit, starting with the rightmost digit. Your program should also
determine whether or not the number is divisible by 9
#include <stdio.h>
int main()
{
INPUT:
int a,b,s,A;
s=0;
Enter the number=81
printf("Enter the number=");
scanf("%d",&a);
A=a;
while(A>0)
{
b=A%10;
if(b>0)
{ OUTPUT:
printf("%d\n",b);
} 81 is divisible by 9
s=s+b;
A=A/10;
}
if(s%9==0)
{
printf("%d is divisible by 9",a);
}
else
{
printf("Not divisible");
}
return 0;
}

You might also like