Showing posts with label reverse. Show all posts
Showing posts with label reverse. Show all posts

Tuesday, September 23, 2014

Program to print out numbers separated by stars with the occurrence defined by the number printed.

This will print out something like this
1
2*2
3*3*3
4*4*4*4
and then the reverse image.
If you have any doubt, please do ask.

#include<stdio.h>
main()
{
int i=1,j=2,z=4,k;
printf("%d\n",i);
for(k=0;k<3;k++)
{
for(i=2;i<z-1;i++)
{
printf("%d*",j);
}
printf("%d\n");
j++;
z++;
}
j=4;
for(k=0;k<3;k++)
{
for(i=2;i<z-2;i++)
{
printf("%d*",j);
}
printf("%d\n");
j--;
z--;
}
printf("%d",1);
}

Saturday, August 9, 2014

Program to reverse a string

Program to reverse a string. You'll need to work with pointers in this program. If you need help, comment below

#include<stdio.h> #include<string.h> main() { char *ptr; char string[50],t; int i,j,l; ptr=string; printf("\nEnter the string"); gets(string); l=strlen(string); for(i=0,j=l-1;i<=(l-1)/2;i++,j--) { t= *(ptr+i); *(ptr+i)= *(ptr+j); *(ptr+j)=t; } printf("Reverse string is %s\n",string); }