ECK3131 -- C Programming
Assingment 01
Q 001
B...
#include<stdio.h>
int main()
{
int num,res;
float s;
for(num=1;num<=10;num++){
res=(num*num);
printf(" %d squars: %d",num,res);
}
scanf("%f",&s);
}
B...
#include <math.h>
#include <stdio.h>
int main()
{
int num,numspace,x,y;
float s;
int fraction, integer;
for(num=11;num>=1;num--)
{
fraction = modf(num, &integer);
printf("%1f",&fraction);
if (fraction/2==1)
{
goto gg;
}
else {
fraction==fraction+1;
}
gg:
numspace=(((fraction+1)/2)-1); //calculate space on each line
for (x=1; x<=numspace;x++) //print spaces
{
printf("2");
}
//********************************************************
//for(y=1;y<=3;num++)//print characters
//{
printf("*");
//}
}
scanf("%f",&s);
}
Q 002
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void display_info(void);
int add_int(int x,int y);
int divide_int(int x5,int y5);
int muiltiply_int(int x6,int y6);
int subtract_int(int x7,int y7);
main()
{
char choice,hold;
int num1,num2,h,x1,x2,x3,x4;
float r;
s :
printf("
Enter first Integer ?.");
scanf("%d",&num1);
printf("
Enter Second Integer ?.");
scanf("%d",&num2);
display_info();
choice=getche();
switch(choice)
{
case 'a':
x1=add_int(num1,num2);
printf("
The result is = %d",x1);
hold=getche();
clrscr();
goto s;
break;
case 'b':
r=divide_int(num1,num2);
printf("
The result is = %f",r);
hold=getche();
clrscr();
goto s;
break;
case 'c':
x3=muiltiply_int(num1,num2);
printf("
The result is = %d",x3);
hold=getche();
clrscr();
goto s;
break;
case 'd':
x4=subtract_int(num1,num2);
printf("
The result is = %d",x4);
hold=getche();
clrscr();
goto s;
break;
case 'q':
exit(0);
default :
printf("
sorry, wrong character... ");
clrscr();
goto s;
}
}
void display_info(void)
{
printf("
a -- Add two integers ");
printf("
b -- Divide two integers ");
printf("
c -- Multiply two integers");
printf("
d -- Subtract two integers");
printf("
q -- Quit");
printf("
Enter your required character ?. ");
}
int add_int(int x,int y)
{
int z;
z=x+y;
return z;
}
int divide_int(int x5,int y5)
{
float g;
g=x5/y5;
return g;
}
int muiltiply_int(int x6,int y6)
{
int j;
j=x6*y6;
return j;
}
int subtract_int(int x7,int y7)
{
int k;
k=x7-y7;
return k;
}

Q 1 A
#include<stdio.h>
int main()
{
int num,res;
float s;
for(num=1;num<=10;num++){
res=(num*num);
printf("
%d squars: %d",num,res);
}
scanf("%f",&s);
}
