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

assignment file 4 while loop (2)

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 views

assignment file 4 while loop (2)

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

1)

#include <stdio.h>
#include <conio.h>
int main()
{
int n, i=1;

printf("enter the number :");


scanf("%d", &n);

while (i <= n)
{
printf("%d,", i);
i++;
}
return 0;
}

OUTPUT:
Enter the number :10

1,2,3,4,5,6,7,8,9,10

2)

#include <stdio.h>
#include <conio.h>
int main()
{
int n = 1, i;

printf("enter the number :");


scanf("%d", &i);

while (n <= i)
{
printf("%d,", i);
i--;
}
return 0;
}
OUTPUT:
Enter the number :10

10,9,8,7,6,5,4,3,2,1

3)

#include <stdio.h>
#include <conio.h>
int main()
{
char i = 'a';

while (i <= 'z')


{
printf("%c,", i);
i++;
}
return 0;
}

OUTPUT:
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,v,w,x,y,z

4)
#include <stdio.h>
#include <conio.h>
int main()
{
int i = 1;

while (i <= 100)


{
if (i % 2 == 0)

printf("%d ", i);


i++;
}
return 0;
}
OUTPUT:
2,4,6,8,10,12,14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34,
36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62,
64, 66,68,70,72.74.76.78.80.82,84,86,88.90.92.94.96.98.100.

5)

#include <stdio.h>
#include <conio.h>
int main()
{
int i = 1;

while (i <= 100)


{
printf("%d ", i);
i=i+2;
}
return 0;
}
OUTPUT:
1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35
,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,
73,75,77,79,81,83,85,87,89,91,93,95,97,99,

6)

#include <stdio.h>
#include <conio.h>
int main()
{
int i = 1, n, sum = 0;

printf("enter the number :");


scanf("%d", &n);
while (i <= n)
{
if (i % 2 == 0)
sum = sum + i;
i++;
}
printf(" sum of even number is :%d", sum);
return 0;
}
OUTPUT:
enter the number:12
sum of all even number :42

7)

#include<stdio.h>
#include<conio.h>
int main()

{ int n,i=1,sum=0;

printf("enter the number:");


scanf("%d", & n);

while(i<=n)
{
if(i%2!=0)
sum=sum+i;
i++;

}
printf("sum of all odd number :%d", sum );
return 0;

}
OUTPUT:
Enter the number:15
sum of all odd number:64

8)

#include<stdio.h>
#include<conio.h>
int main()
{ int i=1,n;

printf("enter the number:");


scanf("%d", & n);

while(i<=10)
{
printf("%d\n",n*i);
i++;
}
return 0;
}
OUTPUT:
Enter the number:2

2
4
6
8
10
12
14
16
18
20

9)

#include<stdio.h>
#include<conio.h>
int main()
{ int n,i=1,sum=0;

printf("enter the number:");


scanf("%d", & n);

while(i<=n)
{

sum=sum+i;
i++;

}
printf("sum of all natural number:%d",sum);

return 0;
}
OUTPUT:

Enter the number:85


sum of all natural number:3655

10)

#include<stdio.h>
#include<conio.h>
int main()

{
int n,first,last;

printf("enter the number");


scanf("%d", & n);

last=n%10;

while(n>=10)
{
n=n/10;
}
first=n;
printf("first digit of number: %d\n and last digit of number: %d",first ,last);
}

OUTPUT:
Enter the number:1539
the first digit of number :1
the last digit of number: 9

11)

#include <stdio.h>
#include <conio.h>
int main()
{
int n, count = 0;

printf("Enter the number:");


scanf("%d", &n);

while (n != 0)
{
n = n / 10;
count++;
}
printf("number of digit is %d", count);

return 0;
}

OUTPUT:
Enter the number:46799
number of digit is : 5

12)

#include <stdio.h>
#include <conio.h>
int main()
{
int n, sum = 0, r;

printf("Enter the number:");


scanf("%d", &n);

while (n != 0)
{
r = n % 10;
sum = sum + r;
n = n / 10;
}
printf("sum of digit is %d", sum);

return 0;
}

OUTPUT:
Enter the number:5498
sum of each digit: 26

13)

#include <stdio.h>
#include <conio.h>
int main()
{
int n, product = 1, r;

printf("Enter the number:");


scanf("%d", &n);

while (n != 0)
{
r = n % 10;
product = product * r;
n = n / 10;
}
printf("product of digit is %d", product);

return 0;
}

OUTPUT:
Enter the number:125
product of each number: 10

14)

#include <stdio.h>
#include <conio.h>
int main()
{
int n, first, last;

printf("Enter the number:");


scanf("%d", &n);

last = n % 10;

while (n >= 10)


{
n = n / 10;
}
first = n;
first = first + last;
last = first - last;
first = first - last;

printf("the swape value of first and last digit\n");


printf("the first digit is %d\n", first);
printf("the last digit is :%d\n", last);
}

OUTPUT:
Enter the number:2839
the swape value of first and last digit:
the first digit is :9
the last digit is :2
15)

#include<stdio.h>
#include<conio.h>
int main()
{ int n,s=0,first ,last;

printf("enter the numebr ");


scanf("%d", & n);

last=n%10;

while(n>=10)
{
n=n/10;
}
first=n;

s=first+last;
printf("sum of first and last digit :%d\n", s);

return 0;

OUTPUT:
Enter the number:2889
sum of first and last digit :11

16)

#include<stdio.h>
#include<conio.h>
int main()
{ int n,r;

printf("enter the number:");


scanf("%d", & n);

while(n)
{
r=n%10;
printf("%d", r);
n=n/10;
}

}
OUTPUT:
Enter the number:4589
9854

17)

