Wednesday, March 30, 2016

UVA 11875

#include<bits/stdc++.h>

using namespace std;

int main()
{
 int n,i,t,c;
 int v[100];
 while(cin>>t)
 {
  c=1;
  while(t--)
  {
   cin>>n;
   for(i=0; i<n; i++)
   {
    cin>>v[i];
   }
   sort(v,v+n);
   int res=n/2;
   cout<<"Case "<<c<<": "<<v[res]<<endl;
   c++;
  }
 }
 return 0;
}

UVA 11777

#include<iostream>
#include<cmath>
#include<bits/stdc++.h>

using namespace std;

int main()
{
 double t1,t2,f,aa,c1,c3,c2,c,cz;
 int n;
 double sum;
 while(cin>>n)
 {
  sum=0;
  cz=1;
  while(n--)
  {
   cin>>t1>>t2>>f>>aa>>c1>>c2>>c3;
   double a[3]={c1,c2,c3};
   sort(a,a+3);
   
   c= a[1]+ a[2];
   c = c /2;
   sum = t1+t2+f+aa+c;
   
   if(sum>=90) cout<<"Case "<<cz<<": A"<<endl;
   else if(sum>=80 && sum<90) cout<<"Case "<<cz<<": B"<<endl;
   else if(sum<80 && sum>=70) cout<<"Case "<<cz<<": C"<<endl;
   else if(sum>=60 && sum<70) cout<<"Case "<<cz<<": D"<<endl;
   else if(sum<60) cout<<"Case "<<cz<<": F"<<endl;
   cz++;
  }
  
 }
 return 0;
}

UVA 10106


import java.math.BigInteger;
import java.util.Scanner;
 class product {
    public static void main(String[] args) {
       Scanner in=new Scanner(System.in);
       while(in.hasNext())
       {
           BigInteger a=in.nextBigInteger();
           BigInteger b=in.nextBigInteger();
           System.out.println(a.multiply(b));
       }
    }

}

Thursday, March 3, 2016

UVA 272

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<stdio.h>
#include<string.h>

int main()
{
    char s[100000];
    long i,l,p=0;
    while(gets(s))
    {
        l=strlen(s);
        for(i=0;i<l;i++)
        {
            if(s[i]=='"')
            {
                p=p+1;
                if(p%2==1)
                printf("``");
                else
                printf("''");
            }
            else
            printf("%c",s[i]);
        }
        printf("\n");

    }
    return 0;
}

UVA 10370

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

int main()
{
 int n,t,i;
 long long a[1000];
 long long sum=0;
 int count=0;
 double per,res;
 cin>>t;
 while(t--)
 {
  cin>>n;
  for(i=0; i<n; i++)
  {
   cin>>a[i];
   sum=sum+a[i];
   
  }
  
  per = (float)sum/(float)n;
  for(i=0; i<n; i++)
  {
   if(a[i]>per) count=count+1;
  }
  res=((float)count * 100) / (float)n;
  cout<<setprecision(3)<<fixed<<res<<"%"<<endl;
  sum=0;
  count=0;
 }
}

UVA 12015

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iomanip>

using namespace std;

int main()
{
 int a[10],n,i,j,t,k;
 int d=1;
 j=0;
 char bb[10][100];
 
 cin>>t;
 
 while(t--)
 {
  for(i=0; i<10; i++)
  {
   cin>>bb[i];
   cin>>a[i];
   if(a[i]>j){
    j=a[i];
   }
  }
  
  cout<<"Case #"<<d<<":\n";
  
  for(i=0; i<10; i++)
  {
   if(a[i]==j){
    cout<<bb[i]<<endl;
   }
  }
  
  
  d++;
  j=0;
 }
 
 
}

UVA 12403

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<string.h>

using namespace std;

int main()
{
 int a,t,i,j;
 int sum=0;
 char word[100];
 
 cin>>t;
 while(t--)
 {
  cin>>word;
  if(strcmp(word,"donate")==0)
  {
   cin>>a;
   sum=sum+a;
  }
  else cout<<sum<<endl;
 }
 
 return 0;
}

UVA 1585

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <string.h>

