Sunday 26 June 2016

SIMPLE LOOPING programs

1. WAP in c to print hello ten times.

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=10;i++)
{
printf("hello\n");
}
getch();
}

Output:










2. WAP in c to print natural numbers up to 10.

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=10;i++)
{
printf("%d\n",i);
}

getch();
}

Output:














3. WAP in c to print sum of natural numbers up to 10.

S=1+2+3+4+5+6+7+8+9+10

#include<stdio.h>
#include<conio.h>
void main()
{
int i,s=0;
clrscr();
for(i=1;i<=10;i++)
{
s=s+i;
}
printf("sum=%d",s);
getch();
}

Output:







4. WAP in c to print sum of square of natural numbers from 1 to 10.

S=12 +22+3 2+4 2 +5 2 +6 2 +7 2 +8 2 +9 2 +10 2


#include<stdio.h>
#include<conio.h>
void main()
{
int i,s=0;
clrscr();
for(i=1;i<=10;i++)
{
s=s+i*i;
}
printf("sum=%d",s);
getch();
}

Output:






5. WAP in c to print sum of cube of natural numbers up to 10.

S=13 +23+3 3+4 3 +5 3 +6 3 +7 3 +8 3 +9 3+10 3

#include<stdio.h>
#include<conio.h>
void main()
{
int i,s=0;
clrscr();
for(i=1;i<=10;i++)
{
s=s+i*i*i;
}
printf("sum=%d",s);
getch();
}

Output:









6. WAP in c to print all even numbers up to 100.

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=100;i++)
{
if(i%2==0)
{
printf("%d\t",i);
}
}
getch();
}

0utput:




7. WAP in c to print all odd numbers up to 100.

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=100;i++)
{
if(i%2==1)
{
printf("%d\t",i);
}
}
getch();
}

Output:







8. WAP in c to print sum of all even numbers up to 10.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,s=0;
clrscr();
for(i=1;i<=10;i++)
{
if(i%2==0)
{
s=s+i;
}
}
printf("sum=%d",s);
getch();
}

Output:






9. WAP in c to print sum of all odd numbers up to 10.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,s=0;
clrscr();
for(i=1;i<=10;i++)
{
if(i%2==1)
{
s=s+i;
}
}
printf("sum=%d",s);
getch();
}

Output:







10. WAP in c to print multiplication table of given number.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,s;
clrscr();
printf("Enter any number:");
scanf("%d",&n);
printf("Multiplication table of %d is:\n",n);
for(i=1;i<=10;i++)
{
s=n*i;
printf("%d*%d=%d\n",s,n,i);
}
getch();
}

Output:














11. WAP in c to print product of natural numbers upto 10.

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
long int s=1;
clrscr();
for(i=1;i<=10;i++)
{
s=s*i;
}
printf("product = %ld",s);
getch();
}

Output:






12. WAP in c to print product of square of natural numbers upto 5.

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
long int s=1;
clrscr();
for(i=1;i<=5;i++)
{
s=s*i*i;
}
printf("product = %ld",s);
getch();
}

Output:






13. WAP in c to print product of cube of first five natural number.

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
long int s=1;
clrscr();
for(i=1;i<=5;i++)
{
s=s*i*i*i;
}
printf("product = %lu",s);
getch();
}

Output:






14. WAP in c to print odd and even numbers in two columns upto 10.

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf("ODD\tEVEN");
for(i=1;i<=10;i++)
{
if(i%2==0)
{
printf("\t %d",i);
}
else
{
printf("\n %d",i);
}
}
getch();
}


Output:



No comments:

Post a Comment

index

MENU Sample Papers  (new sample paper added for computers) C Language Mathematics IX (NCERT solution)   Computer IX (CBSE) ...