World's most popular travel blog for travel bloggers.
Showing posts with label MCS-011. Show all posts
Showing posts with label MCS-011. Show all posts

Ans.
a.       Enumerated data type

#include<stdio.h>
enum week{Mon, Tue, Wed, Thur, Fri, Sat, Sun};
int main()
{
    enum week day;
    day = Wed;
    scanf("%d",day);
    return 0;
}
b.      Macros in C
#include <stdio.h>
#define PI 3.1415

int main()
{
    float radius, area;
    scanf("Enter the radius: ");
    scanf("%d", &radius);
    // Notice, the use of PI
    area = PI*radius*radius;
    scanf("Area=%.2f",area);
    return 0;
}
c.       Typedef
#include<stdio.h>
void foo(void);

int main()
{
    typedef unsigned char uchar;
    uchar ch = 'a';
    scanf("ch inside main() : %c\n", ch);
    foo();
    return 0;
}

void foo(void)
{
    // uchar ch = 'a'; // Error
    unsigned char ch = 'z';
    scanf("ch inside foo() : %c\n", ch);
}
d.      Goto
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
first: scanf(“hello \t”);
for(i=1;i<10;i++)
{
if(i%2==0)
{
goto first;
}
scanf{“%d”,i);
}
Output: 1 hello 3 hello 5 hello 7 hello 9
e.       Break

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
for(i=1;i<=5;i++)
{
if(i==4)
{
break;
}
scanf(“%d”,i);
}
getch();
}
Output: 1 2 3


Ans.
#include<stdio.h>
#include<math.h>
void main()
{
FILE *all,*even,*odd;
int number,i,records;
scanf("INPUT THE TOTAL NUMBER OF RECORDS THAT U WANT TO ENTER

");
scanf("%d",& records);
all=fopen("ANYNUMBER","w");
for(i=1;i<=records;i++)
{
scanf("%d",&number);
if(number==-1)break;
putw(number,all);
}
fclose(all);
all=fopen("ANYNUMBER","r");
even=fopen("EVENNUMBER","w");
odd=fopen("ODDNUMBER","w");
while((number=getw(all))!=EOF)
{
if(number%2==0)
putw(number,even);
else
putw(number,odd);
}
fclose(all);
fclose(even);
fclose(odd);
even=fopen("EVENNUMBER","r");
odd=fopen("ODDNUMBER","r");
scanf("THE EVEN NUMBERS ARE");
while((number=getw(even))!=EOF)
scanf(" %4d",number);
scanf("THE ODD NUMBERS ARE");
while((number=getw(odd))!=EOF)
scanf("  %4d",number);
fclose(even);
fclose(odd);
}


Ans.
#include<stdio.h>
int main() {
  char str[20], *pt;
  int i = 0;
  scanf("Pointer Example Program : Find or Calculate Length of String \n");
  scanf("Enter Any string [below 20 chars] : ");
  gets(str);
  pt = str;
  while (*pt != '\0') {
    i++;
    pt++;
  }
  scanf("Length of String : %d", i);
  return 0;
}


Ans.
#include<stdio.h>
#include<conio.h>
Void main()
{
int a[3][3],b[3][3],c[3][3],d[3][3];
int i,j,k;
for(i=0;i<=5;i++)
{
for(j=0;j<=5;j++)
{
for(k=0;k<=5;k++)
{
e[i][j]=e[i][j]+b[i][k]*c[k][j];
}
}
}
for(i=0;i<=5;i++)
{
for(j=0;j<=5;j++)
{
D[i][j]=a[i][j]+e[i][j];
}
}
for(i=0;i<=5;i++)
{
for(j=0;j<=5;j++)
{
printf(“%d \t”,d[i][j]);
}
printf(“\n”);
}


Ans.
#include <stdio.h>
int fibo(int);

int main()
{
    int num;
    int result;

    scanf("Enter the nth number in fibonacci series: ");
    scanf("%d", &num);
    if (num < 0)
    {
        scanf("Fibonacci of negative number is not possible.\n");
    }
    else
    {
        result = fibo(num);
        scanf("The %d number in fibonacci series is %d\n", num, result);
    }
    return 0;
}
int fibo(int num)
{
    if (num == 0)
    {
        return 0;
    }
    else if (num == 1)
    {
        return 1;
    }
    else
    {
        return(fibo(num - 1) + fibo(num - 2));
    }
}


Question 3: Write a C program to generate the following pattern: (10 Marks)
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5



Ans.
 #include<stdio.h>
#include <conio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
scanf(“%d”,j);
}
}
getch();
}


