Showing posts with label IGNOU C assignment. Show all posts
Showing posts with label IGNOU C assignment. Show all posts

Thursday, 23 August 2012

IGNOU C ASSIGNMENT SOLVE MCS - 011 (Part 2)

Question 4: Write an interactive program called “DISTANCE CONVERTER” that accepts the distance in millimeters / feet /miles / yards / kilometers and displays its equivalent in meters.

Ans.

#include <stdio.h>
#include <conio.h>
void main ( )
{
            float          meter, dis;
            int             ch;
            clrscr ( );
                                                
            printf ("\n Press 1 to input the distance in millimeters.");
            printf ("\n Press 2 to input the distance in feet.");
            printf ("\n Press 3 to input the distance in miles.");
            printf ("\n Press 4 to input the distance in yards.");
            printf ("\n Press 5 to input the distance in kilometers.");
            printf ("\n Enter the choice..");
            scanf ("%d",&ch);
                                                                  
            switch ( ch )
            {                                                                                           
                                    case 1: printf ("\n Input the distance in millimeters..:");
                                                  scanf ("%f",&dis);
                                                  meter = dis/1000;
                                                  printf ("\n Distance in meter =%f",meter);
                                                  break;
                                                                                                           
                                    case 2: printf ("\n Input the distance in feet..:");
                                                  scanf ("%f",&dis);
                                                  meter = dis*.3048;
                                                  printf ("\n Distance in meter =%f",meter);
                                                  break;
                                                                                                           
                                    case 3: printf ("\n Input the distance in miles..:");
                                                  scanf ("%f",&dis);
                                                  meter = dis*1.60934*1000;
                                                  printf ("\n Distance in meter =%f",meter);
                                                  break;
                                                                                                                  
                                    case 4: printf ("\n Input the distance in yards..:");
                                                  scanf ("%f",&dis);
                                                  meter = dis*.9144;
                                                  printf ("\n Distance in meter =%f",meter);
                                                  break;
                                                                                                               
                                    case 5: printf ("\n Input the distance in kilometers..:");
                                                  scanf ("%f",&dis);
                                                  meter = dis*1000;
                                                  printf ("\n Distance in meter =%f",meter);
                                                  break;
                                                                       
                                    default:  printf("\n Wrong choice.");
            }
            getch ( );
}

Click here to contact us

 
Question 5: Write an interactive program to generate progress reportsfor the students of class XII (Science group).
Assumptions can be made wherever necessary.

 Ans.

#include <stdio.h>
#include <conio.h>
struct  stud
{
            int  roll;
            char  name [40];
            int  sub[4];
            int  total;
};

struct stud getdata( )
{
            struct stud st;
            printf ("\n Enter roll..:"); scanf ("%d",&st.roll);
            fflush(stdin);
                                                                             
            printf ("\n Enter name..:"); gets(st.name);
            fflush(stdin);
                                        
            printf ("\n Enter marks for Mathematics..:"); scanf ("%d",&st.sub[0]);
            printf ("\n Enter marks for Physics......:"); scanf ("%d",&st.sub[1]);
            printf ("\n Enter marks for Chemistry....:"); scanf ("%d",&st.sub[2]);
            printf ("\n Enter marks for Biology......:"); scanf ("%d",&st.sub[3]);
            
            st.total = st.sub[0] + st.sub[1] + st.sub[2] + st.sub[3];
            clrscr( );
            return st;
}               
                               
void showdata(struct stud st)
{                                         
            printf ("\n%d\t%s\t\t%d\t%d\t%d\t%d
                         \t%d",st.roll,st.name,st.sub[0],st.sub[1],st.sub[2],st.sub[3],st.total);
}                                                  
void sort(struct stud s[])
{
            int  i, j;
            struct  stud t;
                                      
            for ( i = 0; i < 5; i++ )
            {                                                  
                            for ( j = i+1; j < 5; j++ )
                            {                                             
                                               if ( s[i].total < s[j].total )
                                               {                                         
                                                                  t = s[i];
                                                                  s[i] = s[j];
                                                                  s[j] = t;
                                               }                                             
                            }                                                              
            }

}

void main ( )
{
            int   i;
            struct   stud s[5];
            clrscr ( );
                                                
            for( i = 0; i < 5; i++ )
            {                                                                          
                           printf ("\n Enter details for student no:%d",i+1);
                           printf ("\n___________________________________\n");
                           s[i] = getdata ( );
            }         
                                                                                                         
            printf ("\n Result of the students of class XII(science)..:");
            printf ("\nROLL\tNAME\t\tMATH\tPHY\tCHEM\tBIO\tTOTAL\n");
                                       
            for ( i = 0; i < 5; i++ )
            {                                             
                            showdata(s[i]);
            }                                               
            sort(s);
                            printf("\n__________________________________________________________\n");
            printf("\nRoll -> %d Name ->%s is in 1st position.",s[0].roll,s[0].name);
            printf("\nRoll -> %d Name ->%s is in 2nd position.",s[1].roll,s[1].name);
            printf("\nRoll -> %d Name ->%s is in 3rd position.",s[2].roll,s[2].name);
            getch();
}

Click here to contact us

IGNOU C ASSIGNMENT SOLVE MCS - 011 (Part 1)


Question 1: Write a program to print the following pattern:
               a) 1                                       b)  1
                   1 2                                         2 2
                   1 2 3                                      3 3 3
                   1 2 3 4                                   4 4 4 4
                   1 2 3 4 5                                5 5 5 5 5


