0% found this document useful (0 votes)
25 views8 pages

Exercise - 6

The document contains C code for 10 different programs that demonstrate various concepts: 1. A program that calculates the power of a number using a for loop. 2. A program that calculates the sum of natural numbers up to a given value using a for loop. 3. A program that takes 10 numbers as input, calculates their average and sum. 4. A program that creates an infinite loop to continuously take two numbers as input and calculate their product. 5. A program that checks if a given number is prime using a for loop. 6. A program that finds all factors of a given number using a for loop. 7. A program that counts the digits of a number using a

Uploaded by

ragulmech362
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views8 pages

Exercise - 6

The document contains C code for 10 different programs that demonstrate various concepts: 1. A program that calculates the power of a number using a for loop. 2. A program that calculates the sum of natural numbers up to a given value using a for loop. 3. A program that takes 10 numbers as input, calculates their average and sum. 4. A program that creates an infinite loop to continuously take two numbers as input and calculate their product. 5. A program that checks if a given number is prime using a for loop. 6. A program that finds all factors of a given number using a for loop. 7. A program that counts the digits of a number using a

Uploaded by

ragulmech362
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

EXERCISE – 6

POWER VALUE OF NUMBER:


#include <stdio.h>

int main() {

int i,a,b,e;

e=1;

printf("Enter the value: ");

scanf("%d",&a);

printf("Enter the exponent: ");

scanf("%d",&b);

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

e=e*a;

printf("%d",e);

return 0;

}
NATURAL NUMBERS AND THEIR SUM:
#include <stdio.h>

int main() {

int i,a,n;

printf("Enter the upto value: ");

scanf("%d",&n);

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

printf("%d\n",i);

a=a+i;

printf("%d",a);

return 0;

10 NUMBERS AND THEIR AVERAGE AND SUM:


#include <stdio.h>

int main() {

int i,a,n,s;

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

printf("Enter number: ");

scanf("%d",&n);

s=s+n;

a=s/10;

printf("Total value is %d\n",s);

printf("Average of total is %d",a);

return 0;

}
INFINITY LOOP:
#include <stdio.h>

int main() {

int a,b,c;

for(;;)

printf("Enter the first value: ");

scanf("%d",&a);

printf("Enter the second value: ");

scanf("%d",&b);

c=a*b;

printf("The answer is %d\n",c);

return 0;

}
PRIME NUMBER CHECKING:
#include <stdio.h>

int main() {

int i,n,f=0;

printf("Enter the number: ");

scanf("%d",&n);

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

if(n%i==0)

f++;

if(f==2)

printf("It is a prime number");

else

printf("It is not a prime number");

return 0;

}
FACTORS FINDING :
#include <stdio.h>

int main() {

int i,n,a;

printf("Enter the number: ");

scanf("%d",&n);

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

if(n%i==0)

printf("Factors are %d\n",i);

a++;

printf("Total number of factors is %d",a);

return 0;

}
DIGITS COUNTING:
#include <stdio.h>

int main() {

int i,n,a;

printf("Enter the number: ");

scanf("%d",&n);

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

n=n/10;

printf("Number of digits is %d",i);

return 0;

FACTORIAL:
#include <stdio.h>

int main() {

int i,n,r=1;

printf("Enter the Factorial number: ");

scanf("%d",&n);

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

r=r*i;

printf("Factorial value is %d",r);

return 0;

}
SQUARE NATURAL NUMBERS AND THEIR SUM:
#include <stdio.h>

int main() {

int i,n,a,b;

printf("How much of numbers do you need?\n");

scanf("%d",&n);

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

b=i*i;

printf("The Square of %d is %d\n",i,b);

a=a+b;

printf("The Sum of the square Numbers is %d",a);

return 0;

}
100 – 200 WHICH ARE DIVISIBLE BY 9 AND THEIR SUM:
#include <stdio.h>

int main() {

int i,n,a,b;

i=100,b=200;

for(i=100;i<=b;++i)

if(i%9==0)

printf("%d\n",i);

a=a+b;

printf("Sum of the numbers is %d",a);

return 0;

You might also like