Programming Assignment Help

Engineering Programming Task on EIT moodle

Q 1 – ANSWER :

int first, last;
first=1;
last=10;
for (i=first; i<last; i++)
{
}

Q 2 – ANSWER :

#include <stdio.h>
int main(void)
{
int volt_1=12;
if(volt_1 > 10)
{
printf("This prints inside the if function \n");
}
printf("This prints outside the if function \n");
}

Q 3 – ANSWER :

#include <stdio.h>
int main(void)
{
FILE * fp;

// opening a file
fp = fopen(“demo.txt”, “w”);

// writing into a file
fprint(fp,“learn to write into a file\n”);

// closing a file
fclose(fp);
}

Q 4 – ANSWER :

#include <stdio.h>
int main(void)
{
char sentence[100];
int i, count=0;
sentence=”a quick brown box jumps over a lazy dog”;

for(i=0; sentence[i]!=’\0’;i++)
{
if(sentence[i]==’ ’)
{
count++;
}
}
printf(“\n No. of Spaces in Sentence : %d”,count);
}

Q 5 – ANSWER :

clc
clear all
close all
randseed(1234);
trial=input('enter no. of trials : ');
for i=1:1:trial
c1(i) = randi([0, 1]);
c2(i) = randi([0, 1]);
c3(i) = randi([0, 1]);
fprintf('\ntrial # %d\n',i);
fprintf('——————\n');
fprintf('coin1=%d coin2=%d coin3=%d\n',c1(i),c2(i),c3(i));
end
total=[c1 c2 c3];
heads_count=find(total==1);
heads_count=length(heads_count);
fprintf('\npercentage of trials all three coins land on Heads(i.e. 1) in the
simulation are : %d\n',heads_count);

CODE OUTPUT :

enter no. of trials : 5

trial # 1
——————
coin1=1 coin2=1 coin3=1

trial # 2
——————
coin1=0 coin2=1 coin3=1

trial # 3
——————
coin1=1 coin2=0 coin3=1

trial # 4
——————
coin1=0 coin2=0 coin3=0

trial # 5
——————
coin1=1 coin2=1 coin3=0

percentage of trials all three coins land on Heads(i.e. 1) in
the simulation are : 9