C Program to print numbers from 1 to N without using semicolon?

link 0

How to print numbers from 1 to N without using any semicolon in C.

#include<stdio.h>
#define N 100
// Add your code here to print numbers from 1
// to N without using any semicolon

What code to add in above snippet such that it doesn’t contain semicolon and prints numbers from 1 to N?

We strongly recommend you to minimize your browser and try this yourself first

Method 1 (Recursive)

// A recursive C program to print all numbers from 1
// to N without semicoolon
#include<stdio.h>
#define N 10
int main(int num)
{
    if (num <= N && printf("%d ", num) && main(num + 1))
    {
    }   
}
Output:
1 2 3 4 5 6 7 8 9 10

 

Method 2 (Iterative)

// An iterative C program to print all numbers from 1
// to N without semicoolon
#include<stdio.h>
#define N 10
int main(int num, char *argv[])
{
while (num <= N && printf("%d ", num) && num++)
{
}
}

Output:

1 2 3 4 5 6 7 8 9 10 

Disclaimer: This content belongs to geeksforgeeks, source: http://geeksforgeeks.org

rakesh

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar