Facebook
From MSE, 8 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 353
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     // Write C++ code here
  5.    
  6.     int i=1,j;
  7.     printf("Enter the number you wish to print: ");
  8.     scanf("%d", &j);
  9.     printf("\nUsing while loop:\n");
  10.     while (i<=j)
  11.         {
  12.             printf("%d\t",i);
  13.             i++;
  14.         }
  15.    
  16.     i--;
  17.     printf("\n\nOn the Reverse Order:\n");
  18.     while (i>=1)
  19.         {
  20.             printf("%d\t",i);
  21.             i--;
  22.         }
  23.     printf("\n\nUsing for loop:\n");
  24.     for (i=1;i<=j;i++)
  25.         {
  26.             printf("%d\t",i);
  27.         }
  28.     i--;
  29.     printf("\n\nOn the Reverse Order:\n");
  30.     for (;i>=1;i--)
  31.         {
  32.             printf("%d\t",i);
  33.         }
  34.     printf("\n\nUsing for do while:\n");
  35.     do { printf("%d\t",i),
  36.             i++; }
  37.     while (i<=j);
  38.    
  39.     i--;
  40.     printf("\n\nOn the Reverse Order:\n");
  41.     do { printf("%d\t",i);
  42.             i--; }
  43.     while (i>=1);
  44.    
  45.     return 0;
  46. }
  47.  
  48.  
  49. int main() {
  50.     // Write C++ code here
  51.    
  52.     int i, RN;
  53.     printf("Enter the number: ");
  54.     scanf("%d",&i);
  55.  
  56.     for (int j=1; j <= i; j++)
  57.        
  58.         {
  59.             if (i % j == 0)
  60.             {
  61.             printf("%d\n",j);}
  62.         }
  63.    
  64.     while ( i != 0)
  65.         { int digit  = i % 10;
  66.         RN = RN * 10 + digit;
  67.         i = i / 10; }
  68.        
  69.         printf("reversed number: %d\n", RN);
  70.        
  71.    
  72.     return 0;
  73. }

Replies to CSE 2.1 CL2 rss

Title Name Language When
Re: CSE 2.1 CL2 CL4 text 8 Months ago.