int main()
{
    char s[101];
    int a[101],b,c,d,i,j,k,l,n,sum;
    scanf("%d",&n);
    
    for(i=1;i<=n;i++)
    {
        scanf("%s",s);
        l=strlen(s);
        for(j=0;j<l;j++)
        {
            if(s[j]=='O')
            a[j]=1;
            else if(s[j]='X')
            a[j]=0;
        }
        c=0,sum=0;
    for(k=0;k<l;k++)
    {
            if(a[k]==1)
            {
                c++;
            }
            if(a[k]==0)
            {
                c=0;
            }
            sum=sum+c;
    }
        printf("%d\n",sum);
  }
  return 0;
}

UVA 10812

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>

using namespace std;

int main()
{
 long long n,a,b,c,d,i,l;
 
while( cin>>n){

 

 
  for(i=1; i<=n; i++)
  {
   cin>>a>>b;
   
   if(a-b<0){
    cout<<"impossible"<<endl;
   }
   else{
    a= a/2;
    b=b/2;
    c= a - b;
    d= a + b;
    if(d>c){
    cout<<d<<" "<<c<<endl;
   }
    else {
     cout<<c<<" "<<d<<endl;
    }
    
   }
   
  }
  
  
  
 
}
 return 0;
}

UVA 13012

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>

using namespace std;

int main()
{
 int n,i,a[5];
 int sum=0;
 
 while(cin>>n)
 {
  for(i=0; i<5; i++)
  {
   cin>>a[i];
   if(a[i]==n) sum=sum+1;
  }
  cout<<sum<<endl;
  sum=0;
 }
 
 return 0;
}

UVA 12372

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>

using namespace std;

int main()
{
 long long n,i,a,b,c;
 
 cin>>n;
 for(i=0; i<n; i++)
 {
  cin>>a>>b>>c;
  
  if(a<=20 && b<=20 && c<=20)
  {
   cout<<"Case "<<i+1<<": good"<<endl;
  }
  else {
   cout<<"Case "<<i+1<<": bad"<<endl;
  }
 }
}

UVA 10945

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<stdio.h>
#include<string.h>

int main()
{
 int l,l1,l2,i,j,bin;
 char s[1000],s1[1000],s2[1000];
 
 while(gets(s))
 {
 bin=0;
 l1=-1;
 l=strlen(s);
 if(l==4 && s[0]=='D' && s[1]=='O' && s[2]=='N' && s[3]=='E')
  break;
 for(i=0;i<l;i++)
    {
    if(s[i]!='.' && s[i]!=',' && s[i]!='?' && s[i]!='!' && s[i]!=' ')
        {
        l1++;
        s1[l1]=s[i];
        }
    }
    
 for(j=0;j<=l1;j++)
    {
    if(s1[j]!=s1[l1-j] && s1[j]!=(s1[l1-j]+32) && s1[j]!=(s1[l1-j]-32))
        {
        printf("Uh oh..\n");
        bin=1;
        break;
        }
      }
    
 if(bin==0)
 printf("You won't be eaten!\n");
 }

}

Grade Generation or use of else-if statement in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>               //preprocessor , header library file included.

main()                  //main funtion starts.
{
 int marks;                //variable taken  defining datatype
 
 printf("Enter your obtained marks:\t");         //a message to the user regarding the program
 scanf("%d",&marks);              //input taken from user.
                    
  if(marks<=100){              //if starts from here with a condition
  if(marks>=80 && marks<=100) printf("A+\n");       //else ....if ladder starts from here.
   else if(marks>=70 && marks<=79) printf("A-\n");
    else if(marks>=60 && marks<=69) printf("B+\n");
     else if(marks>=50 && marks<=59) printf("C+\n");
      else if(marks>=45 && marks<=49) printf("D\n");
       else if(marks>=0 && marks<=40) printf("F\n");   //else if ladder ends here.
  }                
  else
  printf("Sorry the inputed marks is greater than 100.\n");   //the default message printed.
         
}                   //program ends here.

Sum of a number's components in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>