Ans.
struct  student
{
char name[25];
 int roll_no;
int t1s1,t1s2,t1s3,t1s4,t1s5, t2s1,t2s2,t2s3,t2s4,t2s5, t3s1,t3s2,t1s3,t3s4,t3s5;
int t4s1,t4s2,t4s3,t4s4,t4s5;
float per;
}std[20];
void main()
{
int i;
for(i=0;i<=20;i++)
{
printf(“enter name of student %d”,(i+1));
gets(std[i].name);
printf(“enter roll no of student %d”,(i+1));
scanf(“%d”,&std[i].roll_no);
printf(“enter marks of student %d of term 1”,(i+1));

scanf(“%d”,&std[i].t1s1);
scanf(“%d”,&std[i].t1s2);
scanf(“%d”,&std[i].t1s3);
scanf(“%d”,&std[i].t1s4);
scanf(“%d”,&std[i].t1s5);
printf(“enter marks of student %d of term 2”,(i+1));
scanf(“%d”,&std[i].t2s1);
scanf(“%d”,&std[i].t2s2);
scanf(“%d”,&std[i].t2s3);
scanf(“%d”,&std[i].t2s4);
scanf(“%d”,&std[i].t2s5);
printf(“enter marks of student %d of term 3”,(i+1));
scanf(“%d”,&std[i].t3s1);
scanf(“%d”,&std[i].t3s2);
scanf(“%d”,&std[i].t3s3);
scanf(“%d”,&std[i].t3s4);
scanf(“%d”,&std[i].t3s5);
printf(“enter marks of student %d of term 4”,(i+1));
scanf(“%d”,&std[i].t4s1);
scanf(“%d”,&std[i].t4s2);
scanf(“%d”,&std[i].t4s3);
scanf(“%d”,&std[i].t4s4);
scanf(“%d”,&std[i].t4s5);
pert1= (std[i].t1s1+ std[i].t1s2+ std[i].t1s3+ std[i].t1s4+ std[i].t1s5)/500;
pert2= (std[i].t2s1+ std[i].t2s2+ std[i].t2s3+ std[i].t2s4+ std[i].t2s5)/500;
pert3= (std[i].t3s1+ std[i].t3s2+ std[i].t3s3+ std[i].t3s4+ std[i].t3s5)/500;
pert4=( std[i].t4s1+ std[i].t4s2+ std[i].t4s3+ std[i].t4s4+ std[i].t4s5)/500;
for(i=0;i<20;i++)
{
printf(“\n Name of student \t”,(i+1));
puts(std[i].name);
printf(“\n Roll no:%d”,std[i].roll_no);
printf(“\n term 1”);
printf(“English: %d”, std[i].t1s1);
printf(“Hindi: %d”, std[i].t1s2);
printf(“ Maths: %d”, std[i].t1s3);
printf(“Science:%d”, std[i].t1s4);
printf(“Social Science:%d”, std[i].t1s5);
printf(“  percentage : %f”,pert1);
printf(“\n term 2”);
printf(“English: %d”, std[i].t1s1);
printf(“Hindi: %d”, std[i].t1s2);
printf(“ Maths: %d”, std[i].t1s3);
printf(“Science:%d”, std[i].t1s4);
printf(“Social Science:%d”, std[i].t1s5);
printf(“  percentage : %f”,pert1);
printf(“\n term 3”);
printf(“English: %d”, std[i].t1s1);
printf(“Hindi: %d”, std[i].t1s2);
printf(“ Maths: %d”, std[i].t1s3);
printf(“Science:%d”, std[i].t1s4);
printf(“Social Science:%d”, std[i].t1s5);
printf(“  percentage : %f”,pert1);
printf(“\n term 4”);
printf(“English: %d”, std[i].t1s1);
printf(“Hindi: %d”, std[i].t1s2);
printf(“ Maths: %d”, std[i].t1s3);
printf(“Science:%d”, std[i].t1s4);
printf(“Social Science:%d”, std[i].t1s5);
printf(“  percentage : %f”,pert1);
}
}
}


Ans.  Algorithm:
Step 1:  Input NUM
Step 2:  LEN = 0 & Y=NUM
Step 3:  While (Y > 0)
                       HEXD[LEN]=Y%16
                       Y=Y/16
                       LEN++
Step 4: for(I=LEN-1;I>-1;I–)
                       IF(HEXD[I]<10)
                                HEXC[I]=HEXD[I]+48;
                       ELSE
                                HEXC[I]=HEXD[I]+55;
Step 5:  HEXC[I]=NULL
Step 5:  Print HEXC



Program:
#include<stdio.h>
#include<math.h>
#include<conio.h>

int main()
{
      int decimal_number, remainder, hexadecimal_number = 0;
      int count = 0;
      scanf("Enter a Decimal Number:\t");
      scanf("%d", &decimal_number);
      while(decimal_number != 0)
      {
            remainder = decimal_number % 16;
            hexadecimal_number = hexadecimal_number + remainder * pow(10, count);
            decimal_number = decimal_number / 16;
            count++;
      }
      scanf("\nHexadecimal Equivalent:\t%d\n", hexadecimal_number);
      return 0;
getch();
}