Posts

c program to find the leap year or not

LEAP YEAR // WAP to find out Year is leap or not (IF-ELSE) void main () { int a; clrscr (); printf ("Enter the Year: "); scanf("%d",&a); if (a%400==0) { printf ("\nYear is Leap"); } else { printf("\nYear is not Leap"); } getch (); } //WAP to find out Year is leap or not (switch case) #include<stdio.h> #include<conio.h> int main () { int a; //clrscr(); printf ("Enter the Year: "); scanf("%d",&a); a=a%400; switch(a) { case 0: { printf ("\n Leap Year"); break; } default: { printf("\n Not Leap Year"); break; } } getch (); }  // about leap year: http://www.infoplease.com/spot/leapyear1.html  

c program to find the size of a variable

SIZE OF VARIABLE WAP to find size of any variable void main() { int a; float b; double c; char ch; long d; char nm[10]; clrscr(); printf("\nInt size is \t:%d", sizeof (a)); printf("\nFloat size is \t:%d", sizeof (b)); printf("\nDouble size is \t:%d", sizeof (c)); printf("\nChar size is \t:%d", sizeof (ch)); printf("\nLong size is \t:%d", sizeof (d)); printf("\nString size is \t:%d", sizeof (nm)); getch (); }

c program to find string

FIND STRING WAP to find string within a string void main () { char *k="Borland International", *g, *p; clrscr (); printf ("Enter string to find: "); gets (g); p=strstr(k,g); printf ("%s",p); getch (); }

c program to find the string length

STRING LENGTH WAP to find the length of any string void main () { char ch [20]; int l; clrscr (); printf ("Enter String: "); gets (ch); l=strlen(ch); printf ("Length of string is %d",l); getch (); }

c program to reverse words

program to reverse words ‎#include <stdio.h> #include <conio.h> #include <string.h> const int opt = 50; int main(){ int i=0,j=0,c=0,vali[opt] = {0}; char str1[opt],str2[opt]="",str3[opt]="",ch; printf("please enter your sentence :"); gets(str1); for(i=0;str1[i] != '\0';i++){ if(str1[i] == ' '){ vali[j+1] = i; j++; } } c = j; for(i=0;i<=j && c!=0;i++){ strcat(str2,&str1[vali[c]+1]); strcpy(&str1[vali[c]],str3); strcat(str2," "); c--; } strcat(str2,str1); printf("\nyour reversed sentence is :"); puts(str2); getch(); return 0; }

c program to Swap Numbers

Image
Program to SWAP the three digit number #include<    > void main () { int b,r,n,r1,r2; clrscr (); printf ("Enter the Value: "); scanf ("%d",&n); r=n%10; n=n/10; r1=n%10; n=n/10; r2=n%10; n=n/10; b=(r*100)*(r2*10)+(r2); printf ("%d%d%d",r,r1,r2); getch (); }

c program to check armstrong number or not

Whether the given no. is armstrong or not   #include<stdio.h>   #include<conio.h>   void main()    {     int n,r,t,sum=0;     clrscr();     printf("  OUTPUT :\n");     printf("\tEnter a no.");     scanf("%d",&n);     t=n;     while(n!=0) { r=n%10; sum=sum+r*r*r; n=n/10; }    if(sum==t)    printf("The no. %d is armstrong",t);    else    printf("The no. %d is not an armstrong",t);    getch();   }