0% found this document useful (0 votes)
79 views

CS Assignment

This document contains a computer science assignment submitted by Aranya Raj Singh with ID 2016UCH1680. It includes the student's responses to 47 questions related to C programming concepts like data types, operators, loops, functions, arrays, strings, pointers, structures and file handling. The questions cover a range of fundamental and advanced C programming topics.

Uploaded by

Aranya raj singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

CS Assignment

This document contains a computer science assignment submitted by Aranya Raj Singh with ID 2016UCH1680. It includes the student's responses to 47 questions related to C programming concepts like data types, operators, loops, functions, arrays, strings, pointers, structures and file handling. The questions cover a range of fundamental and advanced C programming topics.

Uploaded by

Aranya raj singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

 

Computer Science  
assignment 
BY -ARANYA RAJ 
SINGH 
BATCH-F4
ID-2016UCH1680
ROLL NO-56
 
Q1-
Ans. (a)8bits
Q2-
Ans. (c)ROM
Q3-
Ans. (c)Logical Address
Q4-
Ans. (b) Processor and memory
Q5-
Ans. (d) Cache
Q6-
Ans. (c) Complex instruction set computer
Q7-
Ans. (a) Main memory
Q8-
Ans.
#include<stdio.h>
void main()
{
int a,b,c ;
printf("enter three numbers") ;
scanf("%d%d%d",&a,&b,&c) ;
a=a+b+c ;
c=a-b-c ;
b=a-b-c ;
a=a-b-c ;
printf("swap number is:%d %d %d",a,b,c);
}

Q9-
Ans.
#include<stdio.h>
void main()
{
int a,b,c,temp;
printf("enter three numbers");
scanf("%d%d%d",&a,&b,&c);
temp=a;
a=b;
b=c;
c=temp;
printf("swap number is:%d %d %d",a,b,c);

}
Q10-
Ans.
#include<stdio.h>
void main()
{
int a,b,temp;
printf("enter two number");
scanf("%d%d",&a,&b);
temp=a;
a=b;
b=temp;
printf("swap number is:%d %d",a,b);
}
Q11-
Ans.
#include<stdio.h>
void main()
{
int a,b;
printf("enter two numbers");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("swap number is:%d %d",a,b);
}
Q12-
Ans.
#include<stdio.h>
void main()
{
int h,m,s,ts;
printf("enter hour minute time");
scanf("%d%d%d",&h,&m,&s),
ts=h*3600+m*60+s;
printf("total second is:%d",ts);
}
Q13-
Ans.
#include<stdio.h>
void main()
{
int f;
float c;
printf("enter farnehite temperature");
scanf("%d",&f);
c=(f-32)*5/9.0;
printf("centrigade temp is:%f",c);

}
Q14-
Ans.
#include<stdio.h>
void main()
{
int a,rev,i,sum=0;
printf("enter a number");
scanf("%d",&a);
for(i=1;i<4;i++)
{
rev=a%10;
a=a/10;
sum+=rev;
}
printf("sum is:%d",sum);
}
Q15-
Ans.
#include<stdio.h>
void main()
{
int a,rev=0,n,i;
printf("enter a number");
scanf("%d",&a);
for(i=1;a!=0;i++)
{
n=a%10;
a=a/10;
rev=rev*10+n;
}
printf("reverse number is:%d",rev);
}
Q16-
Ans.
#include<stdio.h>
void main()
{
int a,m=0,n;
printf("enter total number to merged");
scanf("%d",&n);
for(a=1;a<=n;a++)
{
m=m*10+a;
}
printf("merged number is:%d",m);
}

Q17-
Ans.
A) Maximum out of Three Numbers
Algorithm​:
1. Start.
2. Initialize three integer type variables.
3. Scan three variables.
4. If a>b and a>c ​→​ print a.
5. If b>c ​→​ print b.
6. Else ​→​ print c.
7. End.
Pseudo Code​:
main()
{
integer a,b,c;
print ​→​ “Enter Three Numbers”;
scanf ​←​ a,b,c;
if ((a>b) & (a>c)) ​→​ Print “a”;
else if (b>c) ​→​ Print “b”;
else ​→​ Print “c”;
}
​Flow Chart​:
True

False
True

False
B) Maximum out of Four Numbers

Algorithm​:
1. Start.
2. Initialize Integer type array[4],i,big;
3. Scan elements of array;
4. Declare big ​←​ a[0];
5. for loop (i ​←​0;i<4;i=i+1)
if(a[i]>big)
big ​←​ a[i];
6. Print ​→​ big.
7. End.

Pseudo Code​:
main()
{
int a[4],i,big;
printf ​→​ “Enter Four Numbers”;
for(i ​←​ 0;i<4;i++)
{
if(a[i]>big)
big ​←​ a[i];
}
printf ​→​ “Largest of these Four
Numbers : “ ​→​ big;
}