#include<stdio.h>
#include<conio.h>
int main()
{ int n,r,temp,s=0;
printf("Enter the number:");
scanf("%d", & n);

temp=n;
while(n)
{
r=n%10;
s=s*10+r;
n=n/10;

}
if(temp==s){
printf("pelindrom");
}
else{
printf("not a pelindrom");
}

OUTPUT:
Enter the number:1001
pelindrom

Enter the number:596


not pelindrom

19)

#include<stdio.h>
#include<conio.h>
int main()
{ int n,r,arn=0;

printf("enter the number:");


scanf("%d", & n);

while(n>0)
{
arn=(arn*10)+(n%10);
n=n/10;
}
while(arn>0)
{
r=arn%10;
if(r==0){
printf("zero\t");
}
else if(r==1){
printf("one\t");
}
else if(r==2){
printf("two\t");

}
else if(r==3){
printf("three\t");

}
else if(r==4){
printf("four\t");

}
else if(r==5){
printf("five\t");

}
else if(r==6){
printf("six\t");

}
else if(r==7){
printf("seven\t");

}
else if(r==8){
printf("Eight\t");

}
else if(r==9){
printf("nine\t");

}else
{
printf("invalid");
}
arn=arn/10;
}
return 0;

OUTPUT:
Enter the number:4639
four six three nine

20)
#include <stdio.h>
#include <conio.h>
int main()
{
int count = 0;

while (count <= 255)


{
printf("ASCII value of %c is %d\n", count, count);
count++;
}
return 0;
}

21)

#include<stdio.h>
#include<conio.h>
int main()
{ int a,b,p=1,i=1;

printf("Enter the numebr a :");


scanf("%d", & a);

printf("enter the number b:");


scanf("%d", & b);

while(i<=b)
{
p=p*a;
i++;

}
printf("%d",p);
return 0;

OUTPUT:
Enter the number a:2
Enter the number b:3

22)

#include<stdio.h>
#include<conio.h>
int main()
{ int n,i=1;

printf("Enter the number:");


scanf("%d", & n);

while(i<=n)
{
if(n%i==0){
printf("%d ", i);}
i++;

}
return 0;
}

OUTPUT:
Enter the number:10
1 2 5 10

23)

#include<stdio.h>
#include<conio.h>
int main()
{ int n,fact,i=1,sum=0;

printf("Enter the number:");


scanf("%d", & n);
fact=n;
while(i<n)
{
fact=fact*i;
i++;
}
printf("final factorial is:%d", fact);

return 0;
}

OUTPUT:
Enter the number:5
the funal fatorial is : 120

24)
#include <stdio.h>
#include <conio.h>
int main()
{
int a, b, h;

printf("Enter two numbers:");


scanf("%d%d", &a, &b);

for (h = a < b ? a : b; h >= 1; h--)


{

if (a % h == 0 && b % h == 0)
break;
}
printf("Hcf is %d", h);
return 0;
}
OUTPUT:

Enter two numbers: 24 60


Hcf is 12

25)

#include <stdio.h>
#include <conio.h>
int main()
{
int a, b, L;

printf("Enter two numbers:");


scanf("%d%d", &a, &b);

for (L=1;L<=a*b; L++)


{

if (L % a == 0 && L % b == 0)
break;
}
printf("Lcm is %d", L);
return 0;
}
OUTPUT:
Enter two number :4 6
Lcm is 12
26)

#include<stdio.h>
#include<conio.h>
int main()
{ int n,count=0,i=1;

printf("Enter the number:");


scanf("%d",& n);

while(i<=n)
{
if(n%i==0)
count++;
i++;

}
if(count==2){
printf("prime");
}
else{
printf("not prime");

}
OUTPUT:
Enter the number:17
prime

27)

#include<stdio.h>
#include<conio.h>
int main()
{ int n,r,temp,s=0;

printf("Enter the number:");


scanf("%d", & n);
temp=n;
while(n>0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;

}
if(temp==s){
printf("armastrong");
}
else{
printf("not armstrong");
}
return 0;

OUTPUT:
Enter the number:153
armstrong

28)

#include<stdio.h>
#include<conio.h>
int main()
{ int n,s=0,r,i=1,p=1;

printf("Enter the number:");


scanf("%d", & n);

while(n>0)
{
r=n%10;
s=s+r;
p=p*r;
n=n/10;
}
if(s==p){
printf("perfect");
}
else{
printf("not perfect");
}
return 0;

OUTPUT:
Enter the number:6
number is perfect

36)

#include <stdio.h>
#include <conio.h>
int main()
{
int n, c, a = -1, b = 1, i;

printf("Enter the number :");


scanf("%d", &n);

for (i = 1; i <= n; i++)


{
c = a + b;
printf("%d ", c);
a = b;
b = c;
}
return 0;
}
OUTPUT:
Enter the number :6
011235

39)
#include <stdio.h>
#include <conio.h>
int main()
{
int i = 1, n, octal = 0, r;

printf("Enter the binary number :");


scanf("%d", &n);

while (n != 0)
{
r = n % 10;
octal = octal + (r * i);
i = i * 2;
n = n / 10;
}
printf(" octal number is :%d", octal);
return 0;
}

OUTPUT:
Enter the binary number : 1001
octal number is : 9

40)

#include <stdio.h>
#include <conio.h>
int main()
{
int i = 1, n,decimal = 0, r;

printf("Enter the binary number :");


scanf("%d", &n);

while (n != 0)
{
r = n % 10;
n = n / 10;
decimal = decimal + (r * i);
i = i * 2;

}
printf(" decimal number is :%d",decimal);
return 0;
}

OUTPUT:
Enter the binary number : 0111
decimal number is : 7

41)

You might also like