Tuesday, October 13, 2009

pointer

8. By using the given below information answer the questions which follow,
Var. Name Address Contents
P 2568 425
Q 4284 2568
R 6242 4284
A[10] 8468 232
B [10] 8478 2568
a. &p =? 2568
b. *q =? 425
c. **r =? 425
d. &q =? 4284
e. *(&q) =? 2568
f. &(*r) = ? 4284

star

#include"stdio.h"
#include"string.h"
#include"conio.h"
/*Write a program to print the following output
A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
*/
int main()
{
int i,k=1,j=1,len,size;
char let[]={'A','B','C','D','E','F','G','\0'};
len=strlen(let);
size=len;
printf("string len is %d\n\n",len);
for(i=0;i printf("%c",let[i]);
for(i=len-2;i>=0;i--)
printf("%c",let[i]);
printf("\n");printf("\n");

while(k<size)
{
for(i=0;i<len-1;i++)
printf("%c",let[i]);
for(i=0;i<(1*j);i++)
printf(" ");
for(i=len-2;i>=0;i--)
printf("%c",let[i]);

j=j+2;
k++;
len--;
printf("\n");printf("\n");
}
getch();
return 0;
}

string manipulation without library

#include
#include
#include
/*b. Without using library
*
function doing the above operation.
1.string copy,
2.string length
3. String concatenation and
study the function like stricmp, strrev.*/
int main()
{
char str[100];
char str1[100];
char temp[100];
printf("enter the string\n");
scanf("%s",str);
int k,i=0,j=0; //1.string length
while(str[i]!='\0')
{
i++;
}printf("\nstring %s length is:%d\n",str,i);

int length=i; //2.string copy
for(k=0;k<length;k++)
{
str1[k]=str[k];
}
str1[k]='\0';
printf("\n string copy str to str1 like %s to %s\n",str,str1);
//string concatenation
i=0;
while(str1[i]!='\0')
{
i++;
}printf("\n string %s length is:%d\n",str1,i);
int length2=i;
for(k=0;k<(length2+length);k++)
{
if(k {
str[k]=str[k];
}else
{
str[k]=str1[j];
j++;
}
}
str[k] = '\0';
printf("string concatenation like :%s\n",str);

//string reverse
j=0;
for(k=length2-1;k>=0;k--)
{
temp[j]=str1[k];
j++;
}
temp[j]='\0';
printf("\n string reverse %s is %s",str1,temp);
//6.stricmp
printf("\n enter the first string\n");
scanf("%s",str);
printf("enter the second string\n");
scanf("%s",str1);
i=0;
while(str[i]!='\0')
{
i++;
}length=i;
while(str1[i]!='\0')
{
i++;
}length2=i;
if(length==length2)
{
k=0;i=0;
while(k<length)
{
if(str[k]==str1[k] || str[k]==str1[k]+32 || str[k]==str1[k]-32)
{
i++;
}
k++;
}if(i==length)
{
printf("str %s and str1 %s is matched",str,str1);
}else
{
printf("str %s and str1 %s is not matched",str,str1);
}
}
getch();
return 0;
}

strtok

#include
#include
#include
/*Write a Program to split the given string like
str [] ="1>2>3>4>5>" using string tokenizer*/
int main()
{
char str[]="1>2>3>4>5>";
char *a;
a=strtok(str,">");
printf("%s\n",a);
a=strtok(NULL,">");
printf("%s\n",a);
a=strtok(NULL,">");
printf("%s\n",a);
a=strtok(NULL,">");
printf("%s\n",a);
a=strtok(NULL,">");
printf("%s\n",a);
getch();
return 0;
}

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);
}