A )))) //Display 4 numbers(While Loop)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i=1;
while(i<=4)
{
printf("%d\n",i);
i=i+1;
}
getch();
}
---------------------------------------------
Output
1
2
3
4
===============================================
B )))) //Display 4 numbers(for loop)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i=1;
for(i=1;i<=4;i=i+1)
{
printf("%d\n",i);
}
getch();
}
---------------------------------------
Output
1
2
3
4
==============================================
C ))) //To display any 10 numbers using arrays(Our choice)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,a[10];
printf("Enter 10 nos\n");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
printf("The 10 nos are:\n");
for(i=0;i<10;i++)
{
printf("%d\n",a[i]);
}
getch();
}
------------------------------------------------------------
Output
Enter 10 numbers (Enter 10 numbers as per your choice)
1
2
3
4
5
6
8
4
5
6
The 10 numbers are :
1
2
3
4
5
6
8
4
5
6
===============================================
D ))) //To display 10 numbers using arrays
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,a[10];
printf("Displaying 10 nos using arrays:\n");
for(i=0;i<=10;i++)
{
printf("%d\n",a[i]);
}
getch();
}
(May be some error in output)
===============================================
E ))) //Display n nos using Arrays(any numbers upto the given limit)
(Note the difference in the output of E and F)
2
Enter 2 numbers
3
4
The nos are:
3
4
===============================================
G ))) //Display n numbers(Do-While)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i=1,n;
printf("How many nos you want to display\n");
scanf("%d",&n);
do
{
printf("%d\n",i);
i=i+1;
}
while(i<=n);
getch();
}
---------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i=1,n;
printf("How many nos you want to display\n");
scanf("%d",&n);
while(i<=n)
{
printf("%d\n",i);
i=i+1;
}
getch();
}
J ))) //Display n numbers(For loop) - Not as per our choice
Refer Eg:H
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i=1,n;
for(i=1;i<=10;i=i+1)
{
printf("%d\n",i);
}
getch();
}
E ))) //Display n nos using Arrays(any numbers upto the given limit)
(Note the difference in the output of E and F)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,a[100];
printf("How many nos you want to display\n");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
printf("%d",a[i]);
}
getch();
}
------------------------------------------------------------
Output
How many nos you want to display
3
1
2
3
===============================================
F ))) //Display n nos using Arrays(any numbers upto the given limit)
(Note the difference in the output of E and F)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
print i,n,a[100];
printf("How many nos you want to display\n");
scanf("%d",&n);
printf("Enter %d no\n",n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("The nos are:\n");
for(i=1;i<=n;i++)
{
printf("%d\n",a[i]);
}
getch();
}
------------------------------------------------------------
Output
How many nos you want to displayEnter 2 numbers
3
4
The nos are:
3
4
===============================================
G ))) //Display n numbers(Do-While)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i=1,n;
printf("How many nos you want to display\n");
scanf("%d",&n);
do
{
printf("%d\n",i);
i=i+1;
}
while(i<=n);
getch();
}
---------------------------------------------------------
Output
How many nos you want to display
3
1
2
3
===============================================
H ))) //Display n numbers(For loop) (As per our choice)
Refer Eg:J#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i=1,n;
printf("How many nos you want to display\n");
scanf("%d",&n);
for(i=1;i<=n;i=i+1)
{
printf("%d\n",i);
}
getch();
}
---------------------------------------------------------
Output
How many nos you want to display
3
1
2
3
===============================================
I ))) //Display n numbers(While loop)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i=1,n;
printf("How many nos you want to display\n");
scanf("%d",&n);
while(i<=n)
{
printf("%d\n",i);
i=i+1;
}
getch();
}
---------------------------------------------------------
Output
How many nos you want to display
3
1
2
3
==============================================
Refer Eg:H
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i=1,n;
for(i=1;i<=10;i=i+1)
{
printf("%d\n",i);
}
getch();
}
---------------------------------------------------------
Output
1
2
3
4
5
6
7
8
9
10
No comments:
Post a Comment