#include <stdio.h> int main () { int num ; int a ; // Prompt user to enter the number of digits to print printf ( "How many digits you want to print: \n " ); scanf ( " %d " , & num ); // Loop to print the specified number of digits for ( a = 1 ; num >= a ; a ++ ) { printf ( " %d \n " , a ); } return 0 ; } // Blog Title: "Generating a Sequence: Exploring Loops in C Programming" // Keywords: C programming, loops, sequence generation, number printing
#include <stdio.h> int main () { int a , b ; do { // Initialize 'b' to 2 for each iteration of the loop b = 2 ; // Prompt the user to enter a digit printf ( "Enter a digit: \n " ); // Read the input from the user scanf ( " %d " , & a ); // Display message for searching factors printf ( "Searching: \n " ); // Loop to find factors of the entered number while ( a > b ) { if ( a % b == 0 ) { // If 'b' is a factor of 'a', print 'b' and increment 'b' to search for the next factor...
#include <bits/stdc++.h> using namespace std ; #define MOD 1000000007 ; #define int long long int int32_t main (){ ios_base :: sync_with_stdio ( false ); cin . tie ( NULL ); #ifndef ONLINE_JUDGE freopen ( "input.txt" , "r" , stdin ); #endif //----Solution-----// int n ; cin >> n ; while ( n != 1 ){ cout << n << " " ; if ( n & 1 ){ // if n is not divisible by 3 then n = n * 3 + 1 ; // multiply it by 3 and add 1 } else { n /= 2 ; // else divide it by 2 } } cout << n ; return 0 ; }
Comments
Post a Comment