Flow Chart​:

Q18-
Ans. (A) record1-valid
(B)$tax-invalid,$ must not in variable name
(C)name_and_address=valid
(D)1record=invalid,variable name is not
started by digit
(E)name=valid
(F)name-and-address=invalid, this sign(-)
can not be used
(G)file_3=valid
(H)name and address=invalid,space will not
be there
(I)123-45=invalid
(J)return=invalid,predefined keyword

Q19-
Ans.validcharacter constant=’a’,’\0’,’$’,’\a’,’\n’,’t’

Q20-
Ans.garbage
Q21-
Ans.6

Q26-
Ans.a and b are equal

Q27-
Ans.
#include<stdio.h>
void main()
{
int a,b,c,d,e=0,f=0,g=0,h=0;
printf("enter four numbers");
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a>b&&a>c&&a>d)
{
h=b>c?(b>d?b:d):(c>d?c:d);
printf("sec lar is:%d",h);
}
if (b>c&&b>a&&b>d)
{
e=a>c?(a>d?a:d):(c>d?c:d);
printf("second lar is:%d",e);
}
if(c>a&&c>b&&c>d)
{
f=b>a?(b>d?b:d):(a>d?a:d);
printf("sec lar is:%d",f);
}
if(d>a&&d>b&&d>c)
{
g=a>c?(a>b?a:b):(c>b?c:b);
printf("sec lar is:%d",g);
}
}

Q28-
Ans.
#include<stdio.h>
void main()
{
int c,mr=100,tb;
printf("enter numbers of call");
scanf("%d",&c);
if(c>=1&&c<=100)
{
tb=mr+c*0;
printf("total charge is:%d",tb);
}
else if(c>=101&&c<=200)
{
tb=mr+c*0.8;
printf("total charge is:%d",tb);
}
else if(c>=201&&c<=500)
{
tb=mr+c*1;
printf("total charge is:%d",tb);
}
else
{
tb=mr+c*1.2;
printf("total charge is:%d",tb);
}
}
Q29-
Ans.
#include<stdio.h>
void main()
{
int a,rev=0,n,i,t;
printf("enter three digit number");
scanf("%d",&a);
t=a;
for(i=1;i<4;i++)
{
n=a%10;
a=a/10;
rev=rev*10+n;
}
if(rev==t)
{
printf("number is magic number");
}
else
printf("number is not magic number");
}

Q30-
Ans.
#include<stdio.h>
void main()
{
int y;
printf("enter a year");
scanf("%d",&y);
if(y%4==0)
{
if(y%100==0)
{
if(y%400==0)
printf("year is leap year");
else
printf("year is not leap year");
}
else
printf("year is leap year");
}
}

Q31-
Ans.
#include<stdio.h>
void main()
{
char a;
printf("enter character");
scanf("%d",&a);
if(a>=48&&a<=57)
printf("character entered is digit");
if(a>=65&&a<=90)
printf("character entered is upper case");
if(a>=97&&a<=122)
printf("character entered is lower case");

if((a>=0&&a<=47)||(a>=58&&a<=64)||(a>=91
&&a<=96)||(a>=123&&a<=127))
printf("character is special symbol");
}

Q33-
Ans.
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c;
float r1,r2;
printf("enter coefficient of quardetic");
scanf("%d%d%d",&a,&b,&c);
if(b*b-4*a*c>=0)
{
r1=(-b+pow(b*b-4*a*c,0.5))/2*a;
r2=(-b-pow(b*b-4*a*c,0.5))/2*a;
printf("roots is:%f %f",r1,r2);
}
else
printf("roots is imaginary");
}
Q34-
Ans.
#include<stdio.h>
void main()
{
char a;
int b,c,d;
printf("enter the condition");
scanf("%c",&a);
printf("enter two number");
scanf("%d%d",&b,&c);
switch(a)
{
case '+':
{
d=b+c;
printf("sum is:%d",d);
break;
}
case '-':
{
d=b-c;
printf("sub. is:%d",d);
break;
}
case '*':
{
d=b*c;
printf("multiply is:%d",d);
break;
}
case '/':
{
d=b/c;
printf("div. is:%d",d);
break;
}
case '%':
{
d=b%c;
printf("remainder is:%d",d);
}
default:
printf("operator is not correct");
}
}

Q36-
Ans.
#include<stdio.h>
void main()
{
int a=1,b=1,i,n;
printf("enter terms");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d\n",a);
b=a+b;
a=b-a;
}
}