main()
{
 int i,sum,sum1=0,sum2=0, sum3=0, sum4=0;
 
 {
  scanf("%d",&i);
  sum1=i%10;
  i=i/10;
  sum2=i%10;
  i=i/10;
  sum3=i%10;
  i=i/10;
  sum4=i%10;
  i=i/10;
 }
 sum= sum1+sum2+sum3+sum4;
 printf("%d\n",sum);
 
}

strupr() function example in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include<stdio.h>
#include<string.h>

main()
{
 char name[20],name2[20];
 printf("Enter your name ?\n");
 gets(name);
 printf("Enter name2?.\n");
 gets(name2);
 strcat(name,name2);
 printf("\n\n\n\n");
 printf("%s",strupr(name));
 
}

strspn() function example in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include<stdio.h>
#include<string.h>

main()
{
 char name[20],name2[20];
 printf("Enter your name ?\n");
 gets(name);
 printf("Enter name2?.\n");
 gets(name2);

 printf("\n\n\n\n");
 printf("%d",strspn(name,name2));
 
}

strrev() function example in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#include<stdio.h>
#include<string.h>

main()
{
 char aSimpleString[80];
 printf("Enter your string\n");
 gets(aSimpleString);
 printf("Revers is %s",strrev(aSimpleString));
}

strlwr() function example in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include<stdio.h>
#include<string.h>

main()
{
 char name[20],name2[20];
 printf("Enter your name ?\n");
 gets(name);
 printf("Enter name2?.\n");
 gets(name2);
 strcat(name,name2);
 printf("\n\n\n\n");
 printf("%s",strlwr(name));
 
}

strcmp() function example in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include<stdio.h>
#include<string.h>

main()
{
 char name[20],name2[20];
 int value;
 printf("Enter your name ?\n");
 gets(name);
 printf("Enter name2?.\n");
 gets(name2);
 value = strcmp(name,name2);
 if(value==0){
  printf("The strings are equal.");
 }
 else printf("not");
}

strcpy() function example in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include<stdio.h>
#include<string.h>

main()
{
 char name[20],name2[20];
 char value[50];
 printf("Enter your name ?\n");
 gets(name);
 printf("Enter name2?.\n");
 gets(name2);
 strcpy(name,name2);
 printf("%s",name);
 
}

strcat() function example in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include<stdio.h>
#include<string.h>

main()
{
 char name[20],name2[20];
 printf("Enter your name ?\n");
 gets(name);
 printf("Enter name2?.\n");
 gets(name2);
 strcat(name,name2);
 printf("\n\n\n\n");
 printf("%s",name);
 
}

True-false/ on-off printing in C

1
2
3
4
5
6
7
8
9
#include<stdio.h>

main()
{
 int a,b,c;
 scanf("%d %d",&a,&b);
 c = a > b;
 printf("%d",c);
}

Checking leap year in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>

int main(){
      int year;
      printf("Enter a year: ");
      scanf("%d",&year);
      if(year%4 == 0)
      {
          if( year%100 == 0) /* Checking for a century year */
          {
              if ( year%400 == 0)
                 printf("%d is a leap year.", year);
              else
                 printf("%d is not a leap year.", year);
          }
          else
             printf("%d is a leap year.", year );
      }
      else
         printf("%d is not a leap year.", year);
      return 0;
}

switch case example in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<stdio.h>         //header file

main()            //main function
{
 char gradeName;         //variable declaration
 printf("Enter your Grade:");    
 scanf("%c",&gradeName);       //taking input from user
 
  switch(gradeName){       //start point of switch case
   case 'A':
   case 'a':
    printf("Excellent\n");
    break;
   case 'b':
   case 'B':
    printf("Good\n");
    break;
   case 'c':
   case 'C':
    printf("Less good\n");
    break;
   case 'd':
   case 'D':
    printf("Partially good\n");
    break;
   case 'f':
   case 'F':
    printf("Very bad\n");
   default:
    printf("Keyword not found\n");
    break;
  }            //end of switch case
}              //end of program

goto example in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include <stdio.h>

main()
{
 int i;
 i=1;
 mylevel: if(i%2==0){
  printf("%d\n",i);
  i++;
  
 }
  if(i<=20){
   goto mylevel;
  }
}

