Monday, May 25, 2015

string(8)

#include <stdio.h>
///copy a string to another string

int main()
{
    char ch[15],ch1[15];
    int i;
    scanf("%s",ch);
    for(i=0;ch[i]!='\0';i++)

    ch1[i]=ch[i];
    ch1[i]=ch[i];
    printf("%s",ch1);

    return 0;
}

string(7)

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch[15],ch1[15];
    int i,n;
    scanf("%s%s",ch,ch1);
    for(i=0;ch[i]!='\0';i++);
        ch[i]=' ';
       i++;

    for(n=0;ch1[n]!='\0';n++)
        ch[i+n]=ch1[n];
    printf("%s",ch);

    return 0;
}

Sunday, May 24, 2015

string(6)

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch[10][100],i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",ch[i]);
    }
    for(i=n-1;i>=0;i--){
        printf("%s\n",ch[i]);
    }
    return 0;
}

string(5)

#include <stdio.h>
#include <stdlib.h>

int main()
{
char ch[100];
gets(ch);
int a,b;
printf("%*.*s",10,5,ch);
return 0;
}

string(4)

#include <stdio.h>
#include <stdlib.h>

int main()
{
char ch[100];
while(gets(ch)){
    if(ch[0]=='\0')
        return 0;
    printf("%s\n",ch);
}
return 0;
}

string(3)

#include <stdio.h>
#include <stdlib.h>

///int main()
///{
    ///char ch[100];
   /// scanf("%[^\n]",ch);////***same output
  ///  printf("%s",ch);
  ///  return 0;
//}
int main()
{
    char ch[100];
    gets(ch);///***same output
    printf("%s",ch);
    return 0;
}

string(2)

#include <stdio.h>
#include <stdlib.h>

int main()
{
char str[100];
gets(str);
printf("%s\n",str);
gets(str);
printf("%s\n",str);
gets(str);
printf("%s\n",str);
return 0;
}

string(1)

#include <stdio.h>
///character string & array:

int main()
{
char ch[10];

ch[0]='K';
ch[1]='o';
ch[2]='u';
ch[3]='s';
ch[4]='h';
ch[5]='i';
ch[6]='k';
ch[7]='\0';///string terminating character:
ch[8]='t';
ch[9]='m';

printf("%s",ch);

return 0;
}

Thursday, January 1, 2015

pattern-4

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:             
                                                        *
                                                      ***
                                                    *****
                                                  *******
                                                *********
                                              ***********
                                            *************
                                            *************
                                              ***********
                                                *********
                                                  *******
                                                    *****
                                                      ***
                                                        *
                                         

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:             
                                           *******
                                             ******
                                               *****
                                                 ****
                                                   ***
                                                     **
                                                       *

                             
           
                    

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:
  
                    *************
                      ***********
                        *********
                         *******
                           *****
                            ***
                              *



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:
*******
******
*****
****
***
**
*


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

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

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

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

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

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

Wednesday, December 31, 2014

loop(2)

1:
#include <stdio.h>
/// if else basic:

int main()
{
int a;
printf("Please enter a number greter than five:");
scanf("%d",&a);
if(a>=5)
    printf("%d",a*a);
else
    printf("ERROR!!!\n");
return 0;
}

output: depend on your value

2:
#include <stdio.h>
///nested if else:

int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
printf("The result is:%d",a);
else
    printf("The result is:%d",c);
}
else
{
    if(b>c)
        printf("The result is:%d",b);
    else
        printf("The result is:%d",c);
}
return 0;
}

output: depend on your value

3:
#include <stdio.h>
///if else ladder:

int main()
{
int mark;
scanf("%d",&mark);
if(mark>=80) printf("your grade point is:+A");
else if(mark>=70) printf("your grade point is:A");
else if(mark>=60) printf("your grade point is:-A");
else if(mark>=50) printf("your grade point is:B");
else if(mark>=40) printf("your grade point is:C");
else printf("Failed!!!");
return 0;
}


output: depend on your value

loop(1)

1:
#include <stdio.h>
///*** compound statement:
int main()
{
int a;
if(5>10){
    scanf("%d",&a);
    printf("%d",5-a);
}
else
    printf("(The first condition is wrong)\n");
return 0;
}




output: The first condition is wrong

2:
#include <stdio.h>
///The program will print odd number:

int main()
{
int a,b;
for(b=1;b<=5;b++){
    a=(2*b-1);
    printf(" %d ",a);
    if(a>=9)
        break;
}
return 0;
}

output: 1 3 5 7 9

3:
#include <stdio.h>
///The program will print even number:

int main()
{
int a,b;
for(b=1;b<=5;b++){
    a=(2*b-1)+1;
    printf(" %d ",a);
    if(a>=10)
        break;
}
return 0;
}
 
output: 2 4 6 8 10