Professional Documents
Culture Documents
%%:
Without %%:
Void main(){
Output:
Using %%:
Void main(){
Output:
Void main()
Int x=10;
//if we give input in octal let it be 012 now %d consider as decimal but ist octal so to convert it we use %i
//so we need to scan value of x using %i to take input in hexa,octal or any format
Difference between / and %: / can be applied both on int and float whereas % only on integer values
f1=10.0 ,f2=2.0
Printf(“%f”,fmod(f1,f2));
Abs():
Printf(“%f”,fabs(-89.2));
-14%3=-2
-14%-3=-2
14%-3=2 // only numerator sign need to be checked to find the sign of output
void main(){
int a=10,b=5;
int c;
c=((a>20)&&(b++));
printf("%d%d%d",a,b,c);
}
First condition checked its false so no need to check the next condition so exedcution of b++ does not
happen
print(‘x’==(‘x’ or ‘y’)) // prints True since or need to check only one condition (i.e.)’x’ x==x so, True
print(‘y’==(‘x’ or ‘y’)) // prints False since or need to check only one condition (i.e.)’x’ y!=x so, False
print(‘x’==(‘x’ and ‘y’))//prints False since and need to evaluate two condition’s first x and y now
//x!=y, False
print(‘y’==(‘x’ and ‘y’)) //prints True since and need to evaluate two condition’s first x and y now
Global Array has its values as Zero whereas local declared arrays will have the garbage value
Int a[10];
Void main(){
For(i=0;i<10;i++)
Printf(“%d ”,a[i]);
Output: 0 0 0 0 0 0 0 0 0 0
Void main(){
Int a[10]; // if this is Array declared as static the output is same as previous i.e. an array of zeros
For(i=0;i<10;i++)
Printf(“%d ”,a[i]);
Output: 1 0 4203609 0 0 0 17 0 0 0
Placement of header is not important in c:
Void main(){
#include<stdio.h>
Printf(“hello ”);// since we are using printf function after declaring header file so it doesn’t throw error
void like() {
static int count=0;//Static Key word: to update the value every time function called
count++;
printf("%d",count);
int A=10;
void F1(){
printf("A=%d",A);
printf("B=%B",B); //Error: Though B is global but it declared after the function block
int B=20;
void main(){
int i;
for(i=0;i<10;i++)
like();
F1();
F2();
}
void F2(){ //Warning: Function should be declared before main if we are writing the function block
printf("A=%d",A);
printf("B=%B",B);
Void main(){
Int a[2]={1,2,3,4,5};
For(int i=0;i<5;i++)
Printf(“%d”,a[i]); //it prints all 5 values first 2 are given and remaining are Garbage values
Output: 1 2 1 3 10097536->garbage
Designated Initializer
void main(){
Output:
If the size of array size is not mention the array will take the highest index plus 1
3D array
List in python
L1=[1,2,3]
L2=l1
L2.append(22)
L1=append(25)
Print(l1)
Output:
[1, 2, 3, 22, 25] #both values are append to l1 and l2 will effect each individual list
L1=[1,2,3]
L2=l1.copy()
L2.append(22)
L1=append(25)
Print(l1)
Output:
[1, 2, 3, 25]
Type2. Deepcopy
L1=[1,2,3]
L2=copy.deepcopy(L1)
L2.append(22)
L1=append(25)
Print(L1)
Output:
[1, 2, 3, 25]
Pattern:
#include<stdio.h>
void main(){
char c1='A',c2;
int i,j,t,n;
t=0;
scanf("%d",&n);
for(i=0;i<n;i++){
for(j=0;j<=i;j++){
printf("%c ",c1);
c1++;
}
printf("\n");
Output:
BC
DEF
GHIJ
KLMNO
Convert the above pattern into the given below only by adding one line without Removing
AB
ABC
ABCD
ABCDE
Code:
void main(){
char c1='A',c2;
int i,j,t,n;
t=0;
scanf("%d",&n);
for(i=0;i<n;i++){
for(j=0;j<=i;j++){
printf("%c ",c1);
c1++;
}
c1='A';
printf("\n");
#include<stdio.h>
#include<math.h>
int r,count,k,sum;
sum=0;
k=0;
while(n>0){
r=n%10;
if(r==0){
r=1;
sum=sum+r*pow(10,k);
else{
sum=sum+r*pow(10,k);
k=k+1;
n=n/10;
}
printf("%d",sum);
void main(){
int m;
scanf("%d",&m);
num(m);
Input: 80101
Output:81111
Output:
200
100
31
13
97
10
20
11
200 100 10 20