Skip to main content

Posts

Showing posts from February 22, 2012

WAP Program in C to convert Decimal number to Binary

1: #include<stdio.h> 2: #include<conio.h> 3: int binary ( int ); 4: void main() 5: { 6: int num; 7: clrscr(); 8: printf(“\nEnter The Number: “); 9: scanf(“%d”,&num); 10: binary(num); 11: printf(“\n\n\n\n\nPress any key to exit…..”); 12: getch(); 13: } 14: //function to convert deciaml to binary 15: int binary ( int n) 16: { 17: int r; 18: r=n%2; 19: n=n/2; 20: if (n==0) 21: { 22: printf(“\nThe binary equivalent is %d”,r); 23: return (r); 24: } 25: else 26: binary(n); 27: printf(“%d”,r); 28: }

Program in C to check a given year is leap year or not

1: #include<stdio.h> 2: #include<conio.h> 3: void main() 4: { 5: int year; 6: clrscr(); 7: printf(“ENTER YEAR????”); 8: scanf(“%d”,&year); 9: year%100==0?(year %400==0?printf(“leap Year”) 10: :printf(“Not a Leap Year”)):(year%4==0? 11: printf(“Leap Year”):printf(“Not a leap Year”)); 12: printf(“\n\n\n\n\nPress any key to exit…”); 13: getch(); 14: } Technorati Tags: C Language , c Programs

Program in C to calculate or find the day on 1st january of any year

1: #include<stdio.h> 2: #include<conio.h> 3: void main() 4: { 5: int leapdays,firstday,yr; 6: long int normaldays,totaldays; 7: clrscr(); 8: printf(“Enter year “); 9: scanf(“%d”,&yr); 10: normaldays=(yr-1)*365L; 11: leapdays=(yr-1)/4-(yr-1)/100+(yr-1)/400; 12: totaldays=normaldays+leapdays; 13: firstday=totaldays%7; 14: if (firstday==0) printf(“\nMonday”); 15: if (firstday==1) printf(“\Tuesday”); 16: if (firstday==2) printf(“\nWednesday”); 17: if (firstday==3) printf(“\nThrusday”); 18: if (firstday==4) printf(“\nFriday”); 19: if (firstday==5) printf(“\nSaturday”); 20: if (firstday==6) printf(“\nSunday”); 21: printf(“\n\n\n\n\nPress any key to exit….”); 22: getch(); 23: }

Program in C to calculate or find aggregate marks and percentage of a student in 5 subject

1: #include<stdio.h> 2: #include<conio.h> 3: void main() 4: { 5: int m1,m2,m3,m4,m5,aggr; 6: float per; 7: clrscr(); 8: printf(“\nEnter marks in 5 subject:”); 9: scanf(“%d%d%d%d%d”,&m1,&m2,&m3,&m4,&m5); 10: aggr=m1+m2+m3+m4+m5; 11: per=aggr/5; 12: printf(“\nAggregate Marks=%d”,aggr); 13: printf(“\nPercentage Marks=%f”,per); 14: printf(“\n\n\n\nPress any key yo exit….”); 15: getch(); 16: }

Program in C to Reverse the given string

1: #include<stdio.h> 2: int main(){ 3: int a[50],size,i,j=0,big,secondbig; 4: printf( "Enter the size of the array: " ); 5: scanf( "%d" ,&size); 6: printf( "Enter %d elements in to the array: " , size); 7: for (i=0;i<size;i++) 8: scanf( "%d" ,&a[i]); 9: 10: big=a[0]; 11: for (i=1;i<size;i++){ 12: if (big<a[i]){ 13: big=a[i]; 14: j = i; 15: } 16: } 17:   18: secondbig=a[size-j-1]; 19: for (i=1;i<size;i++){ 20: if (secondbig <a[i] && j != i) 21: secondbig =a[i]; 22: } 23: 24: printf( "Second biggest: %d" , secondbig); 25: return 0; 26: } 27:   28:  

PROGRAMMING WITH C-LANGUAGE

The Development Environment - Integrated Development Environment (IDE): The Turbo C compiler has its own built-in text editor. The files you create with text editor are called source files, and for C++ they typically are named with the extension .CPP, .CP, or .C. The C Developing Environment, also called as Programmer’s Platform, is a screen display with windows and pull-down menus. The program listing, error messages and other information are displayed in separate windows. The menus may be used to invoke all the operations necessary to develop the program, including editing, compiling, linking, and debugging and program execution. Invoking the IDE To invoke the IDE from the windows you need to double click the TC icon  in the directory c:\tc\bin. The alternate approach is that we can make a shortcut of tc.exe on the desktop. This makes you enter the IDE interface, which initially displays only a menu bar at the top of the screen and a status line below will appear. The menu bar dis

Flowcharts in Programming

Flowchart Flowchart is the graphical representation of an algorithm. It is used to show all the steps of an algorithm in a sequence pictorially. An algorithm may be converted to a flowchart. The flowchart is then converted into a program written in any programming language. Advantages of Flowcharts Flowchart is used for the following reasons: 1.    Flowchart represents an algorithm in graphical symbols. 2.    It shows the steps of an algorithm in an easy way. 3.    It is used to understand the flow of the program. Flowchart Symbols Following are the symbols used in Flowchart 1.    Start/End Oval symbol is used to represent the start or end of the flowchart. 2.    Input/Output Parallelogram symbol is used to represent an input or output step. 3.     Process Rectangle symbol is used to represent a process step. A process may be a calculation or assignment etc. 4.     Selection  Diamond symbol is used to represent a selection step. A condition is given in the diamond. If con