Ans a)

#include <stdio.h>
#include <conio.h>
void main ( )
{

         int       i, j;
         clrscr ( );
              
         for ( i =1; i <= 5; i++ )
         {                                  
                        for ( j = 1; j <= i; j++ )
                        {                                      
                                        printf("%d",j);
                        }
                        printf("\n");
         }
         getch();
}

Ans b)

#include <stdio.h>
#include <conio.h>
void main ( )
{
             int     i, j;
             clrscr ( );
                               
             for ( i = 1; i <= 5; i++ )
             {                              
                             for ( j = 1; j <= i; j++ )
                             {                                  
                                             printf("%d",i);
                             }
                             printf("\n");
             }
             getch();
}



Question 2: Declare two arrays A and B, find
(i)  A intersection B and (ii) A union B.

Ans(i)

#include <stdio.h>
#include <conio.h>
void main ( )
{
            int         arr[10], brr[10], inter[10], i, j, k = 0, f;
            clrscr ( );
                                
            printf ("\n Enter numbers in 1st array..:");
            for ( i = 0; i < 10; i++ )
            {                                                    
                            printf ("\n Enter a number..:");
                            scanf ("%d", &arr[i]);
            }                                                                
                                           
            printf ("\n Enter numbers in 2nd array..:");
            for ( i = 0; i < 10; i++ )
            {                                                          
                            printf ("\n Enter a number..:");
                            scanf ("%d", &brr[i]);
            }
                                                        
            for ( j = 0; j < 10; j++ )
            {                                        
                            f = 0;
                            for ( i = 0; i < 10; i++ )
                            {                                         
                                            if ( brr[j] == arr[i] )
                                            {                                  
                                                             f = 1;
                                                             break;
                                            }                                  
                            }                                            
                            if ( f == 1 )
                            {                                        
                                      inter[k++] = brr[j];
                            }
            }                                                            
                                                                                  
            printf("\n Intersection array..:");
            for ( i = 0; i < k; i++ )
            {                                                      
                            printf ("%d,", inter[i]);
            }
            getch ( );
}

 
Ans (ii)

#include <stdio.h>
#include <conio.h>
void main ( )
{
            int         arr[5], brr[5], uni[10], i, j, k = 0, f;
            clrscr ( );
                                                                        
            printf ("\n Enter numbers in 1st array..:");
            for ( i = 0; i < 5; i++ )
            {                                                             
                            printf ("\n Enter a number..:");
                            scanf ("%d",&arr[i]);
                            uni[k++]=arr[i];
            }                                                                
                                                                                  
            printf("\n Enter numbers in 2nd array..:");
            for ( i = 0; i < 5; i++ )
            {                                                                 
                            printf ("\n Enter a number..:");
                            scanf ("%d",&brr[i]);
            }                                                                
                                                                 
            for ( j = 0; j < 5; j++ )
            {                                                               
                            f = 0;
                            for ( i = 0; i < 5; i++ )
                            {                                         
                                            if ( brr[j] == arr[i] )
                                            {                                  
                                                            f = 1;
                                                            break;
                                            }                               
                            }                                                
                            if ( f == 0 )
                            {                                                           
                                      uni[k++] = brr[j];
                            }
            }                                                                  
                                                                                 
            printf ("\n Union array..:");
            for ( i = 0; i < k; i++ )
            {                                          
                            printf ("%d,",uni[i]);
            }                                                    
            getch ( );
}

Click here to contact us 


Question 3: Write a program to crypt its input according to a specified transformation scheme. The transformation scheme will consist of two strings: a string of characters and then a string of replacement characters. The idea is that your program replaces every instance of the ith character in the initial string with the (i+2) character (of English alphabets) in the replacement string. When no substitution is defined for a character, the program just passes it through to the output unchanged. Blank spaces and the other symbols remains the same. The program should inform the user of any errors in the transformation scheme. Your program should display the phrase before and after the substitutions have been made.
Example:
Original String: I know C programming.
String after the transformation: K mpqy E rtqitcookpi.

Ans:

#include <stdio.h>
#include <conio.h>
void main ( )
{
            int           i;
            char        str[40], rstr[40];
            clrscr ( );
                                        
            printf ("\n Enter the string..:");
            gets ( str );
            for ( i = 0; str[i]! = '\0'; i++)
            {                                                                                           
                            if (( str[i] >= 'a' && str[i] <= 'x' ) || ( str[i] >= 'A' && str[i] <= 'X' ))
                            {                                                                                                 
                                                                rstr[i] = str[i] + 2;
                            }                                                                                                      
                            else                                                                                                 
                            {                                                                                                        
                                                                rstr[i] = str[i];
                            }                                                                                               
            }
              
            printf ("\n Original string.:%s",str);
            printf ("\n Replaced string.:%s",rstr);
            getch ( );
}

Related Posts Plugin for WordPress, Blogger...