+1 vote
768 views
Write a c program to print numbers from  1-100 without using loops, array, recursive function , standard library function and 100 printf statement
asked Oct 20, 2015 in Computer Science - IT by kishor93 | 768 views
"without using loops, array, recursive function , standard library function and 100 printf statement" .How could you ? :) Have any idea ?

3 Answers

+2 votes

http://ideone.com/FYvHGY

#include <stdio.h>

int main(void) {
    f1(1, 100);
    return 0;
}

void f1(int a, int N) {
    if (a <= N) {
        printf("%d\n", a++);
        f2(a, N);
    }
}

void f2(int a, int N) {
    if (a <= N) {
        printf("%d\n", a++);
        f1(a, N);
    }
}
answered Dec 4, 2015 by sparko
Excellent answer ..just using branching !!
+1 vote
#include <stdio.h>
 
int main () {
  int a = 0;  
  PRINT:printf("%d\n", ++a);
  if (a < 100)
    goto PRINT;  
}
answered Dec 4, 2015 by Vytax
edited Dec 9, 2015 by slow_learner
Excellent @Vytax but one question : is "GOTO" not  a loop ? correct me if im wrong ..
https://ideone.com/5UqrqS
0 votes

Technically this meets you requirements :p

 

#include "stdio.h"

int main(void) {

printf("1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n\100");
return 0;
}
answered Dec 4, 2015 by buluba89
edited Dec 9, 2015 by slow_learner
:) yes that has answer but not a flexible one