Tuesday, October 13, 2009

structure student

#include
#include
#include
/*Write a Program to create a
*
Structure that has
name of student,
Roll number,
mark1, mark2, and mark3
are the member variables to maintain many records.
If I want to access particular record,
then you should search the records
based on either their name or their roll number.*/
//int n;
struct stu
{
char name[50];
int rollno;
int mark1,mark2,mark3;
}b[100];
int main()
{
char data[50];
int i,n,key,flag=0;
printf("enter the number of students record in database\n");
scanf("%d",&n);
printf("enter the student details in the following sequence\n");
printf("name,rollno,mark1,mark2,mark3\n");
for(i=0;i<n;i++)
{
printf("\tenter the %d student details\n",i+1);
scanf("%s%d%d%d%d",b[i].name,&b[i].rollno,&b[i].mark1,&b[i].mark2,&b[i].mark3);
}
printf("****database details**");
for(i=0;i {
printf(" \n \nthe %d student details\n\n",i+1);
printf("\nname %s\t rollno %6.d\t mark1 %6.d\t mark2 %6.d\t mark3 %6.d",b[i].name,b[i].rollno,b[i].mark1,b[i].mark2,b[i].mark3);
}
printf("\nenter the particular students rollno\n");
scanf("%d",&key);
for(i=0;i{
if(key==b[i].rollno)
{
printf("\n****found***\n");
printf("\n name %s\trollno %d\tmark1 %d\tmark2 %d\tmark3 %d\n",b[i].name,b[i].rollno,b[i].mark1,b[i].mark2,b[i].mark3);
flag=1;
}
}
if(flag==0)
{
printf("\n***not found**\n");
}
flag=0;
printf("\n enter the particular students name\n");
scanf("%s",data);
for(i=0;i{
if(strcmp(data,b[i].name)==0)
{
printf("\n****found***\n");
printf("\n name %s\trollno %d\tmark1 %d\tmark2 %d\tmark3 %d\n",b[i].name,b[i].rollno,b[i].mark1,b[i].mark2,b[i].mark3);
flag=1;

}
}
if(flag==0)
{
printf("\n***not found**\n");
}
getch();
return 0;
}

book to be boaoak

#include
#include
#include
/*Write a Program to insert a particular character in a string
* after one specific character like
Str1 [] ="book"
Then in the above given string after character
'o' it should append a character 'a’, so output will be
Boaoak*/

int main()
{
char str1[100]="book";
char str2[100];
int i=0,j=0;

while(str1[i]!='\0')
{
if(str1[i]=='o')
{
str2[j]=str1[i];
j++;
str2[j]='a';
j++;i++;

}else
{
str2[j]=str1[i];
j++;i++;

}

}str2[j]='\0';
printf("replaced string is :%s",str2);
getch();
return 0;
}

first letter in word to caps

#include
#include
#include
/* Write a Program to in which
* the given strings like str []
* ="second week test exercise" should be outputted as
* “Second Week Test Exercise”.
* WITOUT USING ANY STANDARD FUNCTION*/
int main()
{
char str[]="second week test exercise";
int i=0;
int j=0;
while(str[i]!='\0')
{
i++;
}
printf("length of the string %d \n",i);
str[0]=str[0]-32;
while(j<=i)
{
if(str[j]==' ')
{
str[j+1]=str[j+1]-32;
}j++;
}
printf("%s",str);
getch();
return 0;
}

rotational string

1. Rotate the String and display. For example, “SCOPE” “COPES” “OPESC” “PESCO”….
#include<stdio.h>
#include<string.h>
#include"conio.h"
int main()
{
int i,j=0;
char a[100]="scope";
//printf("enter the word\n");
//scanf("%s",a);
int length;
length=strlen(a);
while(j<length)
{
for(i=0+j;i<length;i++)
{
printf("%c",a[i]);
}
for(i=0;i<j;i++)
{
printf("%c",a[i]);
}
printf("\t");
j++;
}getch();
return 0;
}

Thursday, October 8, 2009

find the smallest number of a array?

main()
{
int a[20],n,i,s;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
s=a[0];
for(i=0;i<n;i++)
{
if(s>a[i])
{
s=a[i];
}
}
printf("the smallest number is %d",s);
}



2..#include<stdio.h>
#include<conio.h>
void main()
{
int n,a[50],temp;
printf("enter the max limit :");
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
i=0;
for(int j=0;j<n-1;j++)
{
if(a[j+1]<a[j])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
printf("the smnallest is : %d",*(a+0));
getch();
}

Wednesday, October 7, 2009

temperatures

1.
#include<stdio.h>
int main()
{
int big;
float abc,g;
scanf("%d%f",&big,&abc);
g=big/2+big*4/big-big+abc/3;
printf("%f",g);
return 0;

}
Answer 3.833

2.
#include<stdio.h>
int main()
{
int on,ink=4,act=1;
float tig=3.2;
on=ink*act/2+3/2*act+2+tig;
printf("%d",on);
return 0;
}
Answer 8
3.
#include<stdio.h>
int main()
{
int qui=4,s,add=2,god;
s=qui*add/4-6/2+2/3*6/god;
printf("%d",s);
return 0;
}


Answer -1

4.
#include<stdio.h>
int main()
{
int a,b;
a=-3 - -3;
b=-3 - - (-3);
printf("a=%d b=%d",a,b);
return 0;
}
Answer a=0 b=-6





5.
#include<stdio.h>
int main()
{
float a=5,b=2;
int c;
c= a / b;
printf("%d",c);
return 0;
}
Answer 2

6. fahrengeit to celsius
#include <stdio.h>

/*
* print a table for Fahrenheit to Celsius
* from 0 F to 300 F
*/
void main(void)
{
int fahr; /* fahrenheit temperature */
int celsius; /* celsius temperature */
register int lower = 0; /* begin table here */
register int upper = 300; /* end table here */
register int step = 20; /* increment */

/*
* print out the lines for the table
*/
fahr = lower;
while(fahr <= upper){
/* get corresponding temp in degrees C */
celsius = 5 * (fahr - 32) / 9;
/* print it */
printf("%d\t%d\n", fahr, celsius);
fahr += step;
}

/*
* say goodbye
*/
exit(0);
}

Thursday, September 17, 2009

log

1.Which statement will you add in the following program to work it correctly?
#include
int main()
{
printf("%f\n", log(36.0));
return 0;
}

answer:#include"math.h"

2.We want to round off x, a float, to an int value, The correct way to do is
A.

y = (int)(x + 0.5)

B.

y = int(x + 0.5)
C.

y = (int)x + 0.5
D.

y = (int)((int)x + 0.5)



3.

Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?
A.

rem = (5.5 % 1.3)
B.

rem = modf(5.5, 1.3)
C.

rem = fmod(5.5, 1.3)

D.

Error: we can't divide

Difference between combinational logic circuit and sequential logic circuit?

The main difference between sequential circuits and combinational circuits is that sequential circuits compute their output based on input and state, and that the state is updated based on a clock.

Combinational logic circuits implement Boolean functions, so they are functions only of their inputs, and are not based on clocks.

combinational =========================== sequencial
1.memory unit is not required =============1 it is require to store the past history
2.it is faster =================== 2. less compare to that one
3.easy to design ====== 3. comparatively garder
4.parallel adder ============== 4. serial adder

latch and flipflops

tch is a level triggered device but flip flop is a edge triggered device.

Latch takes less gates but flipflop takes more.
Latch faster flipflop
slower.
Latch does'nt have a clock signal but flip flop depends on the
clock signal but both are having one bit memory.

latch is a device which is used as switch,f/f is a storing
element

Write a C program to determine the number of elements (or size) in a tree.

Try this C program

int tree_size(struct node* node)
{
if (node==NULL)
{
return(0);
}
else
{
return(tree_size(node->left) + tree_size(node->right) + 1);
}