Thursday 27 May 2021

C problems mostly star related

 

/* write a program to repeat 5 times name*/
#include<stdio.h>
void main()
{
int a;
while(a<=5)
{
printf("theprogrammerlearner.com\n");
a=a+1;
}
}


#include <stdio.h>

int main()
{
    int i=0;
    while((i>=10 )&&( i<=20))
    {

        printf("the value of i is %d \n",i );
        i++;


    }

    return 0;
}


/* wite a program weeks numbers to weeks names
*/
#include<stdio.h>
void main()
{
    int week; // week no number
    printf("enter week no.:");
    scanf("%d",&week);
    if(week==1)
        printf("monday");
    else
    {
        if(week==2)
            printf("tuesday");
    }
    else
    {
        if(week==3)
       printf("wednesday");
    }
       else{
        if(week==4)
            printf("thursday");
       }
            else
        {
            if(week==5)
                printf("friday");
        }
                else
            {
                if(weeek==6)
                    printf("saturday");
                else
                    printf("sunday");
            }






}



#include<stdio.h>
#include<time.h>
int main()
{
time_t s;
struct tmcurrent_time;
s=time(NULL);
current_time=localtime(&s);
printf("%02d:%02d:%02d",
         current_time->tm_hour,
         current_time->tm_min,
         current_time->tm_sec);





}



// write a program to convert fahenreit to centigrade
//author:upendra yadav date:10/27/2020
#include<stdio.h>
void main()
{
float fh,cen;
printf("Enter the temperature in fahenrenit:\n");
scanf("%f",&fh);
cen=(fh-32)*5/9;
printf("Temperature in celsius is %f",cen);



/*write a program to print multiplication from
1 to 5*/
#include<stdio.h>
void main()
{
int n;
for(n=1;n<11;n++)
{
for(n=2;n/2<21;n++)
printf("%d\t%d\n",n);
}
}



/*in switch keyword case we can also use
one or more cases depending upon
situation*/
#include<stdio.h>
void main()
{
char ch;
printf("Enter any character 'ch':\n");
scanf("%c",&ch);
switch(ch)
{
case 'y':
case 'Y':
print("Enter character is a upper ch Y");
break;
case 'z':
case 'Z':
printf("Enter character is a upper ch Z");
break;
default:
printf("Enter character is invalid");

}

}



/*switch questions */
#include<stdio.h>
void main()
{
int a;
printf("Enter the one digit value");
scanf("%f",&a);
switch(a)
{
case 1:
printf("\ni can do programming and create application");
break;
case 2:
printf("\ni can create application");
break;
case 3:
printf("\nbe calm and relax your mind ");
break;
case 4:
printf("\nbe self independent");
break;
case 5:
printf("\nIt will help to achieve targets in your life");
break;
default:
printf("\nUser input is incorrect");


}


}



//write a program to add sum of five digits number
//author:upendra yadav
#include<stdio.h>
void main()
{
int n,rem,t;
printf("Enter the digits number:\n");
scanf("%d",&n);
t=n;
while(t!=0)
{
t=t/10;
rem=t%10;





}

printf("Reverse of digit is %d%d",t,rem);











}


// write a program to star mirrored of triangle
#include<stdio.h>
int main()
{
int i,j,N;
printf("Enter the input rows:\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
for(j=1;j<=N-i;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
if(i==1||i==N||j==1||j==N||i==j)
    printf("*");
else
{
    printf(" ");
}
}

printf("\n");

}







}




}


// write a program to print right angled traingle
#include<stdio.h>
int main()
{
int i,j,N; //n is a input row
printf("Enter input row :\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{

for(j=1;j<=N-i;j++)
{
if(i==1||i==N||j==1||j==N||i==j)
    printf("*");
else
{

 printf(" ");}
}
printf("\n");
}

}


// write a program to draw rhombus using special character
#include<stdio.h>
void main()
{
int i,j,N; //N is row
printf("Enter the no.of rows:\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
for(j=1;j<i;j++)
{
printf(" ");


}
for(j=1;j<=N;j++)
{
    if(i==1||i==N||j==1||j==N)
        printf("*");
    else
    {
        printf(" ");
    }
}



printf("\n");
}

}


// write a program to draw rhombus using special character
#include<stdio.h>
void main()
{
int i,j,N; //N is row
printf("Enter the no.of rows:\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
for(j=1;j<i;j++)
{
printf(" ");


}
for(j=1;j<=N;j++)
{
    if(i==1||i==N||j==1||j==N)
        printf("*");
    else
    {
        printf(" ");
    }
}



printf("\n");
}

}


//write a program to print hollow square of special character
#include<stdio.h>
int main()
{
int i,j,N//n is a input rows
printf("Enter the input rows or col:\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
{
if(i==1||i==N||j==1||j==N||j==(N-i+1))
printf("*");
else
{
printf(" ");
}



}

printf("\n");

}








}


// write a program to any special character pattern in square
#include<stdio.h>
int main()
{
int i,j,N; //N enter row and col
printf("Enter the no. of row:\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
{
printf("*");

}
printf("\n");


}






}


//write a program to peint hollow square with diagonals
#include<stdio.h>
void main()
{
int i,j,N;//ith row ,jth column ,N input row
printf("Input the rows with diagonal:\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
{
if(i==1||i==N||j==1||j==N||j==(N-i+1))
printf("*");
else
{
printf(" ");

}



}

printf("\n");

}



}


//write a program of hollow rectangle
#include<stdio.h>
int main()
{
int i,j,N,C;// ith row , jth column,c col , N row
printf("Input the row and col:\n");
scanf("%d%d",&N,&C);
for(i=1;i<=C;i++)
{
for(j=1;j<=N;j++)
{
if(i==1||i==C||j==1||j==N||j==(i+4))
{
printf("*");}
else
{
printf(" ");}

}
printf("\n");

}
return 0;
}


//write a program to hollow star pattern in square
#include<stdio.h>
int main()
{
int i,j,N;// ith rows, jth column ,N input rows
printf("Input the rows:\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
{
    if(i==1||i==N||j==1||j==N)
    {
        printf("*");
    }
    else
      {

       printf(" ");}
}
printf("\n");

}
return 0;
}



// write a program to star pattern of square
#include<stdio.h>
int main()
{
int i,j,N;
printf("Input the rows:\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
{
printf("*");}
printf("\n");

}

}


#include<stdio.h>
void main()
{
int i,j;
for(i=1;i<=10;i++)
{
    for(j=1;j<=5;j++)

        printf("%d\t",i*j);

    printf("%d\n");
}





}
























No comments:

Python if / else

 Python if / else a1 = int ( input (" Enter the number: \n ")) a2 = int ( input (" Enter the number: \n ")) a3 = int ( i...