Lab Assignment 5
Lab Assignment 5
Course-BTech(CSE)
Roll No.-24155589
#include <stdio.h>
int main()
{ INPUT:
int a,i; Enter a number=634
i=0;
printf("Enter a number=");
scanf("%d",&a);
do
{ OUTPUT:
i=i+1; The number of digits
a=a/10; are 3
}while(a>0);
printf("The number of digits are %d",i);
return 0;
}
Question 7)Find the sum of numbers entered using do...while loop
#include <stdio.h>
int main()
{
Input:
int a,b,s=0;
printf("Enter the number="); Enter the number=234
scanf("%d",&a);
do
{
b=a%10;
s=s+b; Output:
a=a/10; The sum of digits is 9
} while (a>0);
printf("The sum of digits is
%d",s);
return 0;
}
Question 8)Multiply two positive numbers without using * operator
#include <stdio.h>
int main()
{ Input:
int a,i,s=1,r=0; Enter the number of terms needed:7
printf("Enter the number of terms
needed:");
scanf("%d",&a);
for(i=1;i<=a;i++)
{ Output:
r=r+s; The sum of series till 7 is 63
s=s+i;
}
printf("The sum of series till %d is
%d",a,r);
return 0;
}
Question 10)Generate Fibonacci series 1,1,2,3,5,8,13,34,55,89
#include <stdio.h>
int main()
{ Input:
long a,b,c; Enter the number of terms required:7
int i,j;
printf("Enter the number of terms required:");
scanf("%d",&j);
a=0;
b=1;
printf("%d\t",b);
for(i=0;i<=j;i++)
{ Output:
c=a+b; 1 1 2 3 5 8 13
printf("%d\t",c);
a=b;
b=c;
}
return 0;
}