Q37-
Ans.
#include<stdio.h>
void main()
{
int i,a[10],n,found=1;
printf("enter the value of n\n");
scanf("%d",&n);
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i+1]<=a[i])
found=0;
}
if(found==1)
printf("increasing order");
else
printf("not in ascending order\n");
}
Q38-
Ans.
#include<stdio.h>
#include<math.h>
void main()
{
int sum,n;
printf("enter the terms in series");
scanf("%d",&n);
sum=(10*(pow(10,n)-1))/9-n;
printf("sum is:%d",sum);
}

Q39-
Ans.
#include<stdio.h>
#include<conio.h>
int fact (int a);
void main()
{
int p,q,r,n=4,s,i,j;
for(i=0;i<=n;i++)
{
for(j=0;j<=i;j++)
{
p=fact(i);
q=fact(j);
r=fact(i-j);
s=p/(q*r);
printf("%d",s);
}
printf("\n");
}
getch();
}
fact (int b)
{
int p=1,i;
for(i=1;i<=b;i++)
p=p*i;
return p;
}

Q40-
Ans.
#include<stdio.h>
void main()
{
int a,s;
printf("enter a number");
scanf("%d",&a);
if(a>0)
{
s=a*a;
printf("square is:%d",s);
}
else
printf("no output");
}

Q41-
Ans.
#include<stdio.h>
void main()
{
int a,i,n,num=0,j,bi=0,r;
printf("enter a number");
scanf("%d",&a);
for(i=1;a!=0;i++)
{
n=a%2;
a=a/2;
num=num*10+n;
}
for(j=1;num!=0;j++)
{
r=num%10;
num=num/10;
bi=bi*10+r;
}
printf("binary number is:%d",bi);
}

Q42-
Ans.
#include<stdio.h>
void main()
{
int a;
float c;
printf("enter a number");
scanf("%d",&a);
c=log(a);
printf("logarithm is:%f",c);
}

Q44-
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,l,s;
for(i=7;i>=1;i--)
{
for(j=1;j<=i;j++)
printf("%c",j+64);
for(k=7;k>=i+1;k--)
printf(" ");
for(l=7;l>=i+2;l--)
printf(" ");
if(i==7)
{
for(i=6;i>=1;i--)
printf("%c",i+64);
}
else
{
for(s=i;s>=1;s--)
printf("%c",s+64);
}
printf("\n");
}
getch();
}

Q46-
Ans.
#include<stdio.h>
void main()
{
int rev=0,a,oc=0,n,m,j,i,p=0;
printf("enter a number");
scanf("%d",&a);
for(i=1;a!=0;i++)
{
n=a%10;
a=a/10;
rev=rev*10+n;
}
for(j=1;rev!=0;j++)
{
m=rev%8;
rev=rev/8;
oc=oc+m*pow(10,p);
p++;
}
printf("octal number is:%d",oc);
}

Q47-
Ans.
#include<stdio.h>
void main()
{
int i,s,k,j;
for(i=4;i>=1;i--)
{
for(s=i;s>=2;s--)
printf(" ");
for(k=4;k>=i;k--)
printf("%d",k);
for(j=i+1;j<=4;j++)
printf("%d",j);
printf("\n");
}
for(i=2;i<=4;i++)
{
for(s=i;s>=2;s--)
printf(" ");
for(k=4;k>=i;k--)
printf("%d",k);
for(j=i+1;j<=4;j++)
printf("%d",j);
printf("\n");
}
}

Q48-
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[50],pos,n,t;
printf("enter the value of n\n");
scanf("%d",&n);
printf("enter the sequence\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=n-1;i>=0;i--)
{
if(a[i]!=a[i-1])
{
printf("the second max is %d\n",a[i]);
pos=i;
printf("position is\t");
printf("%d",pos);
break;
}
}
getch();
}

