Professional Documents
Culture Documents
Unit 1 C
Unit 1 C
if(count == 2)
printf(" prime number");
else {
printf("it is not a prime number");
}
}
b.
#include<stdio.h>
int main()
{
int n,i,j;
char alphabet='a';
printf("enter the number");
scanf("%d",&n);
for(int i=1;i<=n;i++){
for(j=1;j<=i;j++){
printf("%c",alphabet);
}
++alphabet;
printf("\n");
}
}
If-else switch
1.if-else is a selection 1. It is multiple choice
statement. selection statement.
2.it can test any type of 2. It can test only integer and
expression. character expression.
4.it use multiple curly brasses 4. It use only one curly brasses
{}. {}.
Eg: -
#include<stdio.h>
int main(){
Eg: -
#include<stdio.h>
int a,b,c; int main()
{
printf("enter the first number\n"); int a,b,result;
scanf("%d %d %d",&a,&b,&c); char n;
if(a>=b && a>=c){ printf("choose the option(+,-,*,/)\n");
scanf("%c",&n);
printf("%d",a); printf("enter two numbers\n");
} scanf("%d %d",&a,&b);
switch(n){
else if(b>=a && b>=c){ case'-':
printf("%d",b); result=a-b;
} break;
case'+':
else if(c>=b && c>=a){ result=a+b;
printf("%d",c); break;
case'*':
} result=a*b;
} break;
case'/':
result=a/b;
break;
}
printf("your answer is %d \n",result);}
#include<stdio.h>
int main()
{
int n,i,j;
char alphabet='a';
printf("enter the number");
scanf("%d",&n);
for(int i=1;i<=n;i++){
for(j=1;j<=i;j++){
printf("%c",alphabet);
}
++alphabet;
printf("\n");
}
}
(a).prime or not?
#include<stdio.h>
int main()
{
int n,i,count=0;
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++){
if(n%i==0){
count++;
}
}
if(count==2)
printf("number is prime\n");
else
printf("not prime\n");
}
(b).factorial of a given number?
#include<stdio.h>
int main(){
int i,n,f=1;
printf("enter the number\n");
scanf("%d",&n);
for(i=1;i<=n;i++){
f=f*i;
printf(" factorial of %d is%d\n",n,f);
}
}
Unit-3
Ques1:macros
Ans: macro substitutuion is a process where an
identifies in program is replaced by pre defined string
composed of one or more programs.
-simple macro substitution.
-argumented macro substitution.
-nested macro substitution.
Ques2: difference b/w text files and binary files?
Ans:
Text files Binary files
1.stores information in 1.stores the data in the
unicode chararcter. same way as stored in the
memory.
2. each line is terminated 2.there is no delimetre for
by a special EOL the new line.
chararcter
3.stores plain text in a file. 3.stores different types of
data like image,audio,text
4.can be directly read. 4.cannot be directly read.
5.sequental access. 5.random access.
Nested structure:-
-nested structure in c is structure in structure.
-one structure can be declared inside.
-the structure variable can be normal structure
variable.
File handling:-
Unit-4