News:

Build a stunning handcrafted website with IT Acumens

Main Menu

For Loop Programs in C

Started by karthikn, Aug 06, 2008, 04:08 PM

Previous topic - Next topic

karthikn

Programming in C to print the number between two ranges

#include <stdio.h>
#include <conio.h>

int main()

{

int M,N;

printf("enter the ranges do you want diaplay\n");

scanf("%d%d",&M,&N);

printf("the numbers between %d to %d \n",M,N);

for(;M<=N;M++)
printf("%d  ",M);

getch();



Display the leap Years between 1000 and 2000

#include <stdio.h>
#include <conio.h>

int main()

{

int loop;

printf("the leap year or not between 1000 to 2000\n");

for(loop=1000;loop<=2000;loop++)
{

if(loop%4==0)
printf("%d  leap year\n",loop);
else
printf("%d  not\n",loop);
}
getch();


Dnyaneshwar Chavan

Sorry, but its not a perfect programme ....
To find a leap year, following programme is more perfect.
#include <stdio.h>
int main(){
        int year;
        printf("Enter the year\n");
        scanf("%d",&year);
        if(year % 4 == 0){
                if(year % 100 == 0){
                        if(year % 400 == 0)
                                printf("Leap Year\n");
                        else
                                printf("Not a leap year\n");
                }
                else
                        printf("Leap Year\n");
        }
        else
                printf("not a leap year\n");


        return 0;
}                             

naveen kumar T

Quote from: karthikn on Aug 06, 2008, 04:08 PMProgramming in C to print the number between two ranges

#include <stdio.h>
#include <conio.h>

int main()

{

int M,N;

printf("enter the ranges do you want diaplay\n");

scanf("%d%d",&M,&N);

printf("the numbers between %d to %d \n",M,N);

for(;M<=N;M++)
printf("%d  ",M);

getch();



Display the leap Years between 1000 and 2000

#include <stdio.h>
#include <conio.h>

int main()

{

int loop;

printf("the leap year or not between 1000 to 2000\n");

for(loop=1000;loop<=2000;loop++)
{

if(loop%4==0)
printf("%d  leap year\n",loop);
else
printf("%d  not\n",loop);
}
getch();