1.Question: Write a program using loop control to produce the following output
A B C D E F G
A B C D E F
A B C D E
A B C D
A B C
A B
A
A B C D E F G
A B C D E F
A B C D E
A B C D
A B C
A B
A
solution:
#include < stdio.h >
int main()
{
int i,j,n=9,k=9;
char c='A';
for(i=1 ; i<=n ; i++)
{
for(j=k ; j>=1 ; j--)
{
printf("%c" , c++);
}
printf("\n");
c='A';
k--;
}
return 0;
}
int main()
{
int i,j,n=9,k=9;
char c='A';
for(i=1 ; i<=n ; i++)
{
for(j=k ; j>=1 ; j--)
{
printf("%c" , c++);
}
printf("\n");
c='A';
k--;
}
return 0;
}
2.Question:
Write a program using loop control to produce the following output
*
**
***
****
*****
*
**
***
****
*****
solution:
#include < stdio.h >
int main()
{
int i,j,k,n;
printf("\n Enter no. of rows:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{for(j=1;j<=(n-i);j++)
{printf(" ");
}
for(k=1;k<=i;k++)
{printf("*");
}
printf("\n");
}
return 0;
}
3.Question:
Write a program using loop control to produce the following output
*
**
***
****
*****
**
***
****
*****
******
*****
****
***
**
*
solution:
#include < stdio.h >
int main(){
int i,j;
for(i=1;i<=6;i++){
for(j=1;jprintf("*");
}
printf("\n");
}
for(i=6;i>=1;i--){
for(j=1;j<=i;j++){
printf("*");
}
printf("\n");
}
return 0;
}
int main(){
int i,j;
for(i=1;i<=6;i++){
for(j=1;jprintf("*");
}
printf("\n");
}
for(i=6;i>=1;i--){
for(j=1;j<=i;j++){
printf("*");
}
printf("\n");
}
return 0;
}