Q49-
Ans.
#include<stdio.h>
void main()
{
int i,j,k;
for(i=1;i<4;i++)
{
for(j=1;j<4;j++)
{
for(k=1;k<4;k++)
printf("combination
is:%d%d%d",i,j,k);
}
}
}

Q50-
Ans.
#include<stdio.h>
void main()
{
int i,sum=0;
printf("enter the value of n\n");
scanf("%d",&n);
for(j=2;j<=n;j++)
{
for(i=2;i<=j/2;i++)
{
if(j%i!=0)
{
if(i==j/2)
{
sum=sum+j;
}

continue;
}
}
}
printf("sum=%d",sum);
}

Q-51
Ans.
#include<stdio.h>
void main()
{
float i,x=5.5;
int y;
for(y=1;y<7;y++)
{

while(x<=12.5)
{
i=2+(y+0.5*x);
printf("table is:%f\n",i);
x=x+0.5;
}
}
}

Q-52
Ans.
#include<stdio.h>
void main()
{
int a,rev=0,n,i,t;
printf("enter three digit number");
scanf("%d",&a);
t=a;
for(i=1;a!=0;i++)
{
n=a%10;
a=a/10;
rev=rev*10+n;
}
if(rev==t)
{
printf("number is palindron number");
}
else
printf("number is not palindrome
number");
}

Q-53
Ans.
#include<stdio.h>
void main()
{
int r;
float a,v;
printf("enter the radious");
scanf("%d",&r);
a=4*r*r*((float)22/7);
v=4*3.14*r*r*r/3;
printf("area or volume is:%f %f",a,v);

Q-54
Ans.
#include<stdio.h>
void main()
{
int n,sum,sse,sto;
printf("enter the terms of a number");
scanf("%d",&n);
sum=(n*(n+1))/2;
printf("sum of first n numbers is:%d",sum);
sse=(4*n*(n+1)*(2*n+1))/6;
printf("sum of squaew of first even number
is:\n%d",sse);
sto=2*n*n*n*n-n*n;
printf("sun of cube of first odd numbers
is:\n%d",sto);

Q-55
Ans.
#include<stdio.h>
void main()
{
int h,tp;
printf(" enter working hours of employ");
scanf("%d",&h);
if(h>40)
tp=10*12*(h-40);
printf("total pay of ten employ is:%d",tp);
}

Q-56
Ans.
#include<stdio.h>
void main()
{
int i,a[10],n,found=1;
printf("enter the value of n\n");
scanf("%d",&n);
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i+1]<=a[i])
found=0;
}
if(found==1)
printf("increasing order");
else
printf("not in ascending order\n");
}

Q-57
Ans.
#include<stdio.h>
void main()
{
int i,a[25],n,sum=0,term=0;
printf("enter the value of n\n");
scanf("%d",&n);
printf("enter the elements of array\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
{
if(i%3==0)
{
sum=sum+a[i-1];
term++;
}
}
printf("sum=%d",sum);
printf("average=%f",(float)sum/term);
}

Q-58
Ans.
#include<stdio.h>
void main()
{
int i,j,a[10],t,term=0,n=10;
printf("enter the elements of array\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=1;i<=n;i++)
{
if(a[0]==a[i])
term++;
}
printf("min number is occured %d
times",term);
}
Q-59
Ans.
#include<stdio.h>
void main()
{
int a;
printf("enter student number");
scanf("%d",&a);
if(a>=80)
printf("grade is A");
if(a>=70&&a<80)
printf("grade is B");
if(a>=60&&a<70)
printf("grade is C");
if(a>=50&&a<60)
printf("grade is D");
if(a<50)
printf("grade is F");
}

Q-61
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum,n,a[40],term=0;
float avg;
printf("enter the value of n\n");
scanf("%d",&n);
printf("enter the elements of array\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]>=0)
{
sum=sum+a[i];
term++;
}
}
avg=(float)sum/term;
printf("average is %f",avg);
getch();
}
Q-62
Ans.
#include<stdio.h>
void main()
{
int i=2,sum=0;
do
{
if(i%3==1)
sum=sum+i;
i++;
}while(i<100);
printf("sum is :%d",sum);
}
Q-62 Using For Loop
Ans.
#include<stdio.h>
void main()
{
int i,sum=0;
for(i=2;i<100;i++)
{
if(i%3==1)
sum=sum+i;
}
printf("sum is:%d",sum);
}

Q-62 Using While Loop


Ans.
#include<stdio.h>
void main()
{
int i=2,sum=0;
while(i<100)
{
if(i%3==1)
sum=sum+i;
i++;
}
printf("sum is :%d",sum);
}

Q-63
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
int sum;
printf("enter the value of sum\n");
scanf("%d",&sum);
if(sum=printf(" I WIN."))
printf("I WIN");
else
printf("I LOSE");
getch();
}

Q-64
Ans. (a)Hi

Q-65
Ans. (b)how are u
Q-66
Ans.(a)hello
Q-67
Ans.(d)hihello
Q-68
Ans.(c)hello
Q-69
Ans.(a)compile time error
Q-70
Ans.(a)1
Q-71
Ans.(d)2
Q-72
Ans.(b)2
Q-73
Ans.(b)-128
Q-74
Ans.(a)equal
Q-75
Ans.(a)equal
Q-76
Ans.(c)char<int<double
Q-77
Ans.(d)97.000000
Q-78
Ans.(a)C programming Class by
WOW Sanfoundry
Q-79
Ans.(c)compilation error
Q-80
Ans.(c)classundry
Q-81
Ans.(c)classundry
Q-82
Ans.(b)compile time error
Q-83
Ans.(b)Sanfoundry.com
Q-84
Ans.(d)break,exit(0),abort()
Q-85
Ans.(d)for(i=n-1;i>-1;i-)
Q-86
Ans.(c)compile time error
Q-87
Ans.(b)In while loop
after loop
Q-88
Ans.(a)In while loop
In while loop
In while loop
Q-89
Ans.(b)3
Q-90
Ans.a=5(d)

You might also like