Answer 1
Answer 1
An algorithm is a finite set of steps defining the solution of a particular problem. An algorithm is
expressed in pseudo code – something resembling C language or Pascal, but with some
statements in English rather than within the programming language
1. A sequential solution of any program that written in human language, called algorithm.
2. Algorithm is first step of the solution process, after the analysis of problem, programmers
write the algorithm of that problem.
Pseudo code
Input Num
Initialize Len to zero and Y to Num
While Y is not zero
Save Remainder by Y Mod 16 in array HEXD at index Len
Initialize Y to Y divided 16
Increment Len
for(Initialize I to Len-1 ; Condition I Greater than -1 ; Decrement I )
If HEXD[I] Less than 10
HEXC[I]=HEXD[I]+48
Else
HEXC[I]=HEXD[I]+55
Initialize HEXC[I] to NULL
Print HEXC
Detailed Algorithm:
HEXD[LEN]=Y%16
Y=Y/16
LEN++
Step 4: for(I=LEN-1;I>-1;I–)
IF(HEXD[I]<10)
HEXC[I]=HEXD[I]+48;
ELSE
HEXC[I]=HEXD[I]+55;
Step 5: HEXC[I]=NULL
Flowchart:-
long int hexd[50],i=0,len=0;
long int y=num; while(y>0)
{
hexd[i]=num%16; y=y/16;
i++;
len++;
}
printf("Hexadecimal number
: "); for(i=len-1;i>=0;i-
-)
{
switch(hexd[i])
{
case 10:
printf("A"); break;
case 11:
printf("B"); break;
case 12:
printf("C"); break;
case 13:
printf("D"); break;
case 14:
printf("E"); break;
case 15:
printf("F"); break;
default :
printf("%ld",hexd[i]);
}
}
}
//===================================
=============
void main()
{
long int num;
clrscr();
printf("Enter the decimal number : ");
scanf("%ld",&num);
dec_hex(num);
getch();
}
ANSWER 2.
#include<stdio.h>
struct student
{
int ROLL;
char NAME[15];
int S1T1,S1T2,S1T3,S1T4,S2T1,S2T2,S2T3,S2T4,S3T1,S3T2,S3T3,S3T4
,S4T1,S4T2,S4T3,S4T4,S5T1,S5T2,S5T3,S5T4,S6T1,S6T2,S6T3,S6T4;
}STUD[12]={
{1,”GANESH” ,25,6,28,6,35,8,26,4,35,6,34,7,27,7,36,5,34,7,31,8,35,7,26,9},
{2,”MAHESH” ,35,6,26,7,31,6,36,8,25,5,29,6,28,9,37,9,27,7,34,6,31,5,31,8},
{3,”SURESH” ,21,9,27,7,26,7,28,7,31,6,29,6,28,9,37,9,27,7,34,6,31,5,31,8},
{4,”KALPESH” ,28,9,37,9,27,7,34,6,31,5,31,8,21,9,27,7,26,7,28,7,31,6,29,6},
{5,”RAHUL” ,27,7,36,5,34,7,31,8,35,7,26,9,21,9,27,7,26,7,28,7,31,6,29,6},
{6,”SUBBU” ,29,9,34,7,38,9,37,7,34,9,36,8,25,8,37,9,34,7,35,7,27,9,26,7},
{7,”RAKESH” ,25,8,37,9,34,7,35,7,27,9,26,7,29,9,34,7,38,9,37,7,34,9,36,8},
{8,”ATUL” ,25,6,38,7,35,8,25,7,27,9,26,6,27,7,36,5,34,7,31,8,35,7,26,9},
{9,”DHARMESH”,35,6,37,7,34,8,36,8,37,7,34,9,28,9,37,9,27,7,34,6,31,5,31,8},
{10,”AJAY” ,35,7,37,6,34,5,35,7,37,6,36,5,21,9,27,7,26,7,28,7,31,6,29,6},
{11,”ABDUL” ,25,5,28,7,25,5,26,6,25,6,34,5,35,6,26,7,31,6,36,8,25,5,29,6},
{12,”RASHMI” ,35,7,38,5,25,6,36,5,35,4,26,5,25,6,28,6,35,8,26,4,35,6,34,7}
};
void main()
{
int ROL_NO;
void gen_result(int);
clrscr();
Answer 3.
#include
<stdio.h> int
main()
{
int i, j, rows;
int Fibonacci(int n)
{
if ( n == 0 ) return 0;
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );
}
Answer 5
Answer 6.
int main() {
char str[20], *pt;
int i = 0;
printf("Pointer Example Program : Find or Calculate Length of String \n");
printf("Enter Any string [below 20 chars] : ");
gets(str);
pt = str;
while (*pt != '\0') {
i++;
pt++;
}
printf("Length of String : %d", i);
return 0;
}
Answer 7.
#include<math.h>
void main()
{
number,i,records;
printf("INPUT THE TOTAL NUMBER OF RECORDS THAT U WANT TO ENTER");
scanf("%d",& records); all=fopen("ANYNUMBER","w");
for(i=1;i<=records;i++)
scanf("%d",&number); if(number==-1)break;
putw(number,all);
fclose(all); all=fopen("ANYNUMBER","r");
even=fopen("EVENNUMBER","w");
odd=fopen("ODDNUMBER","w");
while((number=getw(all))!=EOF)
putw(number,odd);
even=fopen("EVENNUMBER","r");
ARE");
fclose(odd);
Answer 8.
Enumerated data type
int main()
{
enum week today;
today = wednesday;
printf("Day %d",today+1);
return 0;
}
Output
Day 4
b) Macros In C
C program example
for Macros:
#include<stdio.h>
#include<conio.h>
#define square(x)
x*x void main()
{
int n,s;
clrscr()
;
printf("Enter a number :
"); scanf("%d",&n);
s=square(n);
printf("Square of given number =
%d",s); getch();
}
(c) typedef
Example:
#include<stdio.h>
#include<string.h>
Ans. C supports a unique form of a statement that is the goto Statement which is used to
branch unconditionally within a program from one point to another. Although it is not a good
habit to use goto statement in C, there may be some situations where the use of goto statement
might be desirable.
The goto statement is used by programmers to change the sequence of execution of a C
program by shifting the control to a different part of the same program.
Example:
#include<stdio.h> void main()
{ int age;
g: //label name
printf("you are Eligible\n"); s: //label name
printf("you are not Eligible");
printf("Enter you age:"); scanf("%d", &age);
if(age>=18)
goto g; //goto label g
else
goto s; //goto label s getch();
}
(e) Break statement
Ans. The break statement in C programming has the following two usages –
It can be used to terminate a case in the switch statement (covered in the next
chapter).
Example:
#include <stdio.h>
int main () {
/* local variable definition */ int a
= 10;
/* while loop execution */
while( a < 20 ) {
printf("value of a: %d\n", a);
a++;
if( a > 15) {
/* terminate the loop using break statement */
break;
}
}
return 0;
}