For Loops
Write a program to print first ten natural numbers.
#include<iostream.h>
#include<conio.h>
void main(void)
{
int a;
clrscr();
for(a=1;a<=10;a=a+1)
cout<<"\n"<<a;
}
write a program that print Even number from 2 to 20.
#include<iostream.h>
int main()
{
int a;
clrscr();
for(a=2;a<=20;a=a+2)
cout<<"\n"<<a;
system("pause");
return 0;
}
write a program that print Odd number from 1 to 21
#include<iostream.h>
int main()
{
int a;
clrscr();
for(a=1;a<=21;a=a+2)
cout<<"\n"<<a;
system("pause");
return 0;
}
write a program that print Reverse number from 10 to 1
#include<iostream.h>
int main()
{
int a;
for(a=10;a>=1;a=a-1)
cout<<"\n"<<a;
system("pause");
return 0;
}
To print a name ten time
#include<iostream.h>
int main()
{
int a;
clrscr();
for(a=1;a<=10;a=a+1)
cout<<"\n"<<a<<"waqas";
system("pause");
return 0;
}
To find square and cube of numbers
#include<iostream.h>
int main()
{
int a;
clrscr();
for(a=1;a<=20;a++)
cout<<"\n"<<a<<"\t"<<a*a<<"\t"<<a*a*a;
system("pause");
return 0;
}
Write a program that accept an integer from the user and display the table of that integer.
#include<iostream.h>
int main(void)
{
int a,b;
cout<<" Enter a number=";cin>>a;
for(b=1;b<=10;b++)
cout<<"\n"<<a<<"*"<<b<<"="<<a*b;
system("pause");
return 0;
}
Write a program that accept an integer and than calculate its factorial.
int main()
{
int a,b,c;
clrscr();
cout<<" Enter a number=";cin>>a;
c=1;
for(b=1;b<=a;b++)
c=c*b;
cout<<"\n Factorial="<<c;
system("pause");
return 0;
}
1 comments:
Nice..... Keep It Up Bro