Notification texts go here Contact Us Click here

C program to print 1 to n number using while loop .

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated



Program to print numbers from 1 to n using while loop . 
   #include <stdio.h>
 
    int main() 
    {
    int i = 1,n;
    printf("Enter the value of n:");
    scanf("%d",&n);
    while(i <= n) {
      printf("%d \n", i);
      i++;
    }
    return 0;
    }
 
  Enter the value of n: 20
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
 
Program to print evun numbers from 0 to n using while loop.

   #include<stdio.h>
int main()
{   int i=0,n;
    printf("Enter the value of n: ");
    scanf("%d",&n);
    while(i<=n)
    {
        printf("%d\n",i);
        i=i+2;
    }
    return 0;
}
 
 
Enter the value of n: 10
0
2
4
6
8
10
 
Program to print odd numbers from 1 to n using while loop.
  #include<stdio.h>
int main()
{   int i=1,n;
    printf("Enter the value of n: ");
    scanf("%d",&n);
    while(i<=n)
    {
        printf("%d\n",i);
        i=i+2;
    }
    return 0;
}
 
 
Enter the value of n: 10
1
3
5
7
9
 
Program to add numbers from 1 to n using while loop.


#include<stdio.h> int main() { int i=1,n,sum=0; printf("Enter the value of n: "); scanf("%d",&n); while(i<=n) { sum=sum+i; i++; } printf("The sum of %d numbers is :%d",n,sum); return 0; }     Enter the value of n: 20 The sum of 20 numbers is :210

إرسال تعليق

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.