Sunday 6 January 2019

Length of string using Pointer in c[c programming examples with output]

C programming examples with output

Length of string using Pointer
Program

#include<stdio.h>
int string_In(char*);
void main()
{
      char str[20];
      int length;
      printf("\nEnter any string: ");
      gets(str);
      length=string_In(str);
      printf("The length of the given string %s is: %d",str,length);
}
      int string_In(char*p)
{
      int count=0;
      while(*p!='\0'){
      count++;
      p++;
}
return count;
}

Output:
Enter any string: programming
The length of the given string programming is: 11

Addition using pointer in c[c programming examples with output]

C programming examples with output

Addition using pointer
Program

#include<stdio.h>
int main()
{
      int first,second,*p,*q,sum;
      printf("Enter two integers to add\n");
      scanf("%d%d",&first,&second);
      p=&first;
      q=&second;
      sum=*p+*q;
      printf("Sum of entered numbers=%d\n",sum);
      return 0;
}

Output:
Enter two integers to add
4
6
Sum of entered numbers=10

Asterisks Graph with c[c programming examples with output]

C programming examples with output

Asterisks Graph
Program

#include<stdio.h>
#include<conio.h>
main()
{
      int i,j,rows;
      clrscr();
      printf("Enter number of rows  :");
      scanf("%d",&rows);
      for(i=1;i<=rows;i++)
      {
          for(j=1;j<=1;j++)
         {
            printf("* ");
         }
      printf("\n");
      }
getch();
}

Output:
Enter number of rows:7
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *

Check Leap Year Or Not in c[c programming examples with output]

C programming examples with output

To Check Leap Year Or Not
Program

#include<stdio.h>
#include<conio.h>
main()
{
     int year,i;
     clrscr();
     printf("Enter year : ");
     scanf("%d",&year);
     if(year%4==0)
         printf("%d is a leap year.",year);
     else
         printf("%d is not a leap year.",year);
     getch();
}

Output:
Enter year:2020
2020 is a leap year.
Enter year:2017
2017 is not a leap year.

Best Budget Laptop For Web Developers 2019