Printf() Functions and its different Types with example
- printf sends formatted output to stdin
- cprintf sends formatted output to the text window on the screen
- fprintf sends formatted output to a stream
- sprintf sends formatted output to a string
- vfprintf sends formatted output to a stream, using an argument list
- vprintf sends formatted output to stdin, using an argument list
- vsprintf sends formatted output to a string, using an argument list
- int cprintf ( const char *format [, argument, ...]);
- int fprintf (FILE *stream, const char *format [, argument, ...]);
- int printf ( const char *format [, argument, ...]);
- int sprintf (char *buffer, const char *format [, argument, ...]);
- int vfprintf(FILE *stream, const char *format, va_list arglist);
- int vprintf ( const char *format, va_list arglist);
- int vsprintf(char *buffer, const char *format, va_list arglist);
- All these functions are declared in STDIO.H, except cprintf, which is declared in CONIO.H.
- Accept a series of arguments
- Apply to each argument a format specifier contained in the format string *format
- Output the formatted data (to the screen,a stream, stdin, or a string)
- the first format specifier to the first argument,
- thesecond specifier to the second argument,
- the third to the third, etc., to the end of the format.
On success,
- the ...printf functions return the number of bytes output
- cprintf returns the number of characters output
- sprintf does not include the terminating null byte in the count
- these functions return EOF
#include<stdio.h>
#include<conio.h>
void main()
{
int l;Sample Output:
clrscr();
printf("Enter the value:");
scanf("%d",&l);
printf("The Stored Value: %d",l);
getch();
}
Enter the Value: 10
The Stored Value: 10
The Stored Value: 10
Palindrome using pointer
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int c=0,d;
char str[30];char *a,*b;
clrscr();
printf("Enter the string:");
scanf("%s",str);
a=str;
for(a=str; *a!='\0';a++);
--a;
for(b=str; *b==*a; b++)
{
c=c+1;
--a;
}
d=strlen(str);
if(c==d)
printf("\nGiven String is Palindrome");
else
printf("\nGiven string is not palindrome");
getch();
}
Sample Output:
#include<conio.h>
#include<string.h>
void main()
{
int c=0,d;
char str[30];char *a,*b;
clrscr();
printf("Enter the string:");
scanf("%s",str);
a=str;
for(a=str; *a!='\0';a++);
--a;
for(b=str; *b==*a; b++)
{
c=c+1;
--a;
}
d=strlen(str);
if(c==d)
printf("\nGiven String is Palindrome");
else
printf("\nGiven string is not palindrome");
getch();
}
Sample Output:
Write a program to get two different array values , merge them and finally produce the ascending order sorting of the result. (array Concept)
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[25],b[25],n,g=0,m,i,j,c,temp;
clrscr();
printf("Enter the number of a: ");
scanf("%d",&n);
printf("\nEnter the no of b: ");
scanf("%d",&m);
printf("\nEnter a values\n");
for(i=1; i<=n ; i++)
scanf("%d",&a[i]);
printf("\nEnter b values\n");
for(j=1; j<=m ; j++)
{
scanf("%d",&b[j]);
a[i]=b[j];
i++;
}
printf("\nMerged values:\n");
c=n+m;
for(i=1; i<=c; i++)
printf("%d\t",a[i]);
while(g < c)
{
for(i=1; i<=c; i++)
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
else
a[i]=a[i];
++g;
}
printf("\nSorted Values:\n");
for(i=1; i<=c; i++)
printf("%d\t",a[i]);
getch();
}
Sample Output:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[25],b[25],n,g=0,m,i,j,c,temp;
clrscr();
printf("Enter the number of a: ");
scanf("%d",&n);
printf("\nEnter the no of b: ");
scanf("%d",&m);
printf("\nEnter a values\n");
for(i=1; i<=n ; i++)
scanf("%d",&a[i]);
printf("\nEnter b values\n");
for(j=1; j<=m ; j++)
{
scanf("%d",&b[j]);
a[i]=b[j];
i++;
}
printf("\nMerged values:\n");
c=n+m;
for(i=1; i<=c; i++)
printf("%d\t",a[i]);
while(g < c)
{
for(i=1; i<=c; i++)
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
else
a[i]=a[i];
++g;
}
printf("\nSorted Values:\n");
for(i=1; i<=c; i++)
printf("%d\t",a[i]);
getch();
}
Sample Output:
Subscribe to:
Posts (Atom)