Farenhit to Celcius conversion in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include<stdio.h>
#include<math.h>

main()
{
    float far, cel , kelvin;
    while(printf("Enter your temp in farenheit: ")!=EOF){
    scanf("%f",&far);
    cel=(far-32)/1.8;
    kelvin=cel+273;
    printf("Your Kelvin temp is %.2fK\n",kelvin);
    }
}

do while loop in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include <stdio.h>

main()
{
 int i=10;
 do{
  printf("Hello %d\n",i);
  i--;
  if(i==5) break;
 }
 
    while(i>=1);
}

Continue example in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include<stdio.h>

main()
{
 int i;
 for(i=1; i<=10; i++){
  if(i==6 || i==7){
   continue;
  }
  else printf("%d\n",i);
 }
}

Celcius to Kelvin conversion in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include  <stdio.h>
#include <math.h>

main()
{
 float temp,temp1;
  printf("Enter the temparature in Celcius :");
  scanf("%f",&temp);
   temp1 = temp + 273;
    printf("Converted temparature: %.2f K",temp1);
}

Break example in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include <stdio.h>

main()
{
 int n;
 printf("Enter the Integers:");
  while(1)
  {
   scanf("%d",&n);
    if(n==30)
    break;
  }
 printf("30 is entered so no more.");
 
}

Array element's square sum in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
#include<math.h>

main() 
{
 int i,n;
 printf("Enter how long will be your array:\n");
 scanf("%d",&n);
 float x[n],value,total;
 total = 0.0;
 printf("Enter %d real number:\n",n);
 for(i=0; i<n; i++){
  scanf("%f",&value);
  x[i]=value;
  total = total + pow(x[i],2);
  printf("x[%d] = %.2f\n",i+1,x[i]);
 }
 
 printf("Total = %.2f\n",total);
 
}

Adding two number in C

1
2
3
4
5
6
7
8
9
#include <stdio.h>

main()
{
 int a,b,result;     //variable declaration
 scanf("%d %d",&a,&b);  //input from user
  result = a+b;   //adding two numbers
   printf("%d\n",result);  //printing the result
}

Tuesday, March 1, 2016

Printing 1-10 in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#include <stdio.h>

int main(){
 int i;
 for(i=1; i<=10;){
  printf("%d\t",i);
  i++;
  
 }
}

Small to Capital letter in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <stdio.h>

int main(){
 char name[]={'h', 'u', 'm','a', 'u','n'};
 int i, lenth;
 printf("%s\n", name);   
 lenth=6;
 for (i=0;i<6; i++){
  if (name[i]>=97 && name[i<=122]){
   name[i]='A'+name[i]-'a';
  }
  
 }
 printf("%s",name);
 return(0);
 
}

Calculating (a+b)^2 in C

1:  #include <stdio.h>  
2:    
3:  int main()  
4:  {  
5:        
6:              int a,b,c;  
7:              printf("Enter the value of a and b :\t");  
8:              scanf("%d %d",&a,&b);  
9:              c=a+b;  
10:              printf("The value of (a+b)^2 is %d",c*c);  
11:        
12:      return 0;          
13:  }  

Finding x and y in equations using C program

1:  #include <stdio.h>  
2:    
3:  int main()  
4:  {  
5:      double x,y,x_plus_y,x_minus_y;  
6:        
7:      printf("Enter the value of x+y:");  
8:      scanf("%lf",&x_plus_y);  
9:        
10:      printf("Enter the value of x-y:");  
11:      scanf("%lf",&x_minus_y);  
12:        
13:      x=(x_plus_y+x_minus_y)/2;  
14:      y=(x_plus_y-x_minus_y)/2;  
15:        
16:      printf("x= %.2lf \t y= %.2lf ",x,y);  
17:        
18:      return(0);  
19:        
20:        
21:  }   

Pascal Triangle in C

