For Loop

              
                        1.TABLE OF ONE:

#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

                                                 2.TABLE OF ANY NUMBER: 

#include<stdio.h>
int main()
{
int no;
printf("Enter any number\n");
scanf("%d",&no);
for(int i=1;i<=10;i++)
{
printf("%d ",i*no);
}
}

•OUTPUT 
5
5 10 15 20 25 30 35 40 45 50

                                 3.PRINT ANY NATURAL NUMBER FORM 1 TO N:


#include<stdio.h>
int main()
{
int no;
printf("Enter any number\n");
scanf("%d",&no);
for(int i=1;i<=10;i++)
{
printf("%d ",i*no);
}
}
•OUTPUT
 

Enter any number
8
Natural number from 1 to 8 is given below
1 2 3 4 5 6 7 8

                              4.PRINT All NATURAL NUMBER FORM 1 TO N:


#include<stdio.h>
int main()
{
int no;
printf("Enter any number\n");
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
8
Natural number from 1 to 8 in reverse is given below
8 7 6 5 4 3 2 1

                      5.PRINT SUM OF NATURAL NUMBER FORM 1 TO N:

#include<stdio.h>
int main()
{
int no,sum=0;
printf("Enter any number\n");
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
8
Natural number from 1 to 8 is given below
1 2 3 4 5 6 7 8
Total sum=36

                                             6.PRINT A B C.....Z METHOD 1 :


#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

                     7.PRINT A B C.....Z USING ASCII VALUE METHOD 2 :


#include<stdio.h>
int main()
{
for(int i=65;i<=90;i++)
{
printf("%c ",i);
    }
}
 
•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

                                                 8.PRINT A B C......Z METHOD 1:

#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

                           9.PRINT A B C.....Z USING ASCII VALUE METHOD 2 :


#include<stdio.h>
int main()
{
for(int i=97;i<=122;i++)
{
printf("%c ",i);
    }
}
•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

                      10.PRINT ALL EVEN NUMBER  BETWEEN  1 AND 20 METHOD 1:


#include<stdio.h>
int main()
{
printf("Even number b/w 1 and 20 is given below\n");
 for(int i=2;i<=20;i=i+2)
 {
  printf("%d ",i);
 }
}
•OUTPUT 

Even number between 1 and 20 is given below
2 4 6 8 10 12 14 16 18 20

                11.PRINT ALL EVEN NUMBER BETWEEN  1 AND 20 METHOD 2 :


#include<stdio.h>
int main()
{
printf("Even number b/w 1 and 20 is given below\n");
 for(int i=2;i<=20;i=i+1)
 {
  if(i%2==0)
  printf("%d ",i);
 }
}

•OUTPUT
 

Even number between 1 and 20 is given below                       
2 4 6 8 10 12 14 16 18 20

                      12.PRINT ALL ODD NUMBER BETWEEN  1 AND 20 METHOD 1 :

#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 between 1 and 20 is given below
1 3 5 7 9 11 13 15 17 19

                   13.PRINT ALL ODD NUMBER BETWEEN  1 AND 20 METHOD 2 :


#include<stdio.h>
int main()
{
printf("Odd number b/w 1 and 20 is given below\n");
 for(int i=2;i<=20;i=i+1)
 {
  if(i%2!=0)
  printf("%d ",i);
 }
}
•OUTPUT 

Odd number between 1 and 20 is given below
1 3 5 7 9 11 13 15 17 19

                           14.PRINT ASCII VALUE OF ALPHABET FROM A TO Z:


#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

                                    15.FIND FACTORIAL OF ANY NUMBER :

#include<stdio.h>
int main()
{
int no,f=1;
printf("Enter any number\n");
scanf("%d",&no);
for(int i=1;i<=no;i++)
{
f=f*i;
}
printf("Factorial=%d",f);
}
•OUTPUT
 

Enter any number 
6
Factorial=720

                                      16.FACTOR OF ANY NUMBER: 

#include<stdio.h>
int main()
{
int no,f=1;
printf("Enter any number\n");
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 
8
Factor is given below 
1 2 4 8

                                       17.POWER OF ANY NUMBER: 


#include<stdio.h>
int main()
{
int b,p,f=1;
printf("Enter base\n");
scanf("%d",&b);
printf("Enter power\n");
scanf("%d",&p);
for(int i=1;i<=p;i++)
{
f=f*b;
}
printf("Result=%d",f);
}
•OUTPUT
 

Enter base
2
Enter power 
5
Result=32

                                      18.LCM OF ANY 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 
4
Enter second number 
6
LCM of 4 and 6 is 12

                                              19.HCF OF TWO NUMBER :

#include<stdio.h>
int main()
{
int no1,no2,m=1;
printf("Enter first number\n");
scanf("%d",&no1);
printf("Enter second number\n");
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 
16
Enter second number 
24
HCF of 16 and 24 is 8

                                20.CHECK GIVEN NUMBER PRIME OR NOT:


#include<stdio.h>
int main()
{
int no,m=0;
printf("Enter any number\n");
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 
43
Number is prime

                                   21.PRINT PRIMIME NUMBER FROM 1 TO N:



#include<stdio.h>
int main()
{
int n,m,num;
printf("Enter any number upto you want to print prime number\n");
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 upto you want to print prime number 
20
Prime number between 1 and 20 is given below 
1 2 3 5 7 11 17 19

                         22.PRINT FABONACCI SERIES UPTO N TERMS:


#include<stdio.h>
int main()
{
 int no,a,b=1,c=0;
 printf("Enter any number upto you want to print fabonacci series\n");
 scanf("%d",&no);
 for(int i=1;i<=no;i++)
 {
 	printf("%d ",c);
 	a=b;
 	b=c;
 	c=a+b;
 }
}
•OUTPUT 

Enter any number upto you want to print fabonacci series 
8
0 1 1 2 3 5 8 13


Comments

Popular posts from this blog

SWITCH PROGRAMME