Question
- WAP to read 10 numbers from user and find their sum and average.
- WAP to display the multiplication table of integer given by the user.
- WAP to input two integer values from the user and print the even number between the range of integers. Also count the even number and display the count as well [Hint: if user enters 10 and 100. The program should print and count even numbers between 10 and 100].
- WAP to display sum of series: 1 + 1/2 + 1/3 + 1/4 + 1/5 ... 1/n
- WAP to display sum of series: 1 + 1/2! + 1/3! + 1/4! + 1/5! ... 1/n!
- WAP to display sum of series: x + x2/2! + x3/3! + x4/4! + x5/5! ... xn/n!
- WAP to find the value cos(x) without using cos(x) library function.
- WAP to display weather a number is Armstrong or not.
- WAP to display the first n terms of Fibonacci series.
- WAP to display the number in reverse order.
- WAP to check whether a number is a palindrome or not.
- WAP to find HCF and LCM of two numbers.
-
WAP to print the following patterns:
-
1 12 123 1234 12345
-
12345 1234 123 12 1
-
* *** ***** ******* *********
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
-
1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1
-
5 4 3 2 1 5 4 3 2 5 4 3 5 4 5
-
Solution:
Lab Sheet 5: To be familiar with LOOPS
1. WAP to read 10 numbers from the user and find their sum and average.
C Program: Code
#include <stdio.h>
int main()
{
int a,b=0,i;
printf("Enter 10 Number:\n");
for (i=1;i<=10;i++)
{
scanf("%d",&a);
b=b+a;
}
printf("Sum of 10 number given by user is %d.",b);
return 0;
}
int main()
{
int a,b=0,i;
printf("Enter 10 Number:\n");
for (i=1;i<=10;i++)
{
scanf("%d",&a);
b=b+a;
}
printf("Sum of 10 number given by user is %d.",b);
return 0;
}
Output:
Discussion and Conclusion:
Discussion:Conclusion:
2. WAP to display the multiplication table of integers given by the user.
C Program: Code
#include<stdio.h>
int main()
{
int a,i,b;
printf("Enter any Number:\n");
scanf("%d",&a);
for (i=1;i<=10;i++)
{
b=a*i;
printf("%d * %d = %d\n",a,i,b);
}
return 0;
}
int main()
{
int a,i,b;
printf("Enter any Number:\n");
scanf("%d",&a);
for (i=1;i<=10;i++)
{
b=a*i;
printf("%d * %d = %d\n",a,i,b);
}
return 0;
}
Output:
Discussion and Conclusion:
Discussion:Conclusion:
3. WAP to input two integer values from the user and print the even number between the range of integers. Also, count the even number and display the count as well [Hint: if the user enters 10 and 100. The program should print and count even numbers between 10 and 100].
C Program: Code
#include<stdio.h>
int main()
{
int a,b,i,c=0,d=0;
printf("Enter the starting Number:\n");
scanf("%d",&a);
printf("Enter the ending number:\n");
scanf("%d",&b);
for (i=a;i<=b;i++)
{
c=i%2;
if(c==0)
{
printf("%d\t",i);
d=d+1;
}
}
printf("\n There are total %d even numbers.",d);
return 0;
}
int main()
{
int a,b,i,c=0,d=0;
printf("Enter the starting Number:\n");
scanf("%d",&a);
printf("Enter the ending number:\n");
scanf("%d",&b);
for (i=a;i<=b;i++)
{
c=i%2;
if(c==0)
{
printf("%d\t",i);
d=d+1;
}
}
printf("\n There are total %d even numbers.",d);
return 0;
}
Output:
Discussion and Conclusion:
Discussion:Conclusion:
4. WAP to display sum of series: 1 + 1/2 + 1/3 + 1/4 + 1/5 ... 1/n
C Program: Code
#include <stdio.h>
int main()
{
int i, n;
float sum = 0;
printf("Enter the value of n: \n");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
sum = sum + 1.0 / i;
}
printf("The sum of the above series up to %d th term is %f", n, sum);
return 0;
}
int main()
{
int i, n;
float sum = 0;
printf("Enter the value of n: \n");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
sum = sum + 1.0 / i;
}
printf("The sum of the above series up to %d th term is %f", n, sum);
return 0;
}
Output:
Discussion and Conclusion:
Discussion:Conclusion:
5. WAP to display sum of series: 1 + 1/2! + 1/3! + 1/4! + 1/5! ... 1/n!
C Program: Code
Code
Output:
Discussion and Conclusion:
Discussion:Conclusion:
6. WAP to display sum of series: x + x2 /2! + x3 /3! + x4 /4! + x5 /5! ... x n /n!
C Program: Code
Code
Output:
Discussion and Conclusion:
Discussion:Conclusion:
7. WAP to find the value cos(x) without using cos(x) library function.
C Program: Code
Code
Output:
Discussion and Conclusion:
Discussion:Conclusion:
8. WAP to display weather a number is Armstrong or not.
C Program: Code
Code
Output:
Discussion and Conclusion:
Discussion:Conclusion:
9. WAP to display the first n terms of Fibonacci series.
C Program: Code
Code
Output:
Discussion and Conclusion:
Discussion:Conclusion:
10. WAP to display the number in reverse order.
C Program: Code
Code
Output:
Discussion and Conclusion:
Discussion:Conclusion:
11. WAP to check whether a number is a palindrome or not.
C Program: Code
Code
Output:
Discussion and Conclusion:
Discussion:Conclusion:
12. WAP to find HCF and LCM of two numbers.
C Program: Code
Code
Output:
Discussion and Conclusion:
Discussion:Conclusion:
13. WAP to print the following patterns:
-
1
12
123
1234
12345
-
12345
1234
123
12
1
-
*
***
*****
*******
*********
-
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
-
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
-
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
1 12 123 1234 12345
12345 1234 123 12 1
* *** ***** ******* *********
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 2 3 4 5 4 3 2 1 1 2 3 4 3 2 1 1 2 3 2 1 1 2 1 1
5 4 3 2 1 5 4 3 2 5 4 3 5 4 5
C Program: Code
Code
Output:
Discussion and Conclusion:
Discussion:Conclusion: