Вы находитесь на странице: 1из 13

C unit5

Derive script accepts values 1 to 5 performs action depending upon number keyed in

Algorithm to search particular data singly linked list

246

Unit3
Programreverse string palindrome or not
#include <stdio.h>
#include <string.h>
int main()
{
char inputArray[100], reversedArray[100];
printf("Enter the string for palindrome check \n");
scanf("%s", inputArray);
/* Copy input string and reverse it*/
strcpy(reversedArray, inputArray);
/* reverse string */
strrev(reversedArray);
/* Compare reversed string with inpit string */
if(strcmp(inputArray, reversedArray) == 0 )
printf("%s is a palindrome.\n", inputArray);
else
printf("%s is not a palindrome.\n", inputArray);
getch();
return 0;
}

C program to implement macros


#include<stdio.h>
#include<conio.h>
#include<string.h>
struct mdt
{
char lab[10];
char opc[10];

char oper[10];
}d[10];
void main()
{
char label[10],opcode[10],operand[10],newlabel[10],newoperand[10];
char macroname[10];
int i,lines;
FILE *f1,*f2,*f3;
clrscr();
f1 = fopen("MACIN.txt","r");
f2 = fopen("MACOUT.txt","w");
f3 = fopen("MDT.txt","w");
fscanf(f1,"%s %s %s",label,opcode,operand);
while(strcmp(opcode,"END")!=0)
{
if(strcmp(opcode,"MACRO")==0)
{
strcpy(macroname,label);
fscanf(f1,"%s%s%s",label,opcode,operand);
lines = 0;
while(strcmp(opcode,"MEND")!=0)
{
fprintf(f3,"%s\t%s\t%s\n",label,opcode,operand);
strcpy(d[lines].lab,label);
strcpy(d[lines].opc,opcode);
strcpy(d[lines].oper,operand);
fscanf(f1,"%s %s %s",label,opcode,operand);
lines++;
}
}
else if(strcmp(opcode,macroname)==0)
{
printf("lines=%d\n",lines);
for(i=0;i<lines;i++)
{
fprintf(f2,"%s\t%s\t%s\n",d[i].lab,d[i].opc,d[i].oper);
printf("DLAB=%s\nDOPC=%\nDOPER=%s\n",d[i].lab,d[i].opc,d[i]
.oper);
}
}
else
fprintf(f2,"%s\t%s\t%s\n",label,opcode,operand);
fscanf(f1,"%s%s%s",label,opcode,operand);
}
fprintf(f2,"%s\t%s\t%s\n",label,opcode,operand);
fclose(f1);
fclose(f2);
fclose(f3);
printf("FINISHED");
getch();
}

Assembly program as input (MACIN.TXT)


?

1
2
3

CALC START 1000


SUM MACRO **
** LDA #5
** ADD #10

** sTA 2000
4
** MEND **
5
** LDA LENGTH
6
** COMP ZERO
7
** JEQ LOOP
** SUM **
8
LENGTH WORD S
9
ZERO WORD S
10
LOOP SUM **
11
** END **
12
13
14
Macro definition table (MDT.TXT)
?

1
** LDA #5
** ADD #10
2
** sTA 2000
3
Output (MACOUT.TXT)
?

1
2
3
4
5
6
7
8
9
10
11
12
13

CALC
START
1000
** LDA LENGTH
** COMP
ZERO
** JEQ LOOP
** LDA #5
** ADD #10
** sTA 2000
LENGTH WORD
S
ZERO
WORD
S
** LDA #5
** ADD #10
** sTA 2000
** END **

Write a c program to find whether the given string is palindrome

UNIX programs-unit3

Program to find greatest of 3 numbers


echo Enter 3 numbers with spaces in between
read a b c
l=$a
if [ $b -gt $l ]
then
l=$b
fi

if [ $c -gt $l ]
then
l=$c
fi
echo Lagest of $a $b $c is $l

Splitting and joining lines


By Richard Petersen

Introductory Command Line Unix for Users

Program given number prime or not


echo "Enter a number: "
read num
i=2
f=0
while [ $i -le `expr $num / 2` ]
do
if [ `expr $num % $i` -eq 0 ]
then
f=1
fi
i=`expr $i + 1`
done
if [ $f -eq 1 ]
then
echo "The number is composite"
else
echo "The number is Prime"
fi

Program sum of n odd numbers


echo Enter Upper limit
read n
$i=1
while [Si -lt $n]

do
expr $sum=$sum+$i
expr $i=$i+2
done

echo sum is : $sum


Program shell Fibonacci series
#!/bin/bash
c=0
a=1
b=1
read -p "Enter limit of fibonacci Series:" n
echo -n "$a "
echo -n "$b "
#Fibonacci series logic
while((c<n))
do
c=$((a+b))
echo -n "$c "
a=$b
b=$c
done
echo -e "\n"

enter as 21

Вам также может понравиться