1:  #include<stdio.h>  
2:    
3:  long fact(int);  
4:  int main(){  
5:    int n,i,j;  
6:    
7:    printf("Enter the no. of lines: ");  
8:    scanf("%d",&n);  
9:    
10:    for(i=0;i<n;i++){  
11:       for(j=0;j<n-i-1;j++)  
12:         printf(" ");  
13:    
14:       for(j=0;j<=i;j++)  
15:         printf("%ld ",fact(i)/(fact(j)*fact(i-j)));  
16:       printf("\n");  
17:    }  
18:    return 0;  
19:  }  
20:    
21:  long fact(int num){  
22:    long f=1;  
23:    int i=1;  
24:    while(i<=num){  
25:       f=f*i;  
26:       i++;  
27:   }  
28:   return f;  
29:   }  
30:    

Sum up to n th number using user define function in C

1:  #include <stdio.h>  
2:  int sum(int n){  
3:    if(n==0)  
4:      return n;  
5:    else  
6:      return n+sum(n-1);  
7:  }  
8:    
9:  int main(){  
10:    int num,add;  
11:    printf("Enter a positive integer:\n");  
12:    scanf("%d",&num);  
13:    add=sum(num);  
14:    printf("sum=%d",add);  
15:  }  
16:    

Decimel to Binary in C

1:  #include <stdio.h>  
2:    
3:  int main()  
4:  {  
5:      int i;  
6:      scanf("%d",&i);  
7:      while(i--)  
8:      {  
9:        
10:       int n, c, k;  
11:     
12:   printf("Enter an integer in decimal number system\n");  
13:   scanf("%d", &n);  
14:     
15:   printf("%d in binary number system is:\n", n);  
16:     
17:   for (c = 31; c >= 0; c--)  
18:   {  
19:    k = n >> c;  
20:     
21:    if (k & 1)  
22:     printf("1");  
23:    else  
24:     printf("0");  
25:   }  
26:     
27:   printf("\n");  
28:    
29:   }   
30:   return 0;  
31:  }  

Bubble Sort in C

1:  #include<stdio.h>  
2:    
3:  int main()  
4:  {  
5:      int n,i,j;  
6:      int num[100];  
7:      int swap;  
8:        
9:      printf("How many element do you want to sort? \n");  
10:      scanf("%d",&n);  
11:        
12:      for(i=0 ; i<n; i++)  
13:      {  
14:          scanf("%d",&num[i]);  
15:      }  
16:        
17:      for(i=0; i<n-1; i++)  
18:      {  
19:          for(j=0 ; j< (n-i-1);j++)  
20:          {  
21:              if(num[j]>num[j+1]){  
22:                      swap=num[j];  
23:                      num[j]=num[j+1];  
24:                      num[j+1]=swap;  
25:              }  
26:            
27:                
28:          }  
29:      }  
30:      printf("Your sorted list is :\n");  
31:        
32:      for(i=0; i<n; i++)  
33:      {  
34:          printf("%d\n",num[i]);  
35:      }  
36:    
37:  }  

Multiplication of two matrices in C

1:  #include<stdio.h>  
2:  #include<stdlib.h>  
3:    
4:  int main()  
5:  {  
6:      int i,j;  
7:      int a[3][3],b[3][3],c[3][3];  
8:        
9:      printf("\nEnter the element of first matrix:\n");  
10:          for(i=0; i<3; i++)  
11:          {  
12:              for(j=0; j<3; j++)  
13:              {  
14:                  scanf("%d",&a[i][j]);  
15:              }  
16:          }  
17:              printf("\nEnter the elements of second matrix:\n");  
18:                      for(i=0; i<3; i++)  
19:          {  
20:              for(j=0; j<3; j++)  
21:              {  
22:                  scanf("%d",&b[i][j]);  
23:              }  
24:          }  
25:            
26:            
27:          for(i=0; i<3; i++)  
28:          {  
29:              for(j=0; j<3; j++)  
30:              {  
31:                  c[i][j] = a[i][j] * b[i][j];  
32:              }  
33:          }  
34:            
35:          printf("\nThe resultant matrix is:\n");  
36:          for(i=0; i<3; i++)  
37:          {  
38:              for(j=0; j<3; j++)  
39:              {  
40:                  printf("%d ",c[i][j]);  
41:              }  
42:              printf("\n");  
43:          }                          
44:      return 0;  
45:  }  
46:    

