for loop all program list with output in c language 2021

for loop all program list with output in c language 2021
for loop all program list with output in c language 2021

For Loop All Program: A for loop is a control flow statement that allows us to execute a block of code multiple times.


Initialize is the starting value for the counter. Condition is the condition under which the body will be executed. Increment specifies how will be incremented after each iteration. The last part of our code block code will be executed each time the loop executes.

How to print table 1 to 10?

#include<stdio.h>

int main()

{

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

{

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

}

}

*****OUTPUT*****

1

2

3

4

5

6

7

8

9

10

How to print a table of any number.

#include<stdio.h>

int main()

{

int no;

printf("Enter any Number:");

scanf("%d",&no);

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

{

printf("%d ",i*no);

}

}

*****OUTPUT*****

Enter any Number:12

12 24 36 48 60 72 84 96 108 120

How to print all natural of any number.

#include<stdio.h>

int main()

{

int no;

printf("Enter any Number:");

scanf("%d",&no);

printf("Natural no from 1 to %d is given below\n",no);

for(int i=1;i<=no;i++)

{

printf("%d ",i);

}

}

*****OUTPUT*****

Enter any Number:20

Natural no from 1 to 20 is given below

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

How to print reverse all natural number .

#include<stdio.h>

int main()

{

int no;

printf("Enter any Number:");

scanf("%d",&no);

printf("Natural no from 1 to %d in reverse order is given below\n",no);

for(int i=no;i>=1;i--)

{

printf("%d ",i);

}

}

*****OUTPUT*****

Enter any Number:20

Natural no from 1 to 20 in reverse order is given below

20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

How to print all natural number sum.

#include<stdio.h>

int main()

{

int no,sum=0;

printf("Enter any Number:");

scanf("%d",&no);

printf("Natural no from 1 to %d is given below\n",no);

for(int i=1;i<=no;i++)

{

printf("%d ",i);

sum=sum+i;

}

printf("\nTotal sum=%d",sum);

}

*****OUTPUT*****

Enter any Number:20

Natural no from 1 to 20 is given below

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Total sum:210

How to print all Uppercase Alphabets.

#include<stdio.h>

int main()

{

for(char ch='A';ch<='Z';ch++)

{

printf("%c ",ch);

    }

}

*****OUTPUT*****

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

How to print all Lowercase Alphabets.

#include<stdio.h>

int main()

{

for(char ch='a';ch<='z';ch++)

{

printf("%c ",ch);

    }

}

*****OUTPUT*****

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

How to print all even number 1 to 30.

#include<stdio.h>

int main()

{

printf("Even number b/w 1 and 20 is given below\n");

 for(int i=2;i<=30;i=i+2)

 {

  printf("%d ",i);

 }

}

*****OUTPUT*****

Even number b/w 1 and 20 is given below

2 4 6 8 10 12 14 16 18 20 22 24 26 28 30


How to print all odd number 1 to 30.

#include<stdio.h>

int main()

{

printf("Odd number b/w 1 and 20 is given below\n");

 for(int i=1;i<=20;i=i+2)

 {

  printf("%d ",i);

 }

}

*****OUTPUT*****

Odd number b/w 1 and 20 is given below

1 3 5 7 9 11 13 15 17 19 21 23 25 27 29

How to print all  Alphabets Ascii Value. 

#include<stdio.h>

int main()

{

for(char ch='A';ch<='Z';ch++)

{

printf("%c=%d\n",ch,ch);

}

}

*****OUTPUT*****

A=65

B=66

C=67

D=68

E=69

F=70

G=71

H=72

I=73

J=74

K=75

L=76

M=77

N=78

O=79

P=80

Q=81

R=82

S=83

T=84

U=85

V=86

W=87

X=88

Y=89

Z=90

How to find factorial of any number.

#include<stdio.h>

int main()

{

int no,f=1;

printf("Enter any Number:");

scanf("%d",&no);

for(int i=1;i<=no;i++)

{

f=f*i;

}

printf("Factorial Vlaue:%d",f);

}

*****OUTPUT*****

Enter any Number:6

Factorial Vlaue:720

How to find factor of any number.

#include<stdio.h>

int main()

{

int no,f=1;

printf("Enter any Number:");

scanf("%d",&no);

printf("Factor is given below\n");

for(int i=1;i<=no;i++)

{

if(no%i==0)

printf("%d ",i);

}

}

*****OUTPUT*****

Enter any Number:720

Factor is given below

1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 30 36 40 45 48 60 72 80 90 120 144 180 240 360 720

How to find power of any number.

#include<stdio.h>

int main()

{

int b,p,f=1;

printf("Enter Base:");

scanf("%d",&b);

printf("Enter Power:");

scanf("%d",&p);

for(int i=1;i<=p;i++)

{

f=f*b;

}

printf("Result:%d",f);

}

*****OUTPUT*****

Enter Base:20

Enter Power:2

Result:400

How to find LCM of any two number.

#include<stdio.h>

int main()

{

int no1,no2;

printf("Enter first number\n");

scanf("%d",&no1);

printf("Enter second number\n");

scanf("%d",&no2);


 for(int i=1;;i=i+1)

 {

  if(i%no1==0&&i%no2==0)

  {

    printf("LCM of %d and %d is %d",no1,no2,i);

   break;

}

 }

}

*****OUTPUT*****

Enter first Number:45

Enter second Number:7

LCM of 45 and 7 is 315

How to find HCF of any two number.

#include<stdio.h>

int main()

{

int no1,no2,m=1;

printf("Enter first Number:");

scanf("%d",&no1);

printf("Enter second Number:");

scanf("%d",&no2);

 for(int i=1;i<=no1;i=i+1)

 {

  if(no1%i==0&&no2%i==0)

  {

  m=i;

}

 }

 printf("HCF of %d and %d is %d",no1,no2,m);

}

*****OUTPUT*****

Enter first Number:45

Enter second Number:9

HCF of 45 and 9 is 9

How to check number is prime or not.

#include<stdio.h>

int main()

{

int no,m=0;

printf("Enter any Number:");

scanf("%d",&no);

for(int i=2;i<=no-1;i++)

{

if(no%i==0)

{

printf("Number is not  Prime");

m=1;

break;

}

}

if(m==0)

printf("Number is prime");

}

*****OUTPUT*****

Enter any Number:3

Number is prime


How to print prime number list of any number.  

#include<stdio.h>

int main()

{

int n,m,num;

printf("Enter any Number:");

scanf("%d",&num);

printf("Prime number between 1 and %d is given below\n",num);

for(int i=1;i<=num;i++)

{

n=i,m=0;

for(int j=2;j<=n-1;j++)

    {

if(n%j==0)

  {

m=1;

break;

  }

    }

if(m==0)

printf("%d ",n);

}

}

*****OUTPUT*****

Enter any Number:30

Prime number between 1 and 30 is given below

1 2 3 5 7 11 13 17 19 23 29

How to find fabonacci series of any number.

#include<stdio.h>

int main()

{

 int no,a,b=1,c=0;

 printf("Enter any number upto you want to print fabonacci series:");

 scanf("%d",&no);

 for(int i=1;i<=no;i++)

 {

  printf("%d ",c);

  a=b;

  b=c;

  c=a+b;

 }

}

*****OUTPUT*****

Enter any number up to you want to print Fibonacci series:10

0 1 1 2 3 5 8 13 21 34


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.