π₯π₯ Practice Set of Chapter 4 π₯π₯
π₯Table of any number by C language: set the value test condition in loop as i<=10 to print the table till the ultiplication of 10.
#include <stdio.h>
int main()
{
int a, i;
printf("Enter the digit to get table of that number:\n");
scanf("%d", &a);
for (i = 1; i <= 10; i++)
{
printf("Table of %d x %d = %d\n", a, i, a * i);
}
return 0;
}
π₯Reverse table of the given digit by c in this we have to we have to dont give any test condition in loop just and decrement the loop.
#include <stdio.h>
int main()
{
int a, i;
printf("Enter the digit to get reverse table of that digit:");
scanf("%d", &a);
for (i = 10; i; i--)
{
printf("Table of %d x %d = %d\n", a, i, a * i);
}
return 0;
}
π₯ π₯π₯π₯Find the Prime number program by c which means prime is divided by only self or with 1 so we have to
#include <stdio.h>
int main()
{
int a, i = 2, prime = 0;
printf("Enter the number to find it is Prime or not: ");
scanf("%d", &a);
//BY USING FOR LOOP
// for (i = 2; i < a; i++)
// {
// if (a % i == 0)
// {
// prime = 1;
// }
// }
//BY USING WHILE LOOP
// while (i < a)
// {
// if (a % i == 0)
// {
// prime = 1;
// }
// i++;
// }
//BY USING DO WHILE LOOP
do
{
if (a % i == 0)
{
prime = 1;
}
i++;
} while (i < a);
if (prime == 1)
{
printf("%d is not Prime Number\n", a);
}
else
{
printf("%d is Prime Number\n", a);
}
return 0;
}
π₯π₯ SUM = SUM +i ; || SUM +=i;
#include <stdio.h>
int main()
{
int a, i = 1, sum = 0;
printf("Enter the number to add\n");
scanf("%d", &a);
// for (i = 1; i <= a; i++)
// {
// sum += i;
// }
// while (i <= a)
// {
// sum = sum + i;
// i++;
// }
do
{
sum = sum + i;
i++;
} while (i <= a);
printf("Additon of (1 to %d): %d\n", a, sum);
return 0;
}
π₯
#include <stdio.h>
int main()
{
int a, i, table = 0, sum = 0;
printf("Enter the Number to get sum of that table:");
scanf("%d", &a);
for (i = 1; i <= 10; i++)
{
table = a * i;
printf("Table of %d x %d = %d\n", a, i, table);
sum = sum + table;
}
printf("Addition of %d Table is: %d\n", a, sum);
return 0;
}
d
#include <stdio.h>
int main()
{
int a, i = 1, factorial = 1;
printf("Enter the number to find the factorial:");
scanf("%d", &a);
// for (i = 1; i <= a; i++)
// {
// factorial = factorial * i;
// // printf("Factorial of %d:", factorial);
// }
while (i <= a)
{
factorial = factorial * i;
i++;
}
printf("Factorial of %d: %d", a, factorial);
return 0;
}
Comments
Post a Comment