Substrating two matrices in C

1:  #include<stdio.h>  
2:  #include<stdlib.h>  
3:    
4:  int main()  
5:  {  
6:      int i,j;  
7:      int a[3][3],b[3][3],c[3][3];  
8:        
9:      printf("\nEnter the element of first matrix:\n");  
10:          for(i=0; i<3; i++)  
11:          {  
12:              for(j=0; j<3; j++)  
13:              {  
14:                  scanf("%d",&a[i][j]);  
15:              }  
16:          }  
17:              printf("\nEnter the elements of second matrix:\n");  
18:                      for(i=0; i<3; i++)  
19:          {  
20:              for(j=0; j<3; j++)  
21:              {  
22:                  scanf("%d",&b[i][j]);  
23:              }  
24:          }  
25:            
26:            
27:          for(i=0; i<3; i++)  
28:          {  
29:              for(j=0; j<3; j++)  
30:              {  
31:                  c[i][j] = a[i][j] - b[i][j];  
32:              }  
33:          }  
34:            
35:          printf("\nThe resultant matrix is:\n");  
36:          for(i=0; i<3; i++)  
37:          {  
38:              for(j=0; j<3; j++)  
39:              {  
40:                  printf("%d\t",c[i][j]);  
41:              }  
42:              printf("\n");  
43:          }                          
44:      return 0;  
45:  }  
46:    

Hello World in C

1:   #include<stdio.h>  
2:   main()  
3:   {  
4:    printf("Hello world ! \n");  
5:   }  

Factorial in C

1:  #include <stdio.h>  
2:    
3:  int main()  
4:  {  
5:      int n,factorial;  
6:      factorial=1;  
7:      printf("Enter your number: ");  
8:      scanf("%d",&n);  
9:      while(n>0){  
10:          factorial=factorial*n;  
11:          --n;  
12:            
13:      }  
14:      printf("Your factorial number is : %d",factorial);  
15:      return 0;  
16:      }  

Adding two numbers using user define function in C

1:  #include<stdio.h>  
2:    
3:  int sum(int a, int b){  
4:      int add;  
5:      add= a+b;  
6:        
7:      return add;  
8:        
9:  }  
10:    
11:  main()  
12:  {  
13:      int x,y;  
14:      while(1){  
15:            
16:          scanf("%d %d",&x,&y);  
17:      int jog;  
18:      jog = sum(x,y);  
19:        
20:      printf("%d\n",jog);  
21:        
22:      }  
23:  }  

Floyd's Triangle in C

1:  #include <stdio.h>  
2:  int main(){  
3:              int i,j,a=1;  
4:      for(i=1;i<=10; i++){  
5:        
6:          for(j=1; j<=i; j++){  
7:              printf("%d",a);  
8:              a++;  
9:          }  
10:          printf("\n");  
11:      }  
12:  }  

Fibonacci Series in C

1:  #include <stdio.h>  
2:    
3:  int main(){  
4:        
5:      int count,n,x=0,y=1,display=0;  
6:      printf("Enter your term number:\t");  
7:      scanf("%d",&n);  
8:      printf("your fibonacci series is: %d+ %d+",x,y);  
9:      count=2;  
10:        
11:      while (count<n){  
12:          display=x+y;  
13:          x=y;  
14:          y=display;  
15:          ++count;  
16:          printf("%d+",display);  
17:            
18:      }  
19:        
20:      return(0);  
21:  }  

Array Indexing and Printing in C

1:  #include<stdio.h>  
2:  #include<stdlib.h>  
3:    
4:  int main()  
5:  {  
6:      int n[10];  
7:      int m[]={2,4,5,8,10};  
8:      int p[50]={0};  
9:    
10:      int i,k;  
11:      for(i=0; i<=9; i++){  
12:          scanf("%d",&n[i]);  
13:      }  
14:            
15:          for(k=1; k<=10; i++){  
16:              printf("%d no. value is %d",k,n[k-1]);  
17:          }  
18:        
19:      return 0;  
20:  }