1:
#include<stdio.h>
int main()
{
int row,space,star,n;
printf("please enter the number of lines:");
scanf("%d",&n);
for(row=1;row<=n;row++)
{
for(space=n-row;space>=0;space--)
{
printf(" ");
}
for(star=1;star<=2*row-1;star++)
{
printf("*");
}
printf("\n");
}
for(row=n;row>=1;row--)
{
for(space=n-row;space>=0;space--)
{
printf(" ");
}
for(star=1;star<=2*row-1;star++)
{
printf("*");
}
printf("\n");
}
return 0;
}
input: 7
output:
*
***
*****
*******
*********
***********
*************
*************
***********
*********
*******
*****
***
*
Thursday, January 1, 2015
pattern-3
1:
#include<stdio.h>
int main()
{
int row,space,star,n;
printf("please enter the number of lines:");
scanf("%d",&n);
for(row=n;row>=1;row--)
{
for(space=0;space<row;space++)
{
printf(" ");
}
for(star=n;star>=row;star--)
{
printf("*");
}
printf("\n");
}
return 0;
}
input: 7
output:
*
**
***
****
*****
******
*******
2:
#include<stdio.h>
int main()
{
int row,space,star,n;
printf("please enter the number of lines:");
scanf("%d",&n);
for(row=n;row>=1;row--)
{
for(space=n;space>row;space--)
{
printf(" ");
}
for(star=1;star<=row;star++)
{
printf("*");
}
printf("\n");
}
return 0;
}
input: 7
output:
*******
******
*****
****
***
**
*
#include<stdio.h>
int main()
{
int row,space,star,n;
printf("please enter the number of lines:");
scanf("%d",&n);
for(row=n;row>=1;row--)
{
for(space=0;space<row;space++)
{
printf(" ");
}
for(star=n;star>=row;star--)
{
printf("*");
}
printf("\n");
}
return 0;
}
input: 7
output:
*
**
***
****
*****
******
*******
2:
#include<stdio.h>
int main()
{
int row,space,star,n;
printf("please enter the number of lines:");
scanf("%d",&n);
for(row=n;row>=1;row--)
{
for(space=n;space>row;space--)
{
printf(" ");
}
for(star=1;star<=row;star++)
{
printf("*");
}
printf("\n");
}
return 0;
}
input: 7
output:
*******
******
*****
****
***
**
*
pattern-2
1:
#include<stdio.h>
int main()
{
int row,space,star,n;
printf("please enter the number of lines:");
scanf("%d",&n);
for(row=1;row<=n;row++)
{
for(space=n-row;space>=0;space--)
{
printf(" ");
}
for(star=1;star<=2*row-1;star++)
{
printf("*");
}
printf("\n");
}
return 0;
}
input: 7
output:
*
***
*****
*******
*********
***********
*************
2:
#include<stdio.h>
int main()
{
int row,space,star,n;
printf("please enter the number of lines:");
scanf("%d",&n);
for(row=n;row>=1;row--)
{
for(space=n-row;space>=0;space--)
{
printf(" ");
}
for(star=1;star<=2*row-1;star++)
{
printf("*");
}
printf("\n");
}
return 0;
}
input: 7
output:
*************
***********
*********
*******
*****
***
*
#include<stdio.h>
int main()
{
int row,space,star,n;
printf("please enter the number of lines:");
scanf("%d",&n);
for(row=1;row<=n;row++)
{
for(space=n-row;space>=0;space--)
{
printf(" ");
}
for(star=1;star<=2*row-1;star++)
{
printf("*");
}
printf("\n");
}
return 0;
}
input: 7
output:
*
***
*****
*******
*********
***********
*************
2:
#include<stdio.h>
int main()
{
int row,space,star,n;
printf("please enter the number of lines:");
scanf("%d",&n);
for(row=n;row>=1;row--)
{
for(space=n-row;space>=0;space--)
{
printf(" ");
}
for(star=1;star<=2*row-1;star++)
{
printf("*");
}
printf("\n");
}
return 0;
}
input: 7
output:
*************
***********
*********
*******
*****
***
*
pattern-1
1:
#include <stdio.h>
int main()
{
int row,star,n;
printf("please enter the number of lines:",n);
scanf("%d",&n);
for(row=1;row<=n;row++)
{
for(star=1;star<=row;star++)
{
printf("*");
}
printf("\n");
}
return 0;
}
input:7
output:
*
**
***
****
*****
******
*******
2:
#include <stdio.h>
int main()
{
int row,star,n;
printf("please enter the number of lines:",n);
scanf("%d",&n);
for(row=1;row<=n;row++)
{
for(star=n;star>=row;star--)
{
printf("*");
}
printf("\n");
}
return 0;
}
input:7
output:
*******
******
*****
****
***
**
*
#include <stdio.h>
int main()
{
int row,star,n;
printf("please enter the number of lines:",n);
scanf("%d",&n);
for(row=1;row<=n;row++)
{
for(star=1;star<=row;star++)
{
printf("*");
}
printf("\n");
}
return 0;
}
input:7
output:
*
**
***
****
*****
******
*******
2:
#include <stdio.h>
int main()
{
int row,star,n;
printf("please enter the number of lines:",n);
scanf("%d",&n);
for(row=1;row<=n;row++)
{
for(star=n;star>=row;star--)
{
printf("*");
}
printf("\n");
}
return 0;
}
input:7
output:
*******
******
*****
****
***
**
*
loop(8)
1:
#include <stdio.h>
///***summation of even numbers:
///***2+4+6+8+.....+n
int main()
{
int a,b,sum=0;
printf("please enter a number:");
scanf("%d",&b);
for(a=2;a<=b;a=a+2){
sum=sum+a;
}
printf("The sum of even number is:%d",sum);
return 0;
}
input: 6
output:12 ///***2+4+6=12
2:
#include <stdio.h>
///summation of odd numbers:
///1+3+5+7+9+11.........+n
int main()
{
int a,b,sum=0;
printf("please enter a number:");
scanf("%d",&b);
for(a=1;a<=b;a=a+2){
sum=sum+a;
}
printf("The sum of odd number is:%d",sum);
return 0;
}
input: 6
output:9 ///***1+3+5=9
3:
#include <stdio.h>
///1^2+2^2+3^2+.......+n^2
int main()
{
int a,b,sum=0;
printf("please enter a number:");
while(scanf("%d",&b) !=EOF){ ///***here EOF is END OF FUNCTION
for(a=1;a<=b;a++){
sum=sum+a*a;
}
printf("The sum is=%d ",sum);
}
return 0;
}
input: 7
output: 140 ///***1^2++2^2+3^2+4^2+5^2+6^2+7^2=140
#include <stdio.h>
///***summation of even numbers:
///***2+4+6+8+.....+n
int main()
{
int a,b,sum=0;
printf("please enter a number:");
scanf("%d",&b);
for(a=2;a<=b;a=a+2){
sum=sum+a;
}
printf("The sum of even number is:%d",sum);
return 0;
}
input: 6
output:12 ///***2+4+6=12
2:
#include <stdio.h>
///summation of odd numbers:
///1+3+5+7+9+11.........+n
int main()
{
int a,b,sum=0;
printf("please enter a number:");
scanf("%d",&b);
for(a=1;a<=b;a=a+2){
sum=sum+a;
}
printf("The sum of odd number is:%d",sum);
return 0;
}
input: 6
output:9 ///***1+3+5=9
3:
#include <stdio.h>
///1^2+2^2+3^2+.......+n^2
int main()
{
int a,b,sum=0;
printf("please enter a number:");
while(scanf("%d",&b) !=EOF){ ///***here EOF is END OF FUNCTION
for(a=1;a<=b;a++){
sum=sum+a*a;
}
printf("The sum is=%d ",sum);
}
return 0;
}
input: 7
output: 140 ///***1^2++2^2+3^2+4^2+5^2+6^2+7^2=140
loop(7)
1:
#include <stdio.h>
///***counting
int main()
{
int n = 13;
int i;
for(i = 1; i <= 10; i++) {
printf("%d X %d = %d\n", n, i, n*i);
}
return 0;
}
output:
13 X 1 = 13
13 X 2 = 26
13 X 3 = 39
13 X 4 = 52
13 X 5 = 65
13 X 6 = 78
13 X 7 = 91
13 X 8 = 104
13 X 9 = 117
13 X 10 = 130
2:(other way)
#include <stdio.h>
///***counting
int main()
{
int n = 13;
int i = 1;
while (i <= 10) {
printf("%d X %d = %d\n", n, i, n*i);
i = i + 1;
}
return 0;
}
output:
13 X 1 = 13
13 X 2 = 26
13 X 3 = 39
13 X 4 = 52
13 X 5 = 65
13 X 6 = 78
13 X 7 = 91
13 X 8 = 104
13 X 9 = 117
13 X 10 = 130
3:
#include <stdio.h>
///***calculating program:
int main()
{
int a,b,x;
printf("please enter three number:",a,b,x);
scanf("%d%d%d",&a,&b,&x);
if(x==1){
printf("The addition is:%d",a+b);
}
else if(x==2){
printf("The substraction is:%d",a-b);
}
else if(x==3){
printf("The division is:%d",a/b);
}
else if(x==4){
printf("The multiplication is:%d",a*b);
}
else if(x==5){
printf("The modulus number is:%d",a%b);
}
return 0;
}
output: depend on your value
#include <stdio.h>
///***counting
int main()
{
int n = 13;
int i;
for(i = 1; i <= 10; i++) {
printf("%d X %d = %d\n", n, i, n*i);
}
return 0;
}
output:
13 X 1 = 13
13 X 2 = 26
13 X 3 = 39
13 X 4 = 52
13 X 5 = 65
13 X 6 = 78
13 X 7 = 91
13 X 8 = 104
13 X 9 = 117
13 X 10 = 130
2:(other way)
#include <stdio.h>
///***counting
int main()
{
int n = 13;
int i = 1;
while (i <= 10) {
printf("%d X %d = %d\n", n, i, n*i);
i = i + 1;
}
return 0;
}
output:
13 X 1 = 13
13 X 2 = 26
13 X 3 = 39
13 X 4 = 52
13 X 5 = 65
13 X 6 = 78
13 X 7 = 91
13 X 8 = 104
13 X 9 = 117
13 X 10 = 130
3:
#include <stdio.h>
///***calculating program:
int main()
{
int a,b,x;
printf("please enter three number:",a,b,x);
scanf("%d%d%d",&a,&b,&x);
if(x==1){
printf("The addition is:%d",a+b);
}
else if(x==2){
printf("The substraction is:%d",a-b);
}
else if(x==3){
printf("The division is:%d",a/b);
}
else if(x==4){
printf("The multiplication is:%d",a*b);
}
else if(x==5){
printf("The modulus number is:%d",a%b);
}
return 0;
}
output: depend on your value
loop(6)
1:
#include <stdio.h>
///***loop continue:
int main()
{
int i;
for(i=0;i<=5;i++){
printf(" %d",i);
if(i==2)
continue;
printf("%d",i);
}
return 0;
}
output: 00 11 2 33 44 55
2:
#include <stdio.h>
///***print all integer in accending order:
int main()
{
int i,start,end;
scanf("%d %d",&start,&end);
for(i=start;i<=end;i++){
printf("% d ",i);
}
return 0;
}
input:3 9
output:3 4 5 6 7 8 9
3:
#include <stdio.h>
///print all integer in accending order:
int main()
{
int temp,i,start,end;
scanf("%d %d",&start,&end);
if(start>end){
temp=start;
start=end;
end=temp;
}
for(i=start;i<=end;i++){
printf("% d ",i);
}
return 0;
}
input:3 9
output:3 4 5 6 7 8 9
#include <stdio.h>
///***loop continue:
int main()
{
int i;
for(i=0;i<=5;i++){
printf(" %d",i);
if(i==2)
continue;
printf("%d",i);
}
return 0;
}
output: 00 11 2 33 44 55
2:
#include <stdio.h>
///***print all integer in accending order:
int main()
{
int i,start,end;
scanf("%d %d",&start,&end);
for(i=start;i<=end;i++){
printf("% d ",i);
}
return 0;
}
input:3 9
output:3 4 5 6 7 8 9
3:
#include <stdio.h>
///print all integer in accending order:
int main()
{
int temp,i,start,end;
scanf("%d %d",&start,&end);
if(start>end){
temp=start;
start=end;
end=temp;
}
for(i=start;i<=end;i++){
printf("% d ",i);
}
return 0;
}
input:3 9
output:3 4 5 6 7 8 9
loop(5)
1:
#include <stdio.h>
///***while loop using increment operator:
int main()
{
int a,b;
scanf("%d %d",&a,&b);
while(a<=b){
printf("%d ",a);
a++;
}
return 0;
}
input:1 5
output:1 2 3 4 5
2:
#include <stdio.h>
///***loop break:
int main()
{
int i;
for(i=0;i<=5;i++){
printf("% d ",i);
if(i==3)
break;
}
return 0;
}
output: 0 1 2 3
3:
#include <stdio.h>
///***loop break:
int main()
{
int i;
for(i=0;i<=5;i++){
if(i==3)
break;
printf("% d ",i);
}
return 0;
}
output: 0 1 2
#include <stdio.h>
///***while loop using increment operator:
int main()
{
int a,b;
scanf("%d %d",&a,&b);
while(a<=b){
printf("%d ",a);
a++;
}
return 0;
}
input:1 5
output:1 2 3 4 5
2:
#include <stdio.h>
///***loop break:
int main()
{
int i;
for(i=0;i<=5;i++){
printf("% d ",i);
if(i==3)
break;
}
return 0;
}
output: 0 1 2 3
3:
#include <stdio.h>
///***loop break:
int main()
{
int i;
for(i=0;i<=5;i++){
if(i==3)
break;
printf("% d ",i);
}
return 0;
}
output: 0 1 2
loop(4)
1:
#include <stdio.h>
#include <stdlib.h>
///***terminating program:
int main()
{
int a;
while(scanf("%d",&a)&& a!=0){
printf("%d\n",a);
}
return 0;
}
output:the program will terminate when you will input zero:
2:
#include <stdio.h>
///***summation:
int main()
{
int a,sum,range;
printf("please enter a number:",range);
scanf("%d",&range);
sum=0;
for(a=1;a<=range;a++)
sum+=a;
printf("\nthe sum of 1 to %d is %d\n",range,sum);
return 0;
}
input: 6
output: 21
3:
#include <stdio.h>
///***print multiply number:
int main()
{
int a,b,sum;
a=5;
for(b=1;b<=5;b++){
sum=a*b;
printf(" %d ",sum);
}
return 0;
}
output: 5 10 15 20 25
#include <stdio.h>
#include <stdlib.h>
///***terminating program:
int main()
{
int a;
while(scanf("%d",&a)&& a!=0){
printf("%d\n",a);
}
return 0;
}
output:the program will terminate when you will input zero:
2:
#include <stdio.h>
///***summation:
int main()
{
int a,sum,range;
printf("please enter a number:",range);
scanf("%d",&range);
sum=0;
for(a=1;a<=range;a++)
sum+=a;
printf("\nthe sum of 1 to %d is %d\n",range,sum);
return 0;
}
input: 6
output: 21
3:
#include <stdio.h>
///***print multiply number:
int main()
{
int a,b,sum;
a=5;
for(b=1;b<=5;b++){
sum=a*b;
printf(" %d ",sum);
}
return 0;
}
output: 5 10 15 20 25
loop-Basic(3)
1:
#include <stdio.h>
///***Basic for loop:
int main()
{
int a;
for(a=1;a<=5;a++)
printf(" %d ",a);
return 0;
}
output: 1 2 3 4 5
2:
#include <stdio.h>
///while loop:
int main()
{
int a=1;
while(a<=5){
printf(" %d ",a);
a++;
}
return 0;
}
output: 1 2 3 4 5
3:
#include <stdio.h>
///loop statement:
int main()
{
int a=1;
loop:
printf(" %d ",a);
a++;
if(a<=5)
goto loop;
return 0;
}
output: 1 2 3 4 5
4:
#include <stdio.h>
///do loop:
int main()
{
int a=1;
do{
printf(" %d ",a);
a++;
}
while(a<=5);
return 0;
}
output: 1 2 3 4 5
#include <stdio.h>
///***Basic for loop:
int main()
{
int a;
for(a=1;a<=5;a++)
printf(" %d ",a);
return 0;
}
output: 1 2 3 4 5
2:
#include <stdio.h>
///while loop:
int main()
{
int a=1;
while(a<=5){
printf(" %d ",a);
a++;
}
return 0;
}
output: 1 2 3 4 5
3:
#include <stdio.h>
///loop statement:
int main()
{
int a=1;
loop:
printf(" %d ",a);
a++;
if(a<=5)
goto loop;
return 0;
}
output: 1 2 3 4 5
4:
#include <stdio.h>
///do loop:
int main()
{
int a=1;
do{
printf(" %d ",a);
a++;
}
while(a<=5);
return 0;
}
output: 1 2 3 4 5
Subscribe to:
Posts (Atom)