closed To print natural numbers from 1 to 32767

–4 votes
asked Jul 2, 2018 by anonymous
closed Jun 14 by Admin
main()
{
int i=1;
while(i<=32767)
{
 printf("\n %d",i);
 i=i++;
}
}
closed with the note: Since it as been answered.

18 Answers

0 votes
answered Jul 2, 2018 by Sanjay Ganesh (140 points)

#include<stdio.h>

void main()

{

long P=1;

while( P == 32768 )

{

printf("%d",P);

P++;

}

}

0 votes
answered Jul 4, 2018 by PRAVEEN
main()

{

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

{

printf("%d",i);

}
commented Oct 7, 2018 by Faizan Farooqui (120 points)
1 WILL BE PRINTED 32767 TIMES ITS A LOOP
commented Jun 11 by Peter Minarik (7,830 points)
No, it will print all the integral numbers from 1 til 32767 (inclusive) just fine.
0 votes
answered Jul 4, 2018 by anonymous
#include<stdio.h>
int main()
{
long long int i=1;
while(i<=32767)
{

 i++;
}
 printf("\n %lld",i);
}
+1 vote
answered Jul 4, 2018 by subiksha ks (170 points)
#include <iostream>

using namespace std;

int main()
{
    for(long int i=1;i<=32767;i++)
        cout<<i<<"\t";

    return 0;
}
+1 vote
answered Jul 6, 2018 by anonymous
#include <iostream>

using namespace std;

int main()
{
    int limit = 32767;
    int x = 1;
    while(x <= 32767)
    {
        cout << x << endl;
        x++;
    }

    return 0;
}
0 votes
answered Jul 6, 2018 by Raju Prudhvi (160 points)
main()

{

int i;

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

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

}
0 votes
answered Jul 6, 2018 by Akhila Mekapothula (460 points)
#include<stdio.h>

main()

{

int  i,n;

printf("enter no.of natural numbers to print\n");

scanf("%d",&n);

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

{

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

}

}
0 votes
answered Jul 6, 2018 by Akhila Mekapothula (460 points)
#include<stdio.h>

main()

{

int i,n;

printf("enter no.of natural numbers\n");

scanf("%d",&n);

do

{

i=1;

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

I++;

}while(I>=n);

}
commented Jun 11 by Peter Minarik (7,830 points)
This code has many problems.

1. It does not compile.
2. Assuming you meant 'i' when you wrote 'I' (variables are case sensitive, so they are not the same) the code compiles, but it prints '1' and terminates as long as 'n' is at least 3. If 'n' is less than 3, the loop never terminates, you've got an infinite loop printing '1' forever.
0 votes
answered Jul 14, 2018 by yashodha kodag (300 points)
#include<stdio.h>

main()

{

 int i;

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

{
printf("\t%d",i);

}

}
0 votes
answered Jul 14, 2018 by yashodha kodag (300 points)
main()

{

 int i;

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

{
printf("\t%d